
-- -----------------------------------------------------
-- Table `TBG_uf`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `TBG_uf` (
  `UF_id` INT NOT NULL AUTO_INCREMENT,
  `UF_descricao` VARCHAR(50) NULL,
  `UF_sigla` VARCHAR(2) NULL,
  `UF_ibge` INT NULL,
  PRIMARY KEY (`UF_id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `TBG_cidade`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `TBG_cidade` (
  `CIDA_id` INT NOT NULL AUTO_INCREMENT,
  `CIDA_FK_UF_id` INT NOT NULL,
  `CIDA_descricao` VARCHAR(50) NULL,
  `CIDA_ibge` INT NULL,
  PRIMARY KEY (`CIDA_id`),
  INDEX `fk_TBG_cidade_TBG_uf1_idx` (`CIDA_FK_UF_id` ASC) ,
  CONSTRAINT `fk_TBG_cidade_TBG_uf1`
    FOREIGN KEY (`CIDA_FK_UF_id`)
    REFERENCES `TBG_uf` (`UF_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `TBG_unidade`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `TBG_unidade` (
  `UNID_id` INT NOT NULL AUTO_INCREMENT,
  `UNID_FK_CIDA_id` INT NOT NULL,
  `UNID_nome` VARCHAR(50) NULL,
  `UNID_codigo` VARCHAR(6) NULL,
  `UNID_endereco` VARCHAR(50) NULL,
  `UNID_complemento` VARCHAR(50) NULL,
  `UNID_nro` VARCHAR(6) NULL,
  `UNID_bairro` VARCHAR(50) NULL,
  `UNID_cep` VARCHAR(10) NULL,
  `UNID_fone` VARCHAR(20) NULL,
  `UNID_celular` VARCHAR(20) NULL,
  `UNID_email` VARCHAR(100) NULL,
  `UNID_ativo` VARCHAR(1) NULL,
  PRIMARY KEY (`UNID_id`),
  INDEX `fk_TBG_unidade_TBG_cidade1_idx` (`UNID_FK_CIDA_id` ASC) ,
  CONSTRAINT `fk_TBG_unidade_TBG_cidade1`
    FOREIGN KEY (`UNID_FK_CIDA_id`)
    REFERENCES `TBG_cidade` (`CIDA_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `TBG_sistema`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `TBG_sistema` (
  `SIST_id` INT NOT NULL AUTO_INCREMENT,
  `SIST_descricao` VARCHAR(50) NULL,
  `SIST_codigo` CHAR(2) NULL,
  PRIMARY KEY (`SIST_id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `TBG_usuario`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `TBG_usuario` (
  `USUA_id` INT NOT NULL AUTO_INCREMENT,
  `USUA_FK_UNID_id` INT NOT NULL,
  `USUA_nome` VARCHAR(50) NULL,
  `USUA_cpf` VARCHAR(11) NULL,
  `USUA_email` VARCHAR(50) NULL,
  `USUA_celular` VARCHAR(20) NULL,
  `USUA_telefone` VARCHAR(20) NULL,
  `password` VARCHAR(255) NULL,
  `remember_token` VARCHAR(100) NULL,
  `USUA_ativo` VARCHAR(1) NULL,
  `USUA_dt_criacao` TIMESTAMP NULL,
  `USUA_dt_alteracao` TIMESTAMP NULL,
  `USUA_login` VARCHAR(20) NULL,
  PRIMARY KEY (`USUA_id`),
  INDEX `fk_TBG_usuario_TBG_unidade_idx` (`USUA_FK_UNID_id` ASC) ,
  CONSTRAINT `fk_TBG_usuario_TBG_unidade`
    FOREIGN KEY (`USUA_FK_UNID_id`)
    REFERENCES `TBG_unidade` (`UNID_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `TBG_classe`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `TBG_classe` (
  `CLA_id` INT NOT NULL AUTO_INCREMENT,
  `CLA_FK_SIST_id` INT NOT NULL,
  `CLA_descricao` VARCHAR(50) NULL,
  `CLA_codigo` VARCHAR(5) NULL,
  `CLA_admin` CHAR(1) NULL,
  PRIMARY KEY (`CLA_id`),
  INDEX `fk_TBG_classe_TBG_sistema1_idx` (`CLA_FK_SIST_id` ASC) ,
  CONSTRAINT `fk_TBG_classe_TBG_sistema1`
    FOREIGN KEY (`CLA_FK_SIST_id`)
    REFERENCES `TBG_sistema` (`SIST_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `TBG_permissao`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `TBG_permissao` (
  `PERM_id` INT NOT NULL AUTO_INCREMENT,
  `PERM_FK_CLA_id` INT NOT NULL,
  `PERM_FK_USUA_id` INT NOT NULL,
  PRIMARY KEY (`PERM_id`),
  INDEX `fk_TBG_permissao_TBG_classe1_idx` (`PERM_FK_CLA_id` ASC) ,
  INDEX `fk_TBG_permissao_TBG_usuario1_idx` (`PERM_FK_USUA_id` ASC) ,
  CONSTRAINT `fk_TBG_permissao_TBG_classe1`
    FOREIGN KEY (`PERM_FK_CLA_id`)
    REFERENCES `TBG_classe` (`CLA_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_TBG_permissao_TBG_usuario1`
    FOREIGN KEY (`PERM_FK_USUA_id`)
    REFERENCES `TBG_usuario` (`USUA_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `TBG_rotas`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `TBG_rotas` (
  `ROTA_id` INT NOT NULL AUTO_INCREMENT,
  `ROTA_FK_ROTA_id` INT NOT NULL,
  `ROTA_FK_SIST_id` INT NOT NULL,
  `ROTA_nome` VARCHAR(50) NULL,
  `ROTA_role` VARCHAR(50) NULL,
  `ROTA_menu` CHAR(1) NULL,
  `ROTA_icone` VARCHAR(50) NULL,
  PRIMARY KEY (`ROTA_id`),
  INDEX `fk_TBG_rotas_TBG_rotas1_idx` (`ROTA_FK_ROTA_id` ASC) ,
  INDEX `fk_TBG_rotas_TBG_sistema1_idx` (`ROTA_FK_SIST_id` ASC) ,
  CONSTRAINT `fk_TBG_rotas_TBG_rotas1`
    FOREIGN KEY (`ROTA_FK_ROTA_id`)
    REFERENCES `TBG_rotas` (`ROTA_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_TBG_rotas_TBG_sistema1`
    FOREIGN KEY (`ROTA_FK_SIST_id`)
    REFERENCES `TBG_sistema` (`SIST_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `TBG_classe_rota`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `TBG_classe_rota` (
  `CLARO_id` INT NOT NULL AUTO_INCREMENT,
  `CLARO_FK_ROTA_id` INT NOT NULL,
  `CLARO_FK_CLA_id` INT NOT NULL,
  PRIMARY KEY (`CLARO_id`),
  INDEX `fk_TBG_classe_rota_TBG_rotas1_idx` (`CLARO_FK_ROTA_id` ASC) ,
  INDEX `fk_TBG_classe_rota_TBG_classe1_idx` (`CLARO_FK_CLA_id` ASC) ,
  CONSTRAINT `fk_TBG_classe_rota_TBG_rotas1`
    FOREIGN KEY (`CLARO_FK_ROTA_id`)
    REFERENCES `TBG_rotas` (`ROTA_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_TBG_classe_rota_TBG_classe1`
    FOREIGN KEY (`CLARO_FK_CLA_id`)
    REFERENCES `TBG_classe` (`CLA_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `TBG_parametro`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `TBG_parametro` (
  `PARA_id` INT NOT NULL AUTO_INCREMENT,
  `PARA_codigo` VARCHAR(6) NULL,
  `PARA_descricao` VARCHAR(50) NULL,
  `PARA_valor` VARCHAR(100) NULL,
  PRIMARY KEY (`PARA_id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `PRO_tipo_processo`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `PRO_tipo_processo` (
  `TIPOP_id` INT NOT NULL AUTO_INCREMENT,
  `TIPOP_descricao` VARCHAR(50) NULL,
  PRIMARY KEY (`TIPOP_id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `PRO_processo`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `PRO_processo` (
  `PROC_id` INT NOT NULL AUTO_INCREMENT,
  `PROC_FK_UNID_id` INT NOT NULL,
  `PROC_FK_TIPOP_id` INT NOT NULL,
  `PROC_numero` VARCHAR(20) NULL,
  `PROC_titulo` VARCHAR(100) NULL,
  `PROC_descricao` VARCHAR(500) NULL,
  `PROC_data` DATE NULL,
  `PROC_autor` VARCHAR(50) NULL,
  `PROC_notificar` VARCHAR(100) NULL,
  `PROC_status` VARCHAR(1) NULL,
  PRIMARY KEY (`PROC_id`),
  INDEX `fk_PRO_processo_PRO_tipo_processo1_idx` (`PROC_FK_TIPOP_id` ASC) ,
  INDEX `fk_PRO_processo_TBG_unidade1_idx` (`PROC_FK_UNID_id` ASC) ,
  CONSTRAINT `fk_PRO_processo_PRO_tipo_processo1`
    FOREIGN KEY (`PROC_FK_TIPOP_id`)
    REFERENCES `PRO_tipo_processo` (`TIPOP_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_PRO_processo_TBG_unidade1`
    FOREIGN KEY (`PROC_FK_UNID_id`)
    REFERENCES `TBG_unidade` (`UNID_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `TBG_setor`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `TBG_setor` (
  `SETOR_id` INT NOT NULL AUTO_INCREMENT,
  `SETOR_FK_UNID_id` INT NOT NULL,
  `SETOR_descricao` VARCHAR(50) NULL,
  PRIMARY KEY (`SETOR_id`),
  INDEX `fk_TBG_setor_TBG_unidade1_idx` (`SETOR_FK_UNID_id` ASC) ,
  CONSTRAINT `fk_TBG_setor_TBG_unidade1`
    FOREIGN KEY (`SETOR_FK_UNID_id`)
    REFERENCES `TBG_unidade` (`UNID_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `PRO_tramite`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `PRO_tramite` (
  `TRAM_id` INT NOT NULL AUTO_INCREMENT,
  `TRAM_FK_PROC_id` INT NOT NULL,
  `TRAM_FK_SETOR_id` INT NOT NULL,
  `TRAM_data` DATETIME NULL,
  `TRAM_recebido` DATETIME NULL,
  `TRAM_status` VARCHAR(1) NULL,
  `TRAM_obs` VARCHAR(500) NULL,
  PRIMARY KEY (`TRAM_id`),
  INDEX `fk_PRO_tramite_TBG_setor1_idx` (`TRAM_FK_SETOR_id` ASC) ,
  INDEX `fk_PRO_tramite_PRO_processo1_idx` (`TRAM_FK_PROC_id` ASC) ,
  CONSTRAINT `fk_PRO_tramite_TBG_setor1`
    FOREIGN KEY (`TRAM_FK_SETOR_id`)
    REFERENCES `TBG_setor` (`SETOR_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_PRO_tramite_PRO_processo1`
    FOREIGN KEY (`TRAM_FK_PROC_id`)
    REFERENCES `PRO_processo` (`PROC_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `PRO_notificar`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `PRO_notificar` (
  `NOTI_id` INT NOT NULL AUTO_INCREMENT,
  `NOTI_FK_SETOR_id` INT NOT NULL,
  `NOTI_FK_USUA_id` INT NOT NULL,
  PRIMARY KEY (`NOTI_id`),
  INDEX `fk_PRO_notificar_TBG_setor1_idx` (`NOTI_FK_SETOR_id` ASC) ,
  INDEX `fk_PRO_notificar_TBG_usuario1_idx` (`NOTI_FK_USUA_id` ASC) ,
  CONSTRAINT `fk_PRO_notificar_TBG_setor1`
    FOREIGN KEY (`NOTI_FK_SETOR_id`)
    REFERENCES `TBG_setor` (`SETOR_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_PRO_notificar_TBG_usuario1`
    FOREIGN KEY (`NOTI_FK_USUA_id`)
    REFERENCES `TBG_usuario` (`USUA_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

CREATE TABLE `TBG_log` (
  `LOG_id` int(11) NOT NULL AUTO_INCREMENT,
  `LOG_FK_SIST_id` int(11) NOT NULL,
  `LOG_FK_USUA_id` int(11) NOT NULL,
  `LOG_data` datetime DEFAULT NULL,
  `LOG_descricao` varchar(200) DEFAULT NULL,
  `LOG_dt_criacao` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `LOG_dt_alteracao` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`LOG_id`),
  KEY `LOG_FK_SIST_id` (`LOG_FK_SIST_id`),
  KEY `LOG_FK_USUA_id` (`LOG_FK_USUA_id`),
  CONSTRAINT `TBG_log_ibfk_1` FOREIGN KEY (`LOG_FK_SIST_id`) REFERENCES `TBG_sistema` (`SIST_id`),
  CONSTRAINT `TBG_log_ibfk_2` FOREIGN KEY (`LOG_FK_USUA_id`) REFERENCES `TBG_usuario` (`USUA_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

