-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathschema.sql
47 lines (36 loc) · 1.17 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
CREATE TABLE moods (
id SERIAL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
user_id TEXT NOT NULL,
name TEXT NOT NULL,
eyes CHAR(2) NOT NULL,
tongue CHAR(2) NOT NULL,
PRIMARY KEY (id)
);
CREATE UNIQUE INDEX unique_user_moods ON moods (user_id, lower(name));
CREATE TABLE conversations (
id SERIAL,
public_id TEXT NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
heading TEXT NOT NULL,
user_id TEXT NOT NULL,
UNIQUE(public_id),
PRIMARY KEY (id)
);
CREATE TABLE lines (
id SERIAL,
public_id TEXT NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
animal TEXT NOT NULL,
text TEXT NOT NULL,
think BOOLEAN NOT NULL,
mood_name TEXT NOT NULL,
mood_id INTEGER, -- can be null if using a built-in mood
conversation_id INTEGER NOT NULL,
UNIQUE(public_id),
PRIMARY KEY (id)
);
ALTER TABLE lines ADD CONSTRAINT fk_lines_conversation
FOREIGN KEY (conversation_id) REFERENCES conversations(id) ON DELETE CASCADE;
ALTER TABLE lines ADD CONSTRAINT fk_lines_mood
FOREIGN KEY (mood_id) REFERENCES moods(id);