text: -- MySQL Script generated by MySQL Workbench
  -- 12/31/16 14:49:19
  -- Model: New Model    Version: 1.0
  -- 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 pathology
  -- -----------------------------------------------------
  DROP SCHEMA IF EXISTS `pathology` ;
  
  -- -----------------------------------------------------
  -- Schema pathology
  -- -----------------------------------------------------
  CREATE SCHEMA IF NOT EXISTS `pathology` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
  USE `pathology` ;
  
  -- -----------------------------------------------------
  -- Table `pathology`.`tb_patient`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `pathology`.`tb_patient` ;
  
  CREATE TABLE IF NOT EXISTS `pathology`.`tb_patient` (
    `cd_patient` INT NOT NULL AUTO_INCREMENT COMMENT '',
    `nm_patient` VARCHAR(80) NULL COMMENT '',
    `ic_active` TINYINT(1) NULL COMMENT '',
    PRIMARY KEY (`cd_patient`)  COMMENT '')
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `pathology`.`tb_doctor`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `pathology`.`tb_doctor` ;
  
  CREATE TABLE IF NOT EXISTS `pathology`.`tb_doctor` (
    `cd_doctor` INT NOT NULL AUTO_INCREMENT COMMENT '',
    `nm_doctor` VARCHAR(80) NOT NULL COMMENT '',
    `cd_id_doctor` TEXT NULL COMMENT '',
    `ic_active` TINYINT(1) NULL COMMENT '',
    PRIMARY KEY (`cd_doctor`)  COMMENT '')
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `pathology`.`tb_exam`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `pathology`.`tb_exam` ;
  
  CREATE TABLE IF NOT EXISTS `pathology`.`tb_exam` (
    `cd_exam` INT NOT NULL AUTO_INCREMENT COMMENT '',
    `cd_doctor` INT NOT NULL COMMENT '',
    `cd_patient` INT NOT NULL COMMENT '',
    `cd_sku` INT NULL COMMENT '',
    `ds_exam` LONGTEXT NULL COMMENT '',
    `ic_active` TINYINT(1) NULL COMMENT '',
    INDEX `fk_tb_doctor_has_tb_patient_tb_patient1_idx` (`cd_patient` ASC)  COMMENT '',
    INDEX `fk_tb_doctor_has_tb_patient_tb_doctor_idx` (`cd_doctor` ASC)  COMMENT '',
    PRIMARY KEY (`cd_exam`)  COMMENT '',
    CONSTRAINT `fk_tb_doctor_has_tb_patient_tb_doctor`
      FOREIGN KEY (`cd_doctor`)
      REFERENCES `pathology`.`tb_doctor` (`cd_doctor`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_tb_doctor_has_tb_patient_tb_patient1`
      FOREIGN KEY (`cd_patient`)
      REFERENCES `pathology`.`tb_patient` (`cd_patient`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `pathology`.`tb_specialty`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `pathology`.`tb_specialty` ;
  
  CREATE TABLE IF NOT EXISTS `pathology`.`tb_specialty` (
    `cd_specialty` INT NOT NULL AUTO_INCREMENT COMMENT '',
    `nm_specialty` VARCHAR(80) NULL COMMENT '',
    `ic_active` TINYINT(1) NULL COMMENT '',
    PRIMARY KEY (`cd_specialty`)  COMMENT '')
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `pathology`.`tb_doctor_specialty`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `pathology`.`tb_doctor_specialty` ;
  
  CREATE TABLE IF NOT EXISTS `pathology`.`tb_doctor_specialty` (
    `cd_doctor_speciality` INT NOT NULL AUTO_INCREMENT COMMENT '',
    `cd_doctor` INT NOT NULL COMMENT '',
    `cd_specialty` INT NOT NULL COMMENT '',
    INDEX `fk_tb_doctor_has_tb_specialty_tb_specialty1_idx` (`cd_specialty` ASC)  COMMENT '',
    INDEX `fk_tb_doctor_has_tb_specialty_tb_doctor1_idx` (`cd_doctor` ASC)  COMMENT '',
    PRIMARY KEY (`cd_doctor_speciality`)  COMMENT '',
    CONSTRAINT `fk_tb_doctor_has_tb_specialty_tb_doctor1`
      FOREIGN KEY (`cd_doctor`)
      REFERENCES `pathology`.`tb_doctor` (`cd_doctor`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_tb_doctor_has_tb_specialty_tb_specialty1`
      FOREIGN KEY (`cd_specialty`)
      REFERENCES `pathology`.`tb_specialty` (`cd_specialty`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `pathology`.`tb_user_control`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `pathology`.`tb_user_control` ;
  
  CREATE TABLE IF NOT EXISTS `pathology`.`tb_user_control` (
    `cd_user_control` INT NOT NULL AUTO_INCREMENT COMMENT '',
    `nm_control` VARCHAR(45) NULL COMMENT '',
    `ic_active` TINYINT(1) NULL COMMENT '',
    PRIMARY KEY (`cd_user_control`)  COMMENT '')
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `pathology`.`tb_user`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `pathology`.`tb_user` ;
  
  CREATE TABLE IF NOT EXISTS `pathology`.`tb_user` (
    `cd_user` INT NOT NULL AUTO_INCREMENT COMMENT '',
    `cd_user_control` INT NOT NULL COMMENT '',
    `cd_patient` INT NULL COMMENT '',
    `cd_doctor` INT NULL COMMENT '',
    `nm_user` VARCHAR(80) NULL COMMENT '',
    `ds_pass` LONGTEXT NULL COMMENT '',
    `ic_active` TINYINT(1) NULL COMMENT '',
    PRIMARY KEY (`cd_user`)  COMMENT '',
    INDEX `fk_tb_user_tb_patient1_idx` (`cd_patient` ASC)  COMMENT '',
    INDEX `fk_tb_user_tb_doctor1_idx` (`cd_doctor` ASC)  COMMENT '',
    INDEX `fk_tb_user_tb_user_control1_idx` (`cd_user_control` ASC)  COMMENT '',
    CONSTRAINT `fk_tb_user_tb_patient1`
      FOREIGN KEY (`cd_patient`)
      REFERENCES `pathology`.`tb_patient` (`cd_patient`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_tb_user_tb_doctor1`
      FOREIGN KEY (`cd_doctor`)
      REFERENCES `pathology`.`tb_doctor` (`cd_doctor`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_tb_user_tb_user_control1`
      FOREIGN KEY (`cd_user_control`)
      REFERENCES `pathology`.`tb_user_control` (`cd_user_control`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  SET SQL_MODE=@OLD_SQL_MODE;
  SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
  SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
  
  -- -----------------------------------------------------
  -- Data for table `pathology`.`tb_patient`
  -- -----------------------------------------------------
  START TRANSACTION;
  USE `pathology`;
  INSERT INTO `pathology`.`tb_patient` (`cd_patient`, `nm_patient`, `ic_active`) VALUES (DEFAULT, 'Fabio William', 1);
  
  COMMIT;
  
  
  -- -----------------------------------------------------
  -- Data for table `pathology`.`tb_doctor`
  -- -----------------------------------------------------
  START TRANSACTION;
  USE `pathology`;
  INSERT INTO `pathology`.`tb_doctor` (`cd_doctor`, `nm_doctor`, `cd_id_doctor`, `ic_active`) VALUES (DEFAULT, 'William', 'CMR-1002', 1);
  
  COMMIT;
  
  
  -- -----------------------------------------------------
  -- Data for table `pathology`.`tb_specialty`
  -- -----------------------------------------------------
  START TRANSACTION;
  USE `pathology`;
  INSERT INTO `pathology`.`tb_specialty` (`cd_specialty`, `nm_specialty`, `ic_active`) VALUES (DEFAULT, 'neurologist', 1);
  INSERT INTO `pathology`.`tb_specialty` (`cd_specialty`, `nm_specialty`, `ic_active`) VALUES (DEFAULT, 'cardiologist', 1);
  INSERT INTO `pathology`.`tb_specialty` (`cd_specialty`, `nm_specialty`, `ic_active`) VALUES (DEFAULT, 'pulmonologist', 1);
  
  COMMIT;
  
  
  -- -----------------------------------------------------
  -- Data for table `pathology`.`tb_doctor_specialty`
  -- -----------------------------------------------------
  START TRANSACTION;
  USE `pathology`;
  INSERT INTO `pathology`.`tb_doctor_specialty` (`cd_doctor_speciality`, `cd_doctor`, `cd_specialty`) VALUES (DEFAULT, 1, 1);
  
  COMMIT;
  
  
  -- -----------------------------------------------------
  -- Data for table `pathology`.`tb_user_control`
  -- -----------------------------------------------------
  START TRANSACTION;
  USE `pathology`;
  INSERT INTO `pathology`.`tb_user_control` (`cd_user_control`, `nm_control`, `ic_active`) VALUES (DEFAULT, 'admin', 1);
  INSERT INTO `pathology`.`tb_user_control` (`cd_user_control`, `nm_control`, `ic_active`) VALUES (DEFAULT, 'patient', 1);
  INSERT INTO `pathology`.`tb_user_control` (`cd_user_control`, `nm_control`, `ic_active`) VALUES (DEFAULT, 'doctor', 1);
  
  COMMIT;
  
  
  -- -----------------------------------------------------
  -- Data for table `pathology`.`tb_user`
  -- -----------------------------------------------------
  START TRANSACTION;
  USE `pathology`;
  INSERT INTO `pathology`.`tb_user` (`cd_user`, `cd_user_control`, `cd_patient`, `cd_doctor`, `nm_user`, `ds_pass`, `ic_active`) VALUES (DEFAULT, 1, NULL, NULL, 'messhias@gmail.com', '123', 1);
  INSERT INTO `pathology`.`tb_user` (`cd_user`, `cd_user_control`, `cd_patient`, `cd_doctor`, `nm_user`, `ds_pass`, `ic_active`) VALUES (DEFAULT, 2, 1, NULL, 'william@gmail.com', '123', 1);
  INSERT INTO `pathology`.`tb_user` (`cd_user`, `cd_user_control`, `cd_patient`, `cd_doctor`, `nm_user`, `ds_pass`, `ic_active`) VALUES (DEFAULT, 3,NULL, 1, 'doctor@gmail.com', '123', 1);
  
  COMMIT;
  
  
  CREATE TABLE IF NOT EXISTS `ci_sessions` (
          `id` varchar(128) NOT NULL,
          `ip_address` varchar(45) NOT NULL,
          `timestamp` int(10) unsigned DEFAULT 0 NOT NULL,
          `data` blob NOT NULL,
          KEY `ci_sessions_timestamp` (`timestamp`)
  );