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

CREATE SCHEMA IF NOT EXISTS `db_gestion` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
USE `db_gestion` ;

-- -----------------------------------------------------
-- Table `db_gestion`.`passwords_Admin`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `db_gestion`.`passwords_Admin` ;

CREATE  TABLE IF NOT EXISTS `db_gestion`.`passwords_Admin` (
  `user` INT NULL ,
  `passwords` VARCHAR(45) NULL ,
  `administrador_usuario` VARCHAR(10) NOT NULL ,
  PRIMARY KEY (`user`, `administrador_usuario`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `db_gestion`.`administrador`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `db_gestion`.`administrador` ;

CREATE  TABLE IF NOT EXISTS `db_gestion`.`administrador` (
  `usuario` VARCHAR(10) NOT NULL ,
  `nombre` VARCHAR(45) NULL ,
  PRIMARY KEY (`usuario`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `db_gestion`.`subtareas`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `db_gestion`.`subtareas` ;

CREATE  TABLE IF NOT EXISTS `db_gestion`.`subtareas` (
  `id` INT NOT NULL ,
  `nombre` VARCHAR(45) NULL ,
  PRIMARY KEY (`id`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `db_gestion`.`subtareas_has_administrador`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `db_gestion`.`subtareas_has_administrador` ;

CREATE  TABLE IF NOT EXISTS `db_gestion`.`subtareas_has_administrador` (
  `subtareas_id` INT NOT NULL ,
  `administrador_usuario` VARCHAR(10) NOT NULL ,
  PRIMARY KEY (`subtareas_id`, `administrador_usuario`) ,
  INDEX `fk_subtareas_has_administrador_administrador1_idx` (`administrador_usuario` ASC) ,
  INDEX `fk_subtareas_has_administrador_subtareas_idx` (`subtareas_id` ASC) ,
  CONSTRAINT `fk_subtareas_has_administrador_subtareas`
    FOREIGN KEY (`subtareas_id` )
    REFERENCES `db_gestion`.`subtareas` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_subtareas_has_administrador_administrador1`
    FOREIGN KEY (`administrador_usuario` )
    REFERENCES `db_gestion`.`administrador` (`usuario` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `db_gestion`.`Administrador`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `db_gestion`.`Administrador` ;

CREATE  TABLE IF NOT EXISTS `db_gestion`.`Administrador` (
  `Usuario` VARCHAR(30) NOT NULL ,
  `Nombre` VARCHAR(45) NOT NULL ,
  `Apellidos` VARCHAR(45) NOT NULL ,
  PRIMARY KEY (`Usuario`) ,
  UNIQUE INDEX `Usuario_UNIQUE` (`Usuario` ASC) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `db_gestion`.`Pass_Admin`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `db_gestion`.`Pass_Admin` ;

CREATE  TABLE IF NOT EXISTS `db_gestion`.`Pass_Admin` (
  `id` INT NOT NULL AUTO_INCREMENT ,
  `pass` VARCHAR(32) NOT NULL ,
  `Administrador_Usuario` VARCHAR(30) NOT NULL ,
  PRIMARY KEY (`id`, `Administrador_Usuario`) ,
  INDEX `fk_Pass_Admin_Administrador1_idx` (`Administrador_Usuario` ASC) ,
  CONSTRAINT `fk_Pass_Admin_Administrador1`
    FOREIGN KEY (`Administrador_Usuario` )
    REFERENCES `db_gestion`.`Administrador` (`Usuario` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `db_gestion`.`Empleado`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `db_gestion`.`Empleado` ;

CREATE  TABLE IF NOT EXISTS `db_gestion`.`Empleado` (
  `user` VARCHAR(30) NOT NULL ,
  `Nombre` VARCHAR(45) NOT NULL ,
  `ApellidoP` VARCHAR(45) NULL ,
  `ApellidoM` VARCHAR(45) NULL ,
  `Puesto` VARCHAR(45) NULL ,
  `Departamento` VARCHAR(45) NULL ,
  `Email` VARCHAR(45) NOT NULL ,
  `Fecha_Alta` VARCHAR(45) NULL ,
  PRIMARY KEY (`user`) ,
  UNIQUE INDEX `user_UNIQUE` (`user` ASC) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `db_gestion`.`Pass_Emp`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `db_gestion`.`Pass_Emp` ;

CREATE  TABLE IF NOT EXISTS `db_gestion`.`Pass_Emp` (
  `id` INT NOT NULL AUTO_INCREMENT ,
  `pass` VARCHAR(32) NULL ,
  `Empleado_user` VARCHAR(30) NOT NULL ,
  PRIMARY KEY (`id`, `Empleado_user`) ,
  INDEX `fk_Pass_Emp_Empleado1_idx` (`Empleado_user` ASC) ,
  CONSTRAINT `fk_Pass_Emp_Empleado1`
    FOREIGN KEY (`Empleado_user` )
    REFERENCES `db_gestion`.`Empleado` (`user` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `db_gestion`.`Tareas`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `db_gestion`.`Tareas` ;

CREATE  TABLE IF NOT EXISTS `db_gestion`.`Tareas` (
  `id` INT NOT NULL ,
  `Nombre_Tarea` VARCHAR(60) NULL ,
  `Fecha_Inicio` DATE NULL ,
  `Fecha_Termino` DATE NULL ,
  `Prioridad` VARCHAR(10) NULL ,
  `Descripcion_Detallada` VARCHAR(1000) NULL ,
  `Porcentaje_Completo` FLOAT NULL ,
  `Finalizado` TINYINT(1) NULL ,
  `Fecha_Creacion` DATETIME NULL ,
  PRIMARY KEY (`id`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `db_gestion`.`Sub_Tareas`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `db_gestion`.`Sub_Tareas` ;

CREATE  TABLE IF NOT EXISTS `db_gestion`.`Sub_Tareas` (
  `id` INT NOT NULL AUTO_INCREMENT ,
  `Nombre_Tarea` VARCHAR(60) NOT NULL ,
  `Fecha_Inicio` DATE NULL ,
  `Fecha_Termino` DATE NULL ,
  `Prioridad` VARCHAR(10) NULL ,
  `Descripcion_Detallada` VARCHAR(1000) NULL ,
  `Finalizado` TINYINT(1) NULL ,
  `Tareas_id` INT NOT NULL ,
  PRIMARY KEY (`id`, `Tareas_id`) ,
  INDEX `fk_Sub_Tareas_Tareas1_idx` (`Tareas_id` ASC) ,
  UNIQUE INDEX `id_UNIQUE` (`id` ASC) ,
  CONSTRAINT `fk_Sub_Tareas_Tareas1`
    FOREIGN KEY (`Tareas_id` )
    REFERENCES `db_gestion`.`Tareas` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `db_gestion`.`Tareas_has_Empleado`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `db_gestion`.`Tareas_has_Empleado` ;

CREATE  TABLE IF NOT EXISTS `db_gestion`.`Tareas_has_Empleado` (
  `Tareas_id` INT NOT NULL ,
  `Empleado_user` VARCHAR(30) NOT NULL ,
  `Notificado` TINYINT(1) NULL ,
  `Finalizado` TINYINT(1) NULL ,
  PRIMARY KEY (`Tareas_id`, `Empleado_user`) ,
  INDEX `fk_Tareas_has_Empleado_Empleado1_idx` (`Empleado_user` ASC) ,
  INDEX `fk_Tareas_has_Empleado_Tareas1_idx` (`Tareas_id` ASC) ,
  CONSTRAINT `fk_Tareas_has_Empleado_Tareas1`
    FOREIGN KEY (`Tareas_id` )
    REFERENCES `db_gestion`.`Tareas` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_Tareas_has_Empleado_Empleado1`
    FOREIGN KEY (`Empleado_user` )
    REFERENCES `db_gestion`.`Empleado` (`user` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

USE `db_gestion` ;


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