text: -- MySQL Script generated by MySQL Workbench
  -- Thu Jan 19 21:46:46 2017
  -- 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 mydb
  -- -----------------------------------------------------
  
  -- -----------------------------------------------------
  -- Table `role`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `role` ;
  
  CREATE TABLE IF NOT EXISTS `role` (
    `id` INT NOT NULL AUTO_INCREMENT COMMENT '',
    `name` VARCHAR(300) NULL COMMENT '',
    PRIMARY KEY (`id`)  COMMENT '',
    UNIQUE INDEX `id_UNIQUE` (`id` ASC)  COMMENT '')
  ENGINE = InnoDB;
  
  -- -----------------------------------------------------
  -- Table `user`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `user` ;
  
  CREATE TABLE IF NOT EXISTS `user` (
    `id` INT NOT NULL AUTO_INCREMENT COMMENT '',
    `username` VARCHAR(40) NULL COMMENT '',
    `password` VARCHAR(40) NULL COMMENT '',
    `full_name` VARCHAR(300) NULL COMMENT '',
    `email` VARCHAR(300) NULL COMMENT '',
    `active` INT(1) NULL COMMENT '',
    `role_id` INT NULL COMMENT '',
    PRIMARY KEY (`id`)  COMMENT '',
    UNIQUE INDEX `id_UNIQUE` (`id` ASC)  COMMENT '',
    INDEX `fk_user_role_idx` (`role_id` ASC)  COMMENT '',
    CONSTRAINT `fk_user_role`
      FOREIGN KEY (`role_id`)
      REFERENCES `role` (`id`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  -- -----------------------------------------------------
  -- Table `module`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `module` ;
  
  CREATE TABLE IF NOT EXISTS `module` (
    `id` INT NOT NULL AUTO_INCREMENT COMMENT '',
    `name` VARCHAR(100) NULL COMMENT '',
    PRIMARY KEY (`id`)  COMMENT '',
    UNIQUE INDEX `idmodule_UNIQUE` (`id` ASC)  COMMENT '')
  ENGINE = InnoDB;
  
  -- -----------------------------------------------------
  -- Table `menu`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `menu` ;
  
  CREATE TABLE IF NOT EXISTS `menu` (
    `id` INT NOT NULL AUTO_INCREMENT COMMENT '',
    `url` VARCHAR(100) NULL COMMENT '',
    `label` VARCHAR(150) NULL COMMENT '',
    `parent` INT(11) NULL COMMENT '',
    `module_id` INT(11),
    PRIMARY KEY (`id`)  COMMENT '',
    UNIQUE INDEX `idmenu_UNIQUE` (`id` ASC)  COMMENT '',
     CONSTRAINT `fk_menu_module`
      FOREIGN KEY (`module_id`)
      REFERENCES `module` (`id`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `privilege`
  -- -----------------------------------------------------
  DROP TABLE IF EXISTS `privilege` ;
  
  CREATE TABLE IF NOT EXISTS `privilege` (
    `id` INT NOT NULL AUTO_INCREMENT COMMENT '',
    `role_id` INT NOT NULL COMMENT '',
    `menu_id` INT NOT NULL COMMENT '',
    PRIMARY KEY (`id`)  COMMENT '',
    UNIQUE INDEX `id_UNIQUE` (`id` ASC)  COMMENT '',
    INDEX `fk_privilege_role1_idx` (`role_id` ASC)  COMMENT '',
    INDEX `fk_privilege_menu1_idx` (`menu_id` ASC)  COMMENT '',
    CONSTRAINT `fk_privilege_role1`
      FOREIGN KEY (`role_id`)
      REFERENCES `role` (`id`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_privilege_menu1`
      FOREIGN KEY (`menu_id`)
      REFERENCES `menu` (`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;
  