text: -- MySQL Script generated by MySQL Workbench
  -- 08/14/17 13:05:23
  -- 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 monicapp
  -- -----------------------------------------------------
  
  -- -----------------------------------------------------
  -- Schema monicapp
  -- -----------------------------------------------------
  CREATE SCHEMA IF NOT EXISTS `monicapp` DEFAULT CHARACTER SET utf8 COLLATE utf8_spanish2_ci ;
  USE `monicapp` ;
  
  -- -----------------------------------------------------
  -- Table `monicapp`.`grupo`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `monicapp`.`grupo` ;
  
  CREATE TABLE IF NOT EXISTS `monicapp`.`grupo` (
    `codigo` VARCHAR(25) NOT NULL,
    `nombre` VARCHAR(50) NOT NULL,
    `fecha` DATE NOT NULL,
    `cantidad_miembros` INT NULL,
    PRIMARY KEY (`codigo`))
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `monicapp`.`user`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `monicapp`.`user` ;
  
  CREATE TABLE IF NOT EXISTS `monicapp`.`user` (
    `id` VARCHAR(20) NOT NULL,
    `email` VARCHAR(45) NOT NULL,
    `username` VARCHAR(40) NOT NULL,
    `token` VARCHAR(250) NULL,
    `password` VARCHAR(45) NOT NULL,
    `grupo_codigo` VARCHAR(25) NULL,
    UNIQUE INDEX `email_UNIQUE` (`email` ASC),
    PRIMARY KEY (`id`),
    INDEX `fk_user_grupo1_idx` (`grupo_codigo` ASC),
    CONSTRAINT `fk_user_grupo1`
      FOREIGN KEY (`grupo_codigo`)
      REFERENCES `monicapp`.`grupo` (`codigo`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `monicapp`.`ingreso`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `monicapp`.`ingreso` ;
  
  CREATE TABLE IF NOT EXISTS `monicapp`.`ingreso` (
    `codigo` VARCHAR(25) NOT NULL,
    `user_id` VARCHAR(20) NOT NULL,
    `nombre` VARCHAR(50) NOT NULL,
    `valor` DOUBLE NOT NULL DEFAULT 0,
    `frecuencia` VARCHAR(30) NULL,
    PRIMARY KEY (`codigo`, `user_id`),
    INDEX `fk_ingreso_user1_idx` (`user_id` ASC),
    CONSTRAINT `fk_ingreso_user1`
      FOREIGN KEY (`user_id`)
      REFERENCES `monicapp`.`user` (`id`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `monicapp`.`actividad`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `monicapp`.`actividad` ;
  
  CREATE TABLE IF NOT EXISTS `monicapp`.`actividad` (
    `codigo` VARCHAR(25) NOT NULL,
    `user_email` VARCHAR(45) NOT NULL,
    `monto` DOUBLE NULL,
    `fecha_creacion` DATE NOT NULL,
    `fecha_definida` DATE NOT NULL,
    `lugar` VARCHAR(50) NULL,
    PRIMARY KEY (`codigo`),
    INDEX `fk_actividad_user1_idx` (`user_email` ASC),
    CONSTRAINT `fk_actividad_user1`
      FOREIGN KEY (`user_email`)
      REFERENCES `monicapp`.`user` (`email`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `monicapp`.`obligacion`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `monicapp`.`obligacion` ;
  
  CREATE TABLE IF NOT EXISTS `monicapp`.`obligacion` (
    `codigo` INT NOT NULL AUTO_INCREMENT,
    `grupo_codigo` VARCHAR(25) NOT NULL,
    `nombre` VARCHAR(45) NOT NULL,
    `monto` DOUBLE NULL DEFAULT 0,
    `fecha_fin` DATE NULL,
    `frecuencia` VARCHAR(45) NOT NULL,
    `porcentaje` DOUBLE NULL,
    PRIMARY KEY (`codigo`, `grupo_codigo`),
    INDEX `fk_obligacion_grupo1_idx` (`grupo_codigo` ASC),
    CONSTRAINT `fk_obligacion_grupo1`
      FOREIGN KEY (`grupo_codigo`)
      REFERENCES `monicapp`.`grupo` (`codigo`)
      ON DELETE NO ACTION
      ON UPDATE CASCADE)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `monicapp`.`meta`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `monicapp`.`meta` ;
  
  CREATE TABLE IF NOT EXISTS `monicapp`.`meta` (
    `codigo` VARCHAR(45) NOT NULL,
    `grupo_codigo` VARCHAR(25) NOT NULL,
    `nombre` VARCHAR(45) NOT NULL,
    `descripcion` VARCHAR(45) NULL,
    `valor` DOUBLE NOT NULL,
    `fecha_inicio` DATE NOT NULL,
    `fecha_fin` DATE NOT NULL,
    `estado` VARCHAR(45) NOT NULL,
    `frecuencia` VARCHAR(45) NULL,
    PRIMARY KEY (`codigo`),
    INDEX `fk_meta_grupo1_idx` (`grupo_codigo` ASC),
    CONSTRAINT `fk_meta_grupo1`
      FOREIGN KEY (`grupo_codigo`)
      REFERENCES `monicapp`.`grupo` (`codigo`)
      ON DELETE NO ACTION
      ON UPDATE CASCADE)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `monicapp`.`pagoObligacion`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `monicapp`.`pagoObligacion` ;
  
  CREATE TABLE IF NOT EXISTS `monicapp`.`pagoObligacion` (
    `codigo` VARCHAR(25) NOT NULL,
    `obligacion_codigo` INT NOT NULL,
    `user_id` VARCHAR(20) NOT NULL,
    `fecha` DATE NOT NULL,
    `monto` DOUBLE NULL,
    PRIMARY KEY (`codigo`, `obligacion_codigo`),
    INDEX `fk_pagoObligacion_obligacion1_idx` (`obligacion_codigo` ASC),
    INDEX `fk_pagoObligacion_user1_idx` (`user_id` ASC),
    CONSTRAINT `fk_pagoObligacion_obligacion1`
      FOREIGN KEY (`obligacion_codigo`)
      REFERENCES `monicapp`.`obligacion` (`codigo`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_pagoObligacion_user1`
      FOREIGN KEY (`user_id`)
      REFERENCES `monicapp`.`user` (`id`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `monicapp`.`abonoMeta`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `monicapp`.`abonoMeta` ;
  
  CREATE TABLE IF NOT EXISTS `monicapp`.`abonoMeta` (
    `user_id` VARCHAR(20) NOT NULL,
    `meta_grupo_codigo` VARCHAR(25) NOT NULL,
    `fecha` DATE NOT NULL,
    `monto` DOUBLE NULL,
    PRIMARY KEY (`user_id`, `meta_grupo_codigo`),
    INDEX `fk_abonoMeta_user1_idx` (`user_id` ASC),
    INDEX `fk_abonoMeta_meta1_idx` (`meta_grupo_codigo` ASC),
    CONSTRAINT `fk_abonoMeta_user1`
      FOREIGN KEY (`user_id`)
      REFERENCES `monicapp`.`user` (`id`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_abonoMeta_meta1`
      FOREIGN KEY (`meta_grupo_codigo`)
      REFERENCES `monicapp`.`meta` (`grupo_codigo`)
      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;
  