aboutsummaryrefslogtreecommitdiff
path: root/db/init.sql
blob: f1c350602114897c8829233af30787c07174d131 (plain)
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
create schema if not exists webs;

create table if not exists webs.category (
  `ID` int not null auto_increment,
  `name` varchar(45) not null,
  primary key (`ID`)
);

create table if not exists webs.product (
  `ID` int not null auto_increment,
  `name` varchar(45) not null,
  `price` decimal(5, 2) not null,
  `image` mediumblob null default null,
	`category` int not null,
  primary key (`ID`),
  constraint `product_category_fk`
    foreign key (`category`)
    references webs.category (`ID`)
    on update cascade
);

create table if not exists webs.customer (
  `ID` int not null auto_increment,
  `name` varchar(45) not null,
  primary key (`ID`)
);

create table if not exists webs.cart (
  `ID` int not null auto_increment,
  `product` int not null,
  `customer` int not null,
	`count` int not null default 1,
  primary key (`ID`),
  constraint `cart_product_fk`
    foreign key (`product`)
    references webs.product (`ID`)
    on update cascade,
  constraint `cart_customer_fk`
    foreign key (`customer`)
    references webs.customer (`ID`)
    on update cascade
);

create table if not exists webs.promotion (
  `ID` int not null auto_increment,
  `product` int not null,
  `count_buff` int not null default 1,
	`price_buff` decimal(4, 3) not null default 1.0,
  primary key (`ID`),
  constraint `promotion_product_fk`
    foreign key (`product`)
    references webs.product (`ID`)
    on update cascade
);