-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_tables.sql
39 lines (36 loc) · 1007 Bytes
/
create_tables.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
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TABLE IF NOT EXISTS author (
id UUID NOT NULL DEFAULT uuid_generate_v4(),
name TEXT NOT NULL,
surname TEXT NOT NULL,
mail TEXT NOT NULL UNIQUE,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS contents (
id UUID NOT NULL DEFAULT uuid_generate_v4(),
type text NOT NULL,
author UUID NOT NULL,
relation UUID,
title text NOT NULL,
context text NOT NULL,
PRIMARY KEY (id),
CONSTRAINT fk_author
FOREIGN KEY(author)
REFERENCES author(id),
CONSTRAINT fk_relation
FOREIGN KEY(relation)
REFERENCES contents(id)
);
CREATE TABLE IF NOT EXISTS reactions (
id UUID NOT NULL DEFAULT uuid_generate_v4(),
content UUID NOT NULL,
author UUID NOT NULL,
reaction TEXT NOT NULL UNIQUE,
PRIMARY KEY (id),
CONSTRAINT fk_author
FOREIGN KEY(author)
REFERENCES author(id),
CONSTRAINT fk_content
FOREIGN KEY(content)
REFERENCES contents(id)
);