text: -- MySQL Script generated by MySQL Workbench
  -- Fri Mar  9 07:50:15 2018
  -- 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 peief
  -- -----------------------------------------------------
  DROP SCHEMA IF EXISTS `peief` ;
  
  -- -----------------------------------------------------
  -- Schema peief
  -- -----------------------------------------------------
  CREATE SCHEMA IF NOT EXISTS `peief` DEFAULT CHARACTER SET utf8 ;
  USE `peief` ;
  
  -- -----------------------------------------------------
  -- Table `peief`.`states`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`states` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`states` (
    `STTS_PK` INT NOT NULL,
    `STTS_state` VARCHAR(45) NULL,
    PRIMARY KEY (`STTS_PK`))
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`types_identifications`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`types_identifications` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`types_identifications` (
    `TPID_PK` INT NOT NULL,
    `TPDI_type_identification` VARCHAR(45) NULL,
    PRIMARY KEY (`TPID_PK`))
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`genders`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`genders` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`genders` (
    `GNDR_PK` INT NOT NULL,
    `GNDR_gander` VARCHAR(45) NULL,
    PRIMARY KEY (`GNDR_PK`))
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`users`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`users` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`users` (
    `USER_PK` INT(11) NOT NULL,
    `USER_username` VARCHAR(45) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NOT NULL,
    `USER_names` VARCHAR(45) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NOT NULL,
    `USER_lastnames` VARCHAR(45) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NOT NULL,
    `USER_password` VARCHAR(45) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NOT NULL,
    `USER_email` VARCHAR(45) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NOT NULL,
    `USER_address` VARCHAR(45) NOT NULL,
    `USER_telephone` VARCHAR(45) NOT NULL,
    `USER_FK_identification` INT NOT NULL,
    `USER_FK_gender` INT NOT NULL,
    `USER_FK_state` INT NOT NULL,
    `USER_PK_create` INT NULL,
    `USER_date_create` DATETIME NULL,
    `USER_PK_update` VARCHAR(45) NULL,
    `USER_date_update` DATETIME NULL,
    PRIMARY KEY (`USER_PK`),
    INDEX `fk_users_states1_idx` (`USER_FK_state` ASC),
    INDEX `fk_users_types_identifications1_idx` (`USER_FK_identification` ASC),
    INDEX `fk_users_ganders1_idx` (`USER_FK_gender` ASC),
    CONSTRAINT `fk_users_states1`
      FOREIGN KEY (`USER_FK_state`)
      REFERENCES `peief`.`states` (`STTS_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_users_types_identifications1`
      FOREIGN KEY (`USER_FK_identification`)
      REFERENCES `peief`.`types_identifications` (`TPID_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_users_ganders1`
      FOREIGN KEY (`USER_FK_gender`)
      REFERENCES `peief`.`genders` (`GNDR_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB
  AUTO_INCREMENT = 6
  DEFAULT CHARACTER SET = utf8;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`user_profiles`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`user_profiles` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`user_profiles` (
    `id` INT(11) NOT NULL,
    `user_id` INT(11) NOT NULL,
    `country` VARCHAR(20) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NULL DEFAULT NULL,
    `website` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NULL DEFAULT NULL,
    PRIMARY KEY (`id`))
  ENGINE = InnoDB
  AUTO_INCREMENT = 3
  DEFAULT CHARACTER SET = utf8;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`permits`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`permits` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`permits` (
    `PRMS_PK` BIGINT(10) NOT NULL,
    `PRMS_name` VARCHAR(45) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NOT NULL,
    `PRMS_shortname` VARCHAR(45) NOT NULL,
    `PRMS_description` VARCHAR(45) NOT NULL,
    `PRMS_date_create` DATETIME NULL,
    `PRMS_PK_date` INT NULL,
    `PRSM_date_update` DATETIME NULL,
    `PRSM_PK_update` INT NULL,
    PRIMARY KEY (`PRMS_PK`))
  ENGINE = InnoDB
  AUTO_INCREMENT = 30
  DEFAULT CHARACTER SET = utf8
  COLLATE = utf8_bin;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`roles`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`roles` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`roles` (
    `ROLE_PK` BIGINT(10) NOT NULL,
    `ROLE_name` VARCHAR(45) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NOT NULL,
    `ROLE_shortname` VARCHAR(45) CHARACTER SET 'utf8' COLLATE 'utf8_bin' NOT NULL,
    `ROLE_description` LONGTEXT CHARACTER SET 'utf8' COLLATE 'utf8_bin' NOT NULL,
    `ROLE_date_create` DATETIME NULL,
    `ROLE_PK_create` INT NULL,
    `ROLE_date_update` DATETIME NULL,
    `ROLE_PK_update` INT NULL,
    PRIMARY KEY (`ROLE_PK`))
  ENGINE = InnoDB
  AUTO_INCREMENT = 6
  DEFAULT CHARACTER SET = utf8;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`Users_roles`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`Users_roles` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`Users_roles` (
    `USRL_PK` INT NOT NULL,
    `USRL_FK_users` INT(11) NOT NULL,
    `USRL_FK_roles` INT NOT NULL,
    PRIMARY KEY (`USRL_PK`),
    INDEX `fk_Users_role_users_idx` (`USRL_FK_users` ASC),
    INDEX `fk_Users_role_role1_idx` (`USRL_FK_roles` ASC),
    CONSTRAINT `fk_Users_role_users`
      FOREIGN KEY (`USRL_FK_users`)
      REFERENCES `peief`.`users` (`USER_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_Users_role_role1`
      FOREIGN KEY (`USRL_FK_roles`)
      REFERENCES `peief`.`roles` (`ROLE_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`roles_permits`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`roles_permits` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`roles_permits` (
    `RLPR_PK` INT NULL,
    `RLPR_FK_roles` INT NOT NULL,
    `RLPR_FK_permits` INT NOT NULL,
    PRIMARY KEY (`RLPR_PK`),
    INDEX `fk_role_permits_role1_idx` (`RLPR_FK_roles` ASC),
    INDEX `fk_role_permits_permits1_idx` (`RLPR_FK_permits` ASC),
    CONSTRAINT `fk_role_permits_role`
      FOREIGN KEY (`RLPR_FK_roles`)
      REFERENCES `peief`.`roles` (`ROLE_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_role_permits_permits`
      FOREIGN KEY (`RLPR_FK_permits`)
      REFERENCES `peief`.`permits` (`PRMS_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`documentation_users`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`documentation_users` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`documentation_users` (
    `DOCU_PK` INT NOT NULL AUTO_INCREMENT,
    `DOCU_name` VARCHAR(45) NULL,
    `DOCU_description` VARCHAR(45) NULL,
    `DOCU_location` VARCHAR(45) NULL,
    `DOCU_FK_users` INT(11) NOT NULL,
    PRIMARY KEY (`DOCU_PK`),
    INDEX `fk_documentos_usuarios_users1_idx` (`DOCU_FK_users` ASC),
    CONSTRAINT `fk_documentos_usuarios_users`
      FOREIGN KEY (`DOCU_FK_users`)
      REFERENCES `peief`.`users` (`USER_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`focus`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`focus` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`focus` (
    `FOCS_PK` INT NOT NULL,
    `FOCS_name` VARCHAR(45) NULL,
    `FOCS_description` VARCHAR(45) NULL,
    `FOCS_PK_create` INT NULL,
    `FOCS_PK_update` INT NULL,
    `FOCS_date_create` DATETIME NULL,
    `FOCS_date_update` DATETIME NULL,
    PRIMARY KEY (`FOCS_PK`))
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`learning_units`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`learning_units` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`learning_units` (
    `LNUT_PK` INT NOT NULL,
    `LNUT_name` VARCHAR(45) NULL,
    `LNUT_description` TEXT(255) NULL,
    `LNUT_FK_focus` INT NOT NULL,
    `LNUT_date_create` DATETIME NULL,
    `LNUT_PK_create` INT NULL,
    `LNUT_date_update` DATETIME NULL,
    `LNUT_PK_update` INT NULL,
    PRIMARY KEY (`LNUT_PK`),
    INDEX `fk_learning_units_focus1_idx` (`LNUT_FK_focus` ASC),
    CONSTRAINT `fk_learning_units_focus1`
      FOREIGN KEY (`LNUT_FK_focus`)
      REFERENCES `peief`.`focus` (`FOCS_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`subjects`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`subjects` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`subjects` (
    `SBJC_PK` INT NOT NULL,
    `SBJC_name` VARCHAR(45) NULL,
    `SBJC_description` VARCHAR(45) NULL,
    `SBJC_FK_learning_units` INT NOT NULL,
    `SBJC_date_create` DATETIME NULL,
    `SBJC_PK_create` INT NULL,
    `SBJC_date_update` DATETIME NULL,
    `SBJC_PK_update` INT NULL,
    PRIMARY KEY (`SBJC_PK`),
    INDEX `fk_subjects_learning_units1_idx` (`SBJC_FK_learning_units` ASC),
    CONSTRAINT `fk_subjects_learning_units1`
      FOREIGN KEY (`SBJC_FK_learning_units`)
      REFERENCES `peief`.`learning_units` (`LNUT_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`type_projects`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`type_projects` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`type_projects` (
    `TPPJ_PK` INT NOT NULL,
    `TPPJ_type` VARCHAR(45) NULL,
    PRIMARY KEY (`TPPJ_PK`))
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`projects`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`projects` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`projects` (
    `PRJC_PK` INT NOT NULL,
    `PRJC_name` VARCHAR(45) NULL,
    `PRJC_description` TEXT NULL,
    `PRJC_date_start` DATETIME NULL,
    `PRJC_date_final` DATETIME NULL,
    `PRJC_type_projects` INT NOT NULL,
    `PRJC_date_start` DATETIME NULL,
    `PRJC_date_final` DATETIME NULL,
    PRIMARY KEY (`PRJC_PK`),
    INDEX `fk_projects_type_project1_idx` (`PRJC_type_projects` ASC),
    CONSTRAINT `fk_projects_type_project1`
      FOREIGN KEY (`PRJC_type_projects`)
      REFERENCES `peief`.`type_projects` (`TPPJ_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`projects_learning`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`projects_learning` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`projects_learning` (
    `PRLN_PK` INT NOT NULL,
    `PRLN_FK_learning_units` INT NOT NULL,
    `PRLN_FK_projects` INT NOT NULL,
    PRIMARY KEY (`PRLN_PK`),
    INDEX `fk_procyects_learning_learning_units1_idx` (`PRLN_FK_learning_units` ASC),
    INDEX `fk_projects_learning_proyects1_idx` (`PRLN_FK_projects` ASC),
    CONSTRAINT `fk_procyects_learning_learning_units1`
      FOREIGN KEY (`PRLN_FK_learning_units`)
      REFERENCES `peief`.`learning_units` (`LNUT_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_projects_learning_proyects1`
      FOREIGN KEY (`PRLN_FK_projects`)
      REFERENCES `peief`.`projects` (`PRJC_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`versions`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`versions` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`versions` (
    `VRSN_PK` INT NOT NULL,
    `VRSN_name` VARCHAR(45) NULL,
    `VRSN_PK_create` INT NULL,
    `VRSN_PK_update` INT NULL,
    `VRSN_date_create` DATETIME NULL,
    `VRSN_date_update` DATETIME NULL,
    PRIMARY KEY (`VRSN_PK`))
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`plans`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`plans` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`plans` (
    `PLAN_PK` INT NOT NULL,
    `PLAN_name` VARCHAR(45) NULL,
    `PLAN_FK_versions` INT NOT NULL,
    `PLAN_PK_create` INT NULL,
    `PLAN_PK_update` INT NULL,
    `PLAN_date_create` DATETIME NULL,
    `PLAN_date_update` DATETIME NULL,
    PRIMARY KEY (`PLAN_PK`),
    INDEX `fk_plans_versions1_idx` (`PLAN_FK_versions` ASC),
    CONSTRAINT `fk_plans_versions1`
      FOREIGN KEY (`PLAN_FK_versions`)
      REFERENCES `peief`.`versions` (`VRSN_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`cicles`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`cicles` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`cicles` (
    `CCLS_PK` INT NOT NULL,
    `CCLS_name` VARCHAR(45) NULL,
    `CCLS_FK_PLAN` INT NOT NULL,
    `CCLS_date_create` DATETIME NULL,
    `CCLS_PK_create` INT NULL,
    `CCLS_date_update` DATETIME NULL,
    `CCLS_PK_update` INT NULL,
    PRIMARY KEY (`CCLS_PK`),
    INDEX `fk_cicles_plans1_idx` (`CCLS_FK_PLAN` ASC),
    CONSTRAINT `fk_cicles_plans1`
      FOREIGN KEY (`CCLS_FK_PLAN`)
      REFERENCES `peief`.`plans` (`PLAN_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`users_students`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`users_students` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`users_students` (
    `SRST_PK` INT NOT NULL,
    `Users_roles_id` INT NOT NULL,
    `cicles_id` INT NOT NULL,
    PRIMARY KEY (`SRST_PK`),
    INDEX `fk_users_students_Users_roles1_idx` (`Users_roles_id` ASC),
    INDEX `fk_users_students_cicles1_idx` (`cicles_id` ASC),
    CONSTRAINT `fk_users_students_Users_roles1`
      FOREIGN KEY (`Users_roles_id`)
      REFERENCES `peief`.`Users_roles` (`USRL_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_users_students_cicles1`
      FOREIGN KEY (`cicles_id`)
      REFERENCES `peief`.`cicles` (`CCLS_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`cicles_subjects`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`cicles_subjects` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`cicles_subjects` (
    `CLSB_PK` INT NOT NULL,
    `CLSB_credits` INT NOT NULL,
    `CLSB_hourlyintensity` INT NOT NULL,
    `CLSB_FK_subjects` INT NOT NULL,
    `CLSB_FK_cicles` INT NOT NULL,
    `CLSB_date_create` DATETIME NULL,
    `CLSB_PK_create` INT NULL,
    `CLSB_date_update` DATETIME NULL,
    `CLSB_PK_update` INT NULL,
    INDEX `fk_curso materias_subjects1_idx` (`CLSB_FK_subjects` ASC),
    INDEX `fk_curso materias_cursos1_idx` (`CLSB_FK_cicles` ASC),
    PRIMARY KEY (`CLSB_PK`),
    CONSTRAINT `fk_curso materias_subjects1`
      FOREIGN KEY (`CLSB_FK_subjects`)
      REFERENCES `peief`.`subjects` (`SBJC_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_curso materias_cursos1`
      FOREIGN KEY (`CLSB_FK_cicles`)
      REFERENCES `peief`.`cicles` (`CCLS_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`categories`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`categories` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`categories` (
    `CTGR_PK` INT NOT NULL,
    `CTGR_order` INT NULL,
    `CTGR_name` VARCHAR(45) NULL,
    `CTGR_description` TEXT NULL,
    PRIMARY KEY (`CTGR_PK`))
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`enrollment_online`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`enrollment_online` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`enrollment_online` (
    `NRLM_PK` INT NOT NULL,
    `NRLM_users_members_cicles` INT NOT NULL,
    `NRLM_name` VARCHAR(45) NULL,
    `NRLM_date_start` DATETIME NULL,
    `NRLM_date_final` DATETIME NULL,
    `NRLM_value` VARCHAR(45) NULL,
    PRIMARY KEY (`NRLM_PK`),
    INDEX `fk_metodosenrolamiento_users_members_cicles1_idx` (`NRLM_users_members_cicles` ASC),
    CONSTRAINT `fk_metodosenrolamiento_users_members_cicles1`
      FOREIGN KEY (`NRLM_users_members_cicles`)
      REFERENCES `peief`.`users_students` (`SRST_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`cuotas`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`cuotas` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`cuotas` (
    `CUTA_PK` INT NOT NULL,
    `CUTA_FK_enrollment` INT NOT NULL,
    `CUTA_reference` VARCHAR(45) NULL,
    `CUTA_date_start` DATETIME NULL,
    `CUTA_date_final` DATETIME NULL,
    PRIMARY KEY (`CUTA_PK`),
    INDEX `fk_cuota_enrollment_online1_idx` (`CUTA_FK_enrollment` ASC),
    CONSTRAINT `fk_cuota_enrollment_online1`
      FOREIGN KEY (`CUTA_FK_enrollment`)
      REFERENCES `peief`.`enrollment_online` (`NRLM_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`stages`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`stages` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`stages` (
    `STGS_PK` INT NOT NULL,
    `STGS_name` VARCHAR(45) NULL,
    `STGS_description` VARCHAR(255) NULL,
    `STGS_FK_projects` INT NOT NULL,
    `STGS_date_start` DATETIME NULL,
    `STGS_date_final` DATETIME NULL,
    `STGS_order` INT NULL,
    PRIMARY KEY (`STGS_PK`),
    INDEX `fk_stages_projects1_idx` (`STGS_FK_projects` ASC),
    CONSTRAINT `fk_stages_projects1`
      FOREIGN KEY (`STGS_FK_projects`)
      REFERENCES `peief`.`projects` (`PRJC_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`activities`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`activities` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`activities` (
    `CTVT_PK` INT NOT NULL,
    `CTVT_name` VARCHAR(45) NULL,
    `CTVT_description` VARCHAR(255) NULL,
    `CTVT_duration` VARCHAR(45) NULL,
    `CTVT_FK_stages` INT NOT NULL,
    `CTVT_order` INT NULL,
    `CTVT_status` INT NULL,
    `CTVT_result` INT NULL,
    PRIMARY KEY (`CTVT_PK`),
    INDEX `fk_activities_stages1_idx` (`CTVT_FK_stages` ASC),
    CONSTRAINT `fk_activities_stages1`
      FOREIGN KEY (`CTVT_FK_stages`)
      REFERENCES `peief`.`stages` (`STGS_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`groups`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`groups` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`groups` (
    `GRUP_PK` INT NOT NULL,
    `GRUP_name` VARCHAR(45) NULL,
    `cicles_CCLS_PK` INT NOT NULL,
    `Docente_idDocente` INT NOT NULL,
    PRIMARY KEY (`GRUP_PK`),
    INDEX `fk_groups_cicles1_idx` (`cicles_CCLS_PK` ASC),
    CONSTRAINT `fk_groups_cicles1`
      FOREIGN KEY (`cicles_CCLS_PK`)
      REFERENCES `peief`.`cicles` (`CCLS_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`values`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`values` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`values` (
    `VALS_PK` INT NOT NULL,
    `VALS_value` INT NULL,
    `VALS_FK_cuotas` INT NOT NULL,
    `VALS_date_start` DATETIME NULL,
    `VALS_date_final` DATETIME NULL,
    PRIMARY KEY (`VALS_PK`),
    INDEX `fk_values_cuota1_idx` (`VALS_FK_cuotas` ASC),
    CONSTRAINT `fk_values_cuota1`
      FOREIGN KEY (`VALS_FK_cuotas`)
      REFERENCES `peief`.`cuotas` (`CUTA_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`news`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`news` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`news` (
    `NEWS_PK` INT NOT NULL,
    `NEWS_priority` INT NULL,
    `NEWS_title` VARCHAR(45) NULL,
    `NEWS_subtitle` VARCHAR(45) NULL,
    `NEWS_date_create` DATETIME NULL,
    `NEWS_date_update` DATETIME NULL,
    `NESW_PK_create` INT NULL,
    `NEWS_PK_update` INT NULL,
    `NEWS_content` TEXT NULL,
    `NEWS_note` VARCHAR(255) NULL,
    PRIMARY KEY (`NEWS_PK`))
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`subcategories`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`subcategories` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`subcategories` (
    `SBCG_PK` INT NOT NULL,
    `SBCG_FK_categories` INT NOT NULL,
    `SBCG_name` VARCHAR(45) NULL,
    `SBCG_description` TEXT NULL,
    PRIMARY KEY (`SBCG_PK`),
    INDEX `fk_subcategoria_categoria1_idx` (`SBCG_FK_categories` ASC),
    CONSTRAINT `fk_subcategoria_categoria1`
      FOREIGN KEY (`SBCG_FK_categories`)
      REFERENCES `peief`.`categories` (`CTGR_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`categories_news`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`categories_news` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`categories_news` (
    `CGNW_PK` INT NOT NULL,
    `CGNW_FK_news` INT NOT NULL,
    `CGNW_FK_subcategories` INT NOT NULL,
    PRIMARY KEY (`CGNW_PK`),
    INDEX `fk_categorias_noticias_noticias1_idx` (`CGNW_FK_news` ASC),
    INDEX `fk_categorias_noticias_subcategoria1_idx` (`CGNW_FK_subcategories` ASC),
    CONSTRAINT `fk_categorias_noticias_noticias1`
      FOREIGN KEY (`CGNW_FK_news`)
      REFERENCES `peief`.`news` (`NEWS_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_categorias_noticias_subcategoria1`
      FOREIGN KEY (`CGNW_FK_subcategories`)
      REFERENCES `peief`.`subcategories` (`SBCG_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`comments`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`comments` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`comments` (
    `CMTS_PK` INT NOT NULL,
    `CMTS_FK_news` INT NOT NULL,
    `CMTS_FK_user` INT NULL,
    `CMTS_content` TEXT NULL,
    PRIMARY KEY (`CMTS_PK`),
    INDEX `fk_comentarios_noticias1_idx` (`CMTS_FK_news` ASC),
    CONSTRAINT `fk_comentarios_noticias1`
      FOREIGN KEY (`CMTS_FK_news`)
      REFERENCES `peief`.`news` (`NEWS_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`context`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`context` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`context` (
    `CTX_PK` INT NOT NULL,
    `Users_roles_USRL_PK` INT NOT NULL,
    `categories_CTGR_PK` INT NOT NULL,
    `projects_PRJC_PK` INT NOT NULL,
    `learning_units_LNUT_PK` INT NOT NULL,
    PRIMARY KEY (`CTX_PK`),
    INDEX `fk_context_Users_roles1_idx` (`Users_roles_USRL_PK` ASC),
    INDEX `fk_context_categories1_idx` (`categories_CTGR_PK` ASC),
    INDEX `fk_context_projects1_idx` (`projects_PRJC_PK` ASC),
    INDEX `fk_context_learning_units1_idx` (`learning_units_LNUT_PK` ASC),
    CONSTRAINT `fk_context_Users_roles1`
      FOREIGN KEY (`Users_roles_USRL_PK`)
      REFERENCES `peief`.`Users_roles` (`USRL_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_context_categories1`
      FOREIGN KEY (`categories_CTGR_PK`)
      REFERENCES `peief`.`categories` (`CTGR_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_context_projects1`
      FOREIGN KEY (`projects_PRJC_PK`)
      REFERENCES `peief`.`projects` (`PRJC_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_context_learning_units1`
      FOREIGN KEY (`learning_units_LNUT_PK`)
      REFERENCES `peief`.`learning_units` (`LNUT_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `peief`.`users_teacher`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `peief`.`users_teacher` ;
  
  CREATE TABLE IF NOT EXISTS `peief`.`users_teacher` (
    `Users_roles_id` INT NOT NULL,
    `cicles_subjects_id` INT NOT NULL,
    INDEX `fk_users_teacher_Users_roles1_idx` (`Users_roles_id` ASC),
    INDEX `fk_users_teacher_cicles_subjects1_idx` (`cicles_subjects_id` ASC),
    CONSTRAINT `fk_users_teacher_Users_roles1`
      FOREIGN KEY (`Users_roles_id`)
      REFERENCES `peief`.`Users_roles` (`USRL_PK`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_users_teacher_cicles_subjects1`
      FOREIGN KEY (`cicles_subjects_id`)
      REFERENCES `peief`.`cicles_subjects` (`CLSB_PK`)
      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;
  