-
Notifications
You must be signed in to change notification settings - Fork 1
/
fridge_share.sql
91 lines (84 loc) · 2.2 KB
/
fridge_share.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
-- CREATE DATABASE fridge_db;
CREATE TABLE users (
id SERIAL PRIMARY KEY,
username VARCHAR(255),
email VARCHAR(1024),
password_digest VARCHAR(1024)
);
CREATE TABLE fridges (
id SERIAL PRIMARY KEY,
fridge_name VARCHAR(255),
fridge_location VARCHAR(255)
);
CREATE TABLE fridge_user_relationships (
id SERIAL PRIMARY KEY,
fridge_id INT,
user_id INT,
relationship INT,
request_expire_date VARCHAR(255),
FOREIGN KEY (fridge_id) REFERENCES fridges(id) ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE RESTRICT
);
CREATE TABLE goods_infos (
id SERIAL PRIMARY KEY,
goods_name VARCHAR(255),
goods_barcode VARCHAR(255),
recommend_expire_period INT,
category VARCHAR(1024),
brand VARCHAR(255),
description VARCHAR(65536),
image_url VARCHAR(1024),
features VARCHAR(1024),
goods_attributes VARCHAR(65536),
reviews VARCHAR(65536)
);
CREATE TABLE goods_stores (
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL,
fridge_id INTEGER NOT NULL,
goods_info_id INTEGER NOT NULL,
goods_expire_date VARCHAR(255),
goods_quantity INTEGER DEFAULT 1,
goods_share_state BOOLEAN DEFAULT FALSE,
FOREIGN KEY (fridge_id) REFERENCES fridges(id) ON DELETE CASCADE,
FOREIGN KEY (goods_info_id) REFERENCES goods_infos(id) ON DELETE RESTRICT,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE RESTRICT
);
INSERT INTO goods_infos (
goods_name,
goods_barcode,
recommend_expire_period,
category,
brand,
description,
image_url,
features,
goods_attributes) VALUES (
'12 pack 355 mL cans of Vanilla Coke',
'EAN 0049776369867',
365,
'drink',
'Coke',
'12 cans of vanilla coke',
'https://images-na.ssl-images-amazon.com/images/I/21gfuf%2B8-mL.jpg',
'heavy',
'{"Length"=>"0.4","Weight"=>"4.65 lbs"}');
INSERT INTO goods_infos (
goods_name,
goods_barcode,
recommend_expire_period,
category,
brand,
description,
image_url,
features,
goods_attributes) VALUES(
'Kraft Natural Cheese Finely Shredded Mozzarella Cheese, 8 oz',
'EAN 0021000638673',
30,
'dairy',
'Kraft Foods Cheese & Dairy',
'Low-moisture part-skim mozzarella cheese.',
'https://images-na.ssl-images-amazon.com/images/I/51aZ3bsynUL.jpg',
'keep freezing',
'{"Length"=> "1","Width" => "6.5","Height:"=> "8.75","Weight"=>"599 lbs"}');