-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheme.sql
54 lines (46 loc) · 1.18 KB
/
scheme.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
CREATE TABLE states (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL UNIQUE
);
CREATE TABLE products (
id SERIAL PRIMARY KEY,
name TEXT,
type TEXT,
UNIQUE(name, type)
);
CREATE TABLE issues (
id SERIAL PRIMARY KEY,
name TEXT,
type TEXT,
UNIQUE(name, type)
);
CREATE TABLE companies (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL UNIQUE
);
CREATE TABLE complaints (
id BIGINT NOT NULL PRIMARY KEY,
reception_date TIMESTAMPTZ,
product_id BIGINT NOT NULL REFERENCES products(id),
issue_id BIGINT NOT NULL REFERENCES issues(id),
company_id BIGINT NOT NULL REFERENCES companies(id),
state_id BIGINT REFERENCES states(id),
zip_code TEXT,
consumer_narrative TEXT,
company_public_response TEXT,
company_consumer_response TEXT,
consumer_consent BOOLEAN,
submission_channel TEXT,
company_sent_date TIMESTAMPTZ,
timely_response BOOLEAN,
consumer_disputed BOOLEAN
);
CREATE TABLE tags (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL UNIQUE
);
CREATE TABLE complaint_tags (
id SERIAL PRIMARY KEY,
complaint_id BIGINT NOT NULL REFERENCES complaints(id),
tag_id BIGINT NOT NULL REFERENCES tags(id)
);