-
Notifications
You must be signed in to change notification settings - Fork 1
/
schema.sql
97 lines (84 loc) · 2.28 KB
/
schema.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
-- Tables
CREATE DATABASE sdc_reviews
USE sdc_reviews
CREATE TABLE products
(
id SERIAL,
name text COLLATE pg_catalog."default",
CONSTRAINT products_pkey PRIMARY KEY (id)
)
CREATE TABLE characteristics
(
id SERIAL,
product_id integer,
name text COLLATE pg_catalog."default",
CONSTRAINT characteristics_pkey PRIMARY KEY (id),
CONSTRAINT fk_prod FOREIGN KEY (product_id)
REFERENCES products (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
CREATE TABLE reviews
(
id SERIAL,
product_id integer,
rating integer,
date bigint,
summary text COLLATE pg_catalog."default",
body text COLLATE pg_catalog."default",
recommend boolean,
reported boolean,
reviewer_name text,
reviewer_email text,
response text,
helpfulness integer,
CONSTRAINT reviews_pkey PRIMARY KEY (id),
CONSTRAINT fk_prod FOREIGN KEY (product_id)
REFERENCES products (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
CREATE TABLE photos
(
id SERIAL,
review_id integer,
url text,
CONSTRAINT photos_pkey PRIMARY KEY (id),
CONSTRAINT fk_review FOREIGN KEY (review_id)
REFERENCES reviews (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
CREATE TABLE characteristic_reviews
(
id SERIAL,
characteristic_id integer,
review_id integer,
value integer,
CONSTRAINT characteristic_reviews_pkey PRIMARY KEY (id),
CONSTRAINT fk_char FOREIGN KEY (characteristic_id)
REFERENCES characteristics (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT fk_rev FOREIGN KEY (review_id)
REFERENCES reviews (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
-- Indexes
CREATE INDEX reviews_productid_idx
ON reviews USING btree
(product_id ASC NULLS LAST)
TABLESPACE pg_default;
CREATE INDEX photos_reviewid_idx
ON photos USING btree
(review_id ASC NULLS LAST)
TABLESPACE pg_default;
CREATE INDEX char_productid_idx
ON characteristics USING btree
(product_id ASC NULLS LAST)
TABLESPACE pg_default;
CREATE INDEX char_reviews_charid_idx
ON characteristic_reviews USING btree
(characteristic_id ASC NULLS LAST)
TABLESPACE pg_default;