text: -- MySQL Script generated by MySQL Workbench
  -- Wed Oct 11 09:03:49 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
  -- -----------------------------------------------------
  -- -----------------------------------------------------
  -- Schema test
  -- -----------------------------------------------------
  
  -- -----------------------------------------------------
  -- Schema test
  -- -----------------------------------------------------
  CREATE SCHEMA IF NOT EXISTS `test` DEFAULT CHARACTER SET latin1 ;
  USE `test` ;
  
  -- -----------------------------------------------------
  -- Table `test`.`subjects`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `test`.`subjects` (
    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
    `created_at` TIMESTAMP NULL DEFAULT NULL,
    `updated_at` TIMESTAMP NULL DEFAULT NULL,
    PRIMARY KEY (`id`))
  
  AUTO_INCREMENT = 3
  DEFAULT CHARACTER SET = utf8
  COLLATE = utf8_unicode_ci;
  
  
  -- -----------------------------------------------------
  -- Table `test`.`units`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `test`.`units` (
    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
    `created_at` TIMESTAMP NULL DEFAULT NULL,
    `updated_at` TIMESTAMP NULL DEFAULT NULL,
    `subjects_id` INT(10) UNSIGNED NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `units_subjects_id_foreign` (`subjects_id` ASC),
    CONSTRAINT `units_subjects_id_foreign`
      FOREIGN KEY (`subjects_id`)
      REFERENCES `test`.`subjects` (`id`))
  
  AUTO_INCREMENT = 4
  DEFAULT CHARACTER SET = utf8
  COLLATE = utf8_unicode_ci;
  
  
  -- -----------------------------------------------------
  -- Table `test`.`questions`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `test`.`questions` (
    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(1000) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
    `a` VARCHAR(1000) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
    `b` VARCHAR(1000) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
    `c` VARCHAR(1000) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
    `d` VARCHAR(1000) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NULL DEFAULT NULL,
    `e` VARCHAR(1000) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NULL DEFAULT NULL,
    `f` VARCHAR(1000) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NULL DEFAULT NULL,
    `g` VARCHAR(1000) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NULL DEFAULT NULL,
    `answer` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
    `detail_answer` VARCHAR(1000) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL DEFAULT 'Chưa có lời giải',
    `created_at` TIMESTAMP NULL DEFAULT NULL,
    `updated_at` TIMESTAMP NULL DEFAULT NULL,
    `units_id` INT(10) UNSIGNED NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `questions_units_id_foreign` (`units_id` ASC),
    CONSTRAINT `questions_units_id_foreign`
      FOREIGN KEY (`units_id`)
      REFERENCES `test`.`units` (`id`))
  
  AUTO_INCREMENT = 1228
  DEFAULT CHARACTER SET = utf8
  COLLATE = utf8_unicode_ci;
  
  
  -- -----------------------------------------------------
  -- Table `test`.`tests`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `test`.`tests` (
    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
    `time` INT(11) NOT NULL,
    `count` INT(11) NOT NULL,
    `created_at` TIMESTAMP NULL DEFAULT NULL,
    `updated_at` TIMESTAMP NULL DEFAULT NULL,
    `units_id` INT(10) UNSIGNED NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `tests_units_id_foreign` (`units_id` ASC),
    CONSTRAINT `tests_units_id_foreign`
      FOREIGN KEY (`units_id`)
      REFERENCES `test`.`units` (`id`))
  
  AUTO_INCREMENT = 42
  DEFAULT CHARACTER SET = utf8
  COLLATE = utf8_unicode_ci;
  
  
  -- -----------------------------------------------------
  -- Table `test`.`users`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `test`.`users` (
    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    `oauth_provider` ENUM('', 'facebook', 'google', 'twitter') CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
    `oauth_uid` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
    `first_name` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
    `last_name` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
    `name` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
    `email` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
    `password` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
    `gender` VARCHAR(5) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
    `locale` VARCHAR(10) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
    `picture` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
    `link` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
    `remember_token` VARCHAR(100) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NULL DEFAULT NULL,
    `created_at` TIMESTAMP NULL DEFAULT NULL,
    `updated_at` TIMESTAMP NULL DEFAULT NULL,
    PRIMARY KEY (`id`),
    UNIQUE INDEX `users_email_unique` (`email` ASC))
  
  AUTO_INCREMENT = 4
  DEFAULT CHARACTER SET = utf8
  COLLATE = utf8_unicode_ci;
  
  
  -- -----------------------------------------------------
  -- Table `test`.`do_questions`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `test`.`do_questions` (
    `users_id` INT(10) UNSIGNED NOT NULL,
    `questions_id` INT(10) UNSIGNED NOT NULL,
    `tests_id` INT(10) UNSIGNED NOT NULL,
    `check` TINYINT(4) NOT NULL,
    `answerofuser` VARCHAR(45) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
    `created_at` TIMESTAMP NULL DEFAULT NULL,
    `updated_at` TIMESTAMP NULL DEFAULT NULL,
    PRIMARY KEY (`users_id`, `questions_id`, `tests_id`),
    INDEX `do_questions_questions_id_foreign` (`questions_id` ASC),
    INDEX `do_questions_tests_id_foreign` (`tests_id` ASC),
    CONSTRAINT `do_questions_questions_id_foreign`
      FOREIGN KEY (`questions_id`)
      REFERENCES `test`.`questions` (`id`),
    CONSTRAINT `do_questions_tests_id_foreign`
      FOREIGN KEY (`tests_id`)
      REFERENCES `test`.`tests` (`id`),
    CONSTRAINT `do_questions_users_id_foreign`
      FOREIGN KEY (`users_id`)
      REFERENCES `test`.`users` (`id`))
  
  DEFAULT CHARACTER SET = utf8
  COLLATE = utf8_unicode_ci;
  
  
  -- -----------------------------------------------------
  -- Table `test`.`do_tests`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `test`.`do_tests` (
    `users_id` INT(10) UNSIGNED NOT NULL,
    `tests_id` INT(10) UNSIGNED NOT NULL,
    `created_at` TIMESTAMP NULL DEFAULT NULL,
    `updated_at` TIMESTAMP NULL DEFAULT NULL,
    PRIMARY KEY (`users_id`, `tests_id`),
    INDEX `do_tests_tests_id_foreign` (`tests_id` ASC),
    CONSTRAINT `do_tests_tests_id_foreign`
      FOREIGN KEY (`tests_id`)
      REFERENCES `test`.`tests` (`id`),
    CONSTRAINT `do_tests_users_id_foreign`
      FOREIGN KEY (`users_id`)
      REFERENCES `test`.`users` (`id`))
  
  DEFAULT CHARACTER SET = utf8
  COLLATE = utf8_unicode_ci;
  
  
  -- -----------------------------------------------------
  -- Table `test`.`manage_tests`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `test`.`manage_tests` (
    `tests_id` INT(10) UNSIGNED NOT NULL,
    `questions_id` INT(10) UNSIGNED NOT NULL,
    `index` INT(11) NOT NULL,
    `created_at` TIMESTAMP NULL DEFAULT NULL,
    `updated_at` TIMESTAMP NULL DEFAULT NULL,
    `deleted_at` TIMESTAMP NULL DEFAULT NULL,
    PRIMARY KEY (`tests_id`, `questions_id`),
    INDEX `manage_tests_questions_id_foreign` (`questions_id` ASC),
    CONSTRAINT `manage_tests_questions_id_foreign`
      FOREIGN KEY (`questions_id`)
      REFERENCES `test`.`questions` (`id`),
    CONSTRAINT `manage_tests_tests_id_foreign`
      FOREIGN KEY (`tests_id`)
      REFERENCES `test`.`tests` (`id`))
  
  DEFAULT CHARACTER SET = utf8
  COLLATE = utf8_unicode_ci;
  
  
  -- -----------------------------------------------------
  -- Table `test`.`migrations`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `test`.`migrations` (
    `migration` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
    `batch` INT(11) NOT NULL)
  
  DEFAULT CHARACTER SET = utf8
  COLLATE = utf8_unicode_ci;
  
  
  -- -----------------------------------------------------
  -- Table `test`.`password_resets`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `test`.`password_resets` (
    `email` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
    `token` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
    `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    INDEX `password_resets_email_index` (`email` ASC),
    INDEX `password_resets_token_index` (`token` ASC))
  
  DEFAULT CHARACTER SET = utf8
  COLLATE = utf8_unicode_ci;
  
  
  -- -----------------------------------------------------
  -- Table `test`.`tien_questions`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `test`.`tien_questions` (
    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    `answer` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
    `wh` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
    `yes_no` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
    `or` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
    `tag` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
    `created_at` TIMESTAMP NULL DEFAULT NULL,
    `updated_at` TIMESTAMP NULL DEFAULT NULL,
    PRIMARY KEY (`id`),
    UNIQUE INDEX `tien_questions_answer_unique` (`answer` ASC))
  
  AUTO_INCREMENT = 31
  DEFAULT CHARACTER SET = utf8
  COLLATE = utf8_unicode_ci;
  
  
  SET SQL_MODE=@OLD_SQL_MODE;
  SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
  SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
  