-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
48 lines (43 loc) · 1.17 KB
/
schema.sql
File metadata and controls
48 lines (43 loc) · 1.17 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
DROP TABLE IF EXISTS users CASCADE;
DROP TABLE IF EXISTS recipes CASCADE;
DROP TABLE IF EXISTS comments;
DROP TABLE IF EXISTS profiles;
DROP TABLE IF EXISTS messages;
CREATE TABLE users (
id SERIAL PRIMARY KEY,
username TEXT UNIQUE,
password TEXT,
is_admin BOOLEAN DEFAULT FALSE
);
CREATE TABLE recipes (
id SERIAL PRIMARY KEY,
title TEXT,
cooking_time INTEGER,
recipe TEXT,
likes INTEGER,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
public BOOLEAN DEFAULT TRUE,
user_id INTEGER REFERENCES users ON DELETE CASCADE
);
CREATE TABLE comments (
id SERIAL PRIMARY KEY,
content TEXT,
likes INTEGER,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
user_id INTEGER REFERENCES users ON DELETE CASCADE,
recipe_id INTEGER REFERENCES recipes ON DELETE CASCADE
);
CREATE TABLE profiles (
id SERIAL PRIMARY KEY,
bio TEXT,
total_likes INTEGER,
user_id INTEGER REFERENCES users ON DELETE CASCADE
);
CREATE TABLE messages (
id SERIAL PRIMARY KEY,
content TEXT,
sent_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
sent_from_id INTEGER REFERENCES users ON DELETE CASCADE,
sent_to_id INTEGER REFERENCES users ON DELETE CASCADE,
been_read BOOLEAN DEFAULT FALSE
);