-- MySQL Workbench Forward Engineering

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';

-- -----------------------------------------------------
-- Schema wstelegramcco
-- -----------------------------------------------------

-- -----------------------------------------------------
-- Schema wstelegramcco
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `wstelegramcco` DEFAULT CHARACTER SET utf8 ;
USE `wstelegramcco` ;

-- -----------------------------------------------------
-- Table `wstelegramcco`.`_versao`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `wstelegramcco`.`_versao` (
  `versao` CHAR(4) NOT NULL,
  `atualizado_em` DATETIME NOT NULL,
  PRIMARY KEY (`versao`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;


-- -----------------------------------------------------
-- Table `wstelegramcco`.`gm`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `wstelegramcco`.`gm` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `nome` VARCHAR(45) NOT NULL,
  `uf` CHAR(2) NOT NULL,
  `cidade` VARCHAR(45) NOT NULL,
  `url_ws` VARCHAR(200) NULL DEFAULT NULL,
  `ativo` ENUM('S', 'N') NOT NULL DEFAULT 'S',
  PRIMARY KEY (`id`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;


-- -----------------------------------------------------
-- Table `wstelegramcco`.`usuario`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `wstelegramcco`.`usuario` (
  `telegram_id` BIGINT(20) NOT NULL,
  `nome` VARCHAR(100) NOT NULL,
  `sobrenome` VARCHAR(100) NOT NULL,
  `gm_id` INT(11) NULL DEFAULT NULL,
  `criado_em` DATETIME NOT NULL,
  PRIMARY KEY (`telegram_id`),
  INDEX `fk_usuario_gm_idx` (`gm_id` ASC),
  CONSTRAINT `fk_usuario_gm`
    FOREIGN KEY (`gm_id`)
    REFERENCES `wstelegramcco`.`gm` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;

-- Atualiza a versão
INSERT INTO `wstelegramcco`.`_versao` (`versao`,`atualizado_em`) VALUES ('0001', NOW());

SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

