-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.sql
39 lines (34 loc) · 964 Bytes
/
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
CREATE TABLE users (
id SERIAL PRIMARY KEY,
username TEXT UNIQUE NOT NULL,
password TEXT
);
CREATE TABLE collections (
id SERIAL PRIMARY KEY,
owner_id INTEGER REFERENCES users ON DELETE CASCADE,
name TEXT NOT NULL
);
CREATE TABLE collection_invitations (
id SERIAL PRIMARY KEY,
collection_id INTEGER REFERENCES collections,
guest_id INTEGER REFERENCES users
);
CREATE TABLE decks (
id SERIAL PRIMARY KEY,
collection_id INTEGER REFERENCES collections ON DELETE CASCADE,
creator_id INTEGER REFERENCES users,
name TEXT NOT NULL
);
CREATE TABLE cards (
id SERIAL PRIMARY KEY,
collection_id INTEGER REFERENCES collections ON DELETE CASCADE,
name TEXT NOT NULL,
wins INTEGER,
losses INTEGER,
win_rate NUMERIC (5,2)
);
CREATE TABLE cards_in_decks (
id SERIAL PRIMARY KEY,
card_id INTEGER REFERENCES cards ON DELETE CASCADE,
deck_id INTEGER REFERENCES decks ON DELETE CASCADE
);