· 9 years ago · Dec 14, 2016, 06:19 PM
1-- MySQL Workbench Forward Engineering
2
3SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
4SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
5SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
6
7-- -----------------------------------------------------
8-- Schema licensing_server
9-- -----------------------------------------------------
10
11-- -----------------------------------------------------
12-- Schema licensing_server
13-- -----------------------------------------------------
14CREATE SCHEMA IF NOT EXISTS `licensing_server` DEFAULT CHARACTER SET utf8 ;
15USE `licensing_server` ;
16
17-- -----------------------------------------------------
18-- Table `licensing_server`.`products_types`
19-- -----------------------------------------------------
20CREATE TABLE IF NOT EXISTS `licensing_server`.`products_types` (
21 `type_id` INT NOT NULL AUTO_INCREMENT,
22 `name` VARCHAR(45) NOT NULL,
23 PRIMARY KEY (`type_id`),
24 UNIQUE INDEX `type_id_UNIQUE` (`type_id` ASC))
25ENGINE = InnoDB;
26
27
28-- -----------------------------------------------------
29-- Table `licensing_server`.`products`
30-- -----------------------------------------------------
31CREATE TABLE IF NOT EXISTS `licensing_server`.`products` (
32 `product_id` INT NOT NULL AUTO_INCREMENT,
33 `product_name` VARCHAR(45) NULL,
34 `product_type` INT NULL,
35 PRIMARY KEY (`product_id`),
36 INDEX `fk_products_products_types_idx` (`product_type` ASC),
37 UNIQUE INDEX `product_id_UNIQUE` (`product_id` ASC),
38 CONSTRAINT `fk_products_products_types`
39 FOREIGN KEY (`product_type`)
40 REFERENCES `licensing_server`.`products_types` (`type_id`)
41 ON DELETE NO ACTION
42 ON UPDATE NO ACTION)
43ENGINE = InnoDB;
44
45
46-- -----------------------------------------------------
47-- Table `licensing_server`.`customers`
48-- -----------------------------------------------------
49CREATE TABLE IF NOT EXISTS `licensing_server`.`customers` (
50 `customer_id` INT NOT NULL AUTO_INCREMENT,
51 `customer_login` VARCHAR(45) NULL,
52 `customer_email` VARCHAR(45) NULL,
53 `customer_first_name` VARCHAR(45) NULL,
54 `customer_last_name` VARCHAR(45) NULL,
55 `customer_fathername` VARCHAR(45) NULL,
56 `customer_organization` VARCHAR(45) NULL,
57 `customer_department` VARCHAR(45) NULL,
58 `customer_phone` VARCHAR(45) NULL,
59 `customer_registration_date` DATETIME NULL,
60 PRIMARY KEY (`customer_id`),
61 UNIQUE INDEX `user_id_UNIQUE` (`customer_id` ASC))
62ENGINE = InnoDB;
63
64
65-- -----------------------------------------------------
66-- Table `licensing_server`.`product_keys`
67-- -----------------------------------------------------
68CREATE TABLE IF NOT EXISTS `licensing_server`.`product_keys` (
69 `product_key` CHAR(32) NOT NULL,
70 `product_id` INT NOT NULL,
71 `user_id` INT NOT NULL,
72 `machine_id` CHAR(32) NULL,
73 `key_last_activation_date` DATETIME NULL,
74 `expired_date` DATETIME NULL,
75 INDEX `fk_product_keys_products1_idx` (`product_id` ASC),
76 PRIMARY KEY (`product_key`, `user_id`),
77 UNIQUE INDEX `product_key_UNIQUE` (`product_key` ASC),
78 INDEX `fk_product_keys_users1_idx` (`user_id` ASC),
79 CONSTRAINT `fk_product_keys_products1`
80 FOREIGN KEY (`product_id`)
81 REFERENCES `licensing_server`.`products` (`product_id`)
82 ON DELETE NO ACTION
83 ON UPDATE NO ACTION,
84 CONSTRAINT `fk_product_keys_users1`
85 FOREIGN KEY (`user_id`)
86 REFERENCES `licensing_server`.`customers` (`customer_id`)
87 ON DELETE NO ACTION
88 ON UPDATE NO ACTION)
89ENGINE = InnoDB;
90
91
92SET SQL_MODE=@OLD_SQL_MODE;
93SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
94SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;