-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sql
More file actions
57 lines (57 loc) · 1.7 KB
/
Copy pathsetup.sql
File metadata and controls
57 lines (57 loc) · 1.7 KB
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
DROP TABLE IF EXISTS user_table
CASCADE;
CREATE TABLE user_table
(
id SERIAL PRIMARY KEY,
username text NOT NULL,
password text NOT NULL,
avatar text,
created_at TIMESTAMP
WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
DROP TABLE IF EXISTS room_table
CASCADE;
CREATE TABLE room_table
(
id SERIAL PRIMARY KEY,
roomname text,
type boolean,
created_at TIMESTAMP
WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
DROP TABLE IF EXISTS chat_table
CASCADE;
CREATE TABLE chat_table
(
id SERIAL PRIMARY KEY,
roomid integer REFERENCES room_table (id) ON DELETE CASCADE,
userid integer REFERENCES user_table (id) ON DELETE CASCADE,
message text,
created_at TIMESTAMP
WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
DROP TABLE IF EXISTS users_rooms
CASCADE;
CREATE TABLE users_rooms
(
roomid integer REFERENCES room_table (id) ON DELETE CASCADE,
userid integer REFERENCES user_table (id) ON DELETE CASCADE,
PRIMARY KEY (roomid, userid)
);
DROP TABLE IF EXISTS user_session
CASCADE;
CREATE TABLE user_session
(
sid varchar NOT NULL
COLLATE "default",
sess json NOT NULL,
expire timestamp
(6) NOT NULL
)
WITH
(OIDS = FALSE);
ALTER TABLE user_session
ADD
CONSTRAINT session_pkey PRIMARY KEY (sid)
NOT DEFERRABLE INITIALLY IMMEDIATE;
CREATE INDEX IDX_session_expire ON user_session (expire);