50 | | create table product |
51 | | ( |
52 | | id bigserial primary key, |
53 | | name varchar(255), |
54 | | description varchar(255), |
55 | | image bytea, |
56 | | quantity integer, |
57 | | category_id bigint references category (id) |
58 | | on delete set null |
59 | | on update cascade, |
60 | | supplier_id bigint references supplier (id) |
61 | | on delete set null |
62 | | on update cascade |
63 | | ); |
| 50 | create table product\\ |
| 51 | (\\ |
| 52 | id bigserial primary key,\\ |
| 53 | name varchar(255),\\ |
| 54 | description varchar(255),\\ |
| 55 | image bytea,\\ |
| 56 | quantity integer,\\ |
| 57 | category_id bigint references category (id)\\ |
| 58 | on delete set null\\ |
| 59 | on update cascade,\\ |
| 60 | supplier_id bigint references supplier (id)\\ |
| 61 | on delete set null\\ |
| 62 | on update cascade\\ |
| 63 | );\\ |
67 | | create table product_price |
68 | | ( |
69 | | product_id bigint, |
70 | | price integer, |
71 | | start_date date, |
72 | | end_date date, |
73 | | foreign key (product_id) references product (id) |
74 | | on delete cascade |
75 | | on update cascade, |
76 | | primary key (product_id, price, start_date), |
77 | | check ( price > 0 ), |
78 | | check ( end_date >= start_date ) |
79 | | ); |
| 67 | create table product_price\\ |
| 68 | (\\ |
| 69 | product_id bigint,\\ |
| 70 | price integer,\\ |
| 71 | start_date date,\\ |
| 72 | end_date date,\\ |
| 73 | foreign key (product_id) references product (id)\\ |
| 74 | on delete cascade\\ |
| 75 | on update cascade,\\ |
| 76 | primary key (product_id, price, start_date),\\ |
| 77 | check ( price > 0 ),\\ |
| 78 | check ( end_date >= start_date )\\ |
| 79 | );\\ |
92 | | create table product_property |
93 | | ( |
94 | | product_id bigint, |
95 | | property_id bigint, |
96 | | value varchar(255), |
97 | | foreign key (product_id) references product (id) |
98 | | on delete cascade |
99 | | on update cascade, |
100 | | foreign key (property_id) references property (id) |
101 | | on delete cascade |
102 | | on update cascade, |
103 | | primary key (product_id, property_id) |
104 | | ); |
| 92 | create table product_property\\ |
| 93 | (\\ |
| 94 | product_id bigint,\\ |
| 95 | property_id bigint,\\ |
| 96 | value varchar(255),\\ |
| 97 | foreign key (product_id) references product (id)\\ |
| 98 | on delete cascade\\ |
| 99 | on update cascade,\\ |
| 100 | foreign key (property_id) references property (id)\\ |
| 101 | on delete cascade\\ |
| 102 | on update cascade,\\ |
| 103 | primary key (product_id, property_id)\\ |
| 104 | );\\ |
122 | | create table order_details |
123 | | ( |
124 | | order_id bigint, |
125 | | product_id bigint, |
126 | | quantity integer, |
127 | | foreign key (order_id) references orders (id) |
128 | | on delete cascade |
129 | | on update cascade, |
130 | | foreign key (product_id) references product (id) |
131 | | on delete cascade |
132 | | on update cascade, |
133 | | primary key (order_id, product_id) |
134 | | ); |
| 122 | create table order_details\\ |
| 123 | (\\ |
| 124 | order_id bigint,\\ |
| 125 | product_id bigint,\\ |
| 126 | quantity integer,\\ |
| 127 | foreign key (order_id) references orders (id)\\ |
| 128 | on delete cascade\\ |
| 129 | on update cascade,\\ |
| 130 | foreign key (product_id) references product (id)\\ |
| 131 | on delete cascade\\ |
| 132 | on update cascade,\\ |
| 133 | primary key (order_id, product_id)\\ |
| 134 | );\\ |