-
Notifications
You must be signed in to change notification settings - Fork 0
/
page_turners.sql
142 lines (123 loc) · 5.01 KB
/
page_turners.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
-- 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='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
-- -----------------------------------------------------
-- Schema page_turners
-- -----------------------------------------------------
DROP SCHEMA IF EXISTS `page_turners` ;
-- -----------------------------------------------------
-- Schema page_turners
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `page_turners` DEFAULT CHARACTER SET utf8 ;
USE `page_turners` ;
-- -----------------------------------------------------
-- Table `page_turners`.`users`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `page_turners`.`users` ;
CREATE TABLE IF NOT EXISTS `page_turners`.`users` (
`id` INT NOT NULL AUTO_INCREMENT,
`first_name` VARCHAR(255) NULL DEFAULT NULL,
`last_name` VARCHAR(255) NULL DEFAULT NULL,
`email` VARCHAR(255) NULL DEFAULT NULL,
`password` VARCHAR(255) NULL DEFAULT NULL,
`admin` TINYINT NULL DEFAULT NULL,
`created_at` DATETIME NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` DATETIME NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`))
ENGINE = InnoDB
AUTO_INCREMENT = 12
DEFAULT CHARACTER SET = utf8mb3;
-- -----------------------------------------------------
-- Table `page_turners`.`books`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `page_turners`.`books` ;
CREATE TABLE IF NOT EXISTS `page_turners`.`books` (
`id` INT NOT NULL AUTO_INCREMENT,
`title` VARCHAR(255) NULL DEFAULT NULL,
`genre` VARCHAR(255) NULL DEFAULT NULL,
`author` VARCHAR(255) NULL DEFAULT NULL,
`price` DECIMAL(6,2) NULL DEFAULT NULL,
`quantity_in_stock` INT NULL DEFAULT NULL,
`user_id` INT NOT NULL,
`created_at` DATETIME NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` DATETIME NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
INDEX `fk_books_users_idx` (`user_id` ASC) VISIBLE,
CONSTRAINT `fk_books_users`
FOREIGN KEY (`user_id`)
REFERENCES `page_turners`.`users` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB
AUTO_INCREMENT = 9
DEFAULT CHARACTER SET = utf8mb3;
-- -----------------------------------------------------
-- Table `page_turners`.`orders`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `page_turners`.`orders` ;
CREATE TABLE IF NOT EXISTS `page_turners`.`orders` (
`id` INT NOT NULL AUTO_INCREMENT,
`total` DECIMAL(6,2) NULL DEFAULT NULL,
`customer_id` INT NOT NULL,
`created_at` DATETIME NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` DATETIME NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`order_number` VARCHAR(255) NULL,
PRIMARY KEY (`id`),
INDEX `fk_orders_users1_idx` (`customer_id` ASC) VISIBLE,
CONSTRAINT `fk_orders_users1`
FOREIGN KEY (`customer_id`)
REFERENCES `page_turners`.`users` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB
AUTO_INCREMENT = 5
DEFAULT CHARACTER SET = utf8mb3;
-- -----------------------------------------------------
-- Table `page_turners`.`books_in_orders`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `page_turners`.`books_in_orders` ;
CREATE TABLE IF NOT EXISTS `page_turners`.`books_in_orders` (
`order_id` INT NOT NULL,
`book_id` INT NOT NULL,
`id` INT NOT NULL AUTO_INCREMENT,
INDEX `fk_books_in_orders_orders1_idx` (`order_id` ASC) VISIBLE,
INDEX `fk_books_in_orders_books1_idx` (`book_id` ASC) VISIBLE,
PRIMARY KEY (`id`),
CONSTRAINT `fk_books_in_orders_books1`
FOREIGN KEY (`book_id`)
REFERENCES `page_turners`.`books` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_books_in_orders_orders1`
FOREIGN KEY (`order_id`)
REFERENCES `page_turners`.`orders` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb3;
-- -----------------------------------------------------
-- Table `page_turners`.`inquiries`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `page_turners`.`inquiries` ;
CREATE TABLE IF NOT EXISTS `page_turners`.`inquiries` (
`id` INT NOT NULL AUTO_INCREMENT,
`first_name` VARCHAR(255) NULL,
`last_name` VARCHAR(255) NULL,
`category` VARCHAR(255) NULL,
`description` VARCHAR(1000) NULL,
`order_number` VARCHAR(255) NULL,
`created_at` DATETIME NULL DEFAULT NOW(),
`updated_at` DATETIME NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`user_id` INT NULL,
PRIMARY KEY (`id`),
INDEX `fk_inquiries_users1_idx` (`user_id` ASC) VISIBLE,
CONSTRAINT `fk_inquiries_users1`
FOREIGN KEY (`user_id`)
REFERENCES `page_turners`.`users` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;