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';

CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ;

-- -----------------------------------------------------
-- Table `mydb`.`database_list`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mydb`.`database_list` (
  `ID` INT NOT NULL AUTO_INCREMENT ,
  `db_name` VARCHAR(100) NULL ,
  `db_release` VARCHAR(45) NULL ,
  `description` VARCHAR(255) NULL ,
  PRIMARY KEY (`ID`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`organism`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mydb`.`organism` (
  `ID` INT NOT NULL AUTO_INCREMENT ,
  `taxon_id` INT NULL ,
  `org_name` VARCHAR(255) NULL ,
  `description` VARCHAR(255) NULL ,
  PRIMARY KEY (`ID`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`entry`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mydb`.`entry` (
  `ID` INT NOT NULL AUTO_INCREMENT ,
  `entry_id` VARCHAR(100) NULL ,
  `entry_name` VARCHAR(100) NULL ,
  `database_list_ID` INT NOT NULL ,
  `organism_ID` INT NOT NULL ,
  PRIMARY KEY (`ID`) ,
  INDEX `fk_entry_database_list` (`database_list_ID` ASC) ,
  INDEX `fk_entry_organism1` (`organism_ID` ASC) ,
  CONSTRAINT `fk_entry_database_list`
    FOREIGN KEY (`database_list_ID` )
    REFERENCES `mydb`.`database_list` (`ID` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_entry_organism1`
    FOREIGN KEY (`organism_ID` )
    REFERENCES `mydb`.`organism` (`ID` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`xref_db`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mydb`.`xref_db` (
  `ID` INT NOT NULL AUTO_INCREMENT ,
  `xref_db_name` VARCHAR(45) NULL ,
  `db_display_name` VARCHAR(255) NULL ,
  `description` VARCHAR(255) NULL ,
  PRIMARY KEY (`ID`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`entry_xref_db`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mydb`.`entry_xref_db` (
  `ID` INT NOT NULL ,
  `entry_ID` INT NOT NULL ,
  `xref_db_ID` INT NOT NULL ,
  INDEX `fk_entry_xref_db_entry1` (`entry_ID` ASC) ,
  INDEX `fk_entry_xref_db_xref_db1` (`xref_db_ID` ASC) ,
  PRIMARY KEY (`ID`) ,
  CONSTRAINT `fk_entry_xref_db_entry1`
    FOREIGN KEY (`entry_ID` )
    REFERENCES `mydb`.`entry` (`ID` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_entry_xref_db_xref_db1`
    FOREIGN KEY (`xref_db_ID` )
    REFERENCES `mydb`.`xref_db` (`ID` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`xref_value`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mydb`.`xref_value` (
  `ID` INT NOT NULL AUTO_INCREMENT ,
  `entry_xref_db_ID` INT NOT NULL ,
  `acc_no` VARCHAR(45) NULL ,
  `display_label` VARCHAR(128) NULL ,
  `description` VARCHAR(255) NULL ,
  PRIMARY KEY (`ID`) ,
  INDEX `fk_xref_value_entry_xref_db1` (`entry_xref_db_ID` ASC) ,
  CONSTRAINT `fk_xref_value_entry_xref_db1`
    FOREIGN KEY (`entry_xref_db_ID` )
    REFERENCES `mydb`.`entry_xref_db` (`ID` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`synonym`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mydb`.`synonym` (
  `ID` INT NOT NULL AUTO_INCREMENT ,
  `entry_ID` INT NOT NULL ,
  `synonym_name` VARCHAR(255) NULL ,
  PRIMARY KEY (`ID`) ,
  INDEX `fk_synonym_entry1` (`entry_ID` ASC) ,
  CONSTRAINT `fk_synonym_entry1`
    FOREIGN KEY (`entry_ID` )
    REFERENCES `mydb`.`entry` (`ID` )
    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;
