-- MySQL Script generated by MySQL Workbench
-- 01/16/15 15:36:25
-- 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 skeleton
-- -----------------------------------------------------

-- -----------------------------------------------------
-- Schema skeleton
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `skeleton` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
USE `skeleton` ;

-- -----------------------------------------------------
-- Table `skeleton`.`users`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `skeleton`.`users` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `username` VARCHAR(64) NOT NULL,
  `password` VARCHAR(64) NOT NULL,
  `email` VARCHAR(128) NOT NULL,
  `remember_token` VARCHAR(100) NULL,
  `created_at` INT NULL,
  `updated_at` INT NULL,
  `deleted_at` INT NULL,
  PRIMARY KEY (`id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `skeleton`.`products`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `skeleton`.`products` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(256) NOT NULL,
  `description` VARCHAR(512) NULL,
  `created_at` INT NULL,
  `updated_at` INT NULL,
  `deleted_at` INT NULL,
  PRIMARY KEY (`id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `skeleton`.`login_log`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `skeleton`.`login_log` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `remote_addr` VARCHAR(256) NOT NULL,
  `request_uri` VARCHAR(256) NOT NULL,
  `date` INT NOT NULL,
  `username` VARCHAR(64) NULL,
  `user_id` INT NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_login_log_users1_idx` (`user_id` ASC),
  CONSTRAINT `fk_login_log_users1`
    FOREIGN KEY (`user_id`)
    REFERENCES `skeleton`.`users` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `skeleton`.`roles`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `skeleton`.`roles` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(64) NOT NULL,
  `description` VARCHAR(256) NULL,
  PRIMARY KEY (`id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `skeleton`.`users_roles`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `skeleton`.`users_roles` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `user_id` INT NOT NULL,
  `role_id` INT NOT NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_users_roles_users1_idx` (`user_id` ASC),
  INDEX `fk_users_roles_roles1_idx` (`role_id` ASC),
  CONSTRAINT `fk_users_roles_users1`
    FOREIGN KEY (`user_id`)
    REFERENCES `skeleton`.`users` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_users_roles_roles1`
    FOREIGN KEY (`role_id`)
    REFERENCES `skeleton`.`roles` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `skeleton`.`permissions`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `skeleton`.`permissions` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(256) NOT NULL,
  `url` VARCHAR(128) NOT NULL,
  `permission_id` INT NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_permissions_permissions1_idx` (`permission_id` ASC),
  CONSTRAINT `fk_permissions_permissions1`
    FOREIGN KEY (`permission_id`)
    REFERENCES `skeleton`.`permissions` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `skeleton`.`permissions_roles`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `skeleton`.`permissions_roles` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `role_id` INT NOT NULL,
  `permission_id` INT NOT NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_actions_roles_roles1_idx` (`role_id` ASC),
  INDEX `fk_actions_roles_actions1_idx` (`permission_id` ASC),
  CONSTRAINT `fk_actions_roles_roles1`
    FOREIGN KEY (`role_id`)
    REFERENCES `skeleton`.`roles` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_actions_roles_actions1`
    FOREIGN KEY (`permission_id`)
    REFERENCES `skeleton`.`permissions` (`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;


START TRANSACTION;
USE `skeleton`;

-- -----------------------------------------------------
-- Data for table `skeleton`.`users`
-- -----------------------------------------------------
INSERT INTO `skeleton`.`users` (`id`, `username`, `password`, `email`, `remember_token`, `created_at`, `updated_at`, `deleted_at`) VALUES (1, 'admin', '123456', 'admin@mail.com', NULL, NULL, NULL, NULL);


-- -----------------------------------------------------
-- Data for table `skeleton`.`roles`
-- -----------------------------------------------------
INSERT INTO `skeleton`.`roles` (`id`, `name`, `description`) VALUES (1, 'admin', 'acceso total');


-- -----------------------------------------------------
-- Data for table `skeleton`.`users_roles`
-- -----------------------------------------------------
INSERT INTO `skeleton`.`users_roles` (`id`, `user_id`, `role_id`) VALUES (1, 1, 1);

COMMIT;

