summaryrefslogtreecommitdiff
path: root/db/0-create.psql
blob: 35278c75c96a47bc039a066e73734e9e5a0119a9 (plain)
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
CREATE TABLE users (
    user_id SERIAL PRIMARY KEY,
    nick text UNIQUE NOT NULL,
    hash text NOT NULL,
    email text NOT NULL,
    created_on timestamp NOT NULL DEFAULT now(),
    contact text,
    bio text
);

CREATE TABLE rooms (
    room_id SERIAL PRIMARY KEY,
    name text UNIQUE NOT NULL,
    created_on timestamp NOT NULL DEFAULT now()
);

CREATE TABLE messages (
    message_id SERIAL PRIMARY KEY,
    user_id integer NOT NULL REFERENCES users,
    room_id integer NOT NULL REFERENCES rooms,
    content text NOT NULL,
    created_on timestamp NOT NULL DEFAULT now()
);

CREATE TABLE user_session (
    session_id bigint NOT NULL,
    user_id integer NOT NULL REFERENCES users,
    ttl timestamp NOT NULL,
    PRIMARY KEY (session_id, user_id)
);

INSERT INTO rooms (room_id, name) VALUES (1, 'dumpfm');