-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.sql
44 lines (39 loc) · 1.23 KB
/
init.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
CREATE DATABASE hillarocket;
\c hillarocket;
CREATE TABLE IF NOT EXISTS USERS
(
id UUID NOT NULL PRIMARY KEY,
fullName VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
role VARCHAR(20) NOT NULL
);
CREATE TABLE IF NOT EXISTS CONVERSATIONS
(
id UUID NOT NULL PRIMARY KEY,
name VARCHAR(255),
type VARCHAR(10),
create_date TIMESTAMP,
last_modified TIMESTAMP
);
CREATE TABLE IF NOT EXISTS MESSAGES
(
id UUID NOT NULL PRIMARY KEY,
message_text VARCHAR(255),
conversation_id UUID NOT NULL,
sender_id UUID NOT NULL,
sender_name VARCHAR(255) NOT NULL,
time TIMESTAMP NOT NULL,
FOREIGN KEY (sender_id) REFERENCES USERS (id),
FOREIGN KEY (conversation_id) REFERENCES CONVERSATIONS (id)
);
CREATE TABLE IF NOT EXISTS GROUP_MEMBER
(
user_id UUID NOT NULL,
conversation_id UUID NOT NULL,
joined_datetime TIMESTAMP NOT NULL,
left_datetime TIMESTAMP,
PRIMARY KEY (user_id, conversation_id),
FOREIGN KEY (user_id) REFERENCES USERS (id),
FOREIGN KEY (conversation_id) REFERENCES CONVERSATIONS (id)
);