-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase_schema.sql
More file actions
40 lines (36 loc) · 1.15 KB
/
database_schema.sql
File metadata and controls
40 lines (36 loc) · 1.15 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
CREATE DATABASE project_database;
CREATE TABLE IF NOT EXISTS users (
user_id SERIAL PRIMARY KEY,
username VARCHAR(50) UNIQUE NOT NULL,
email VARCHAR(100) UNIQUE NOT NULL,
hobby VARCHAR(50) NOT NULL,
password VARCHAR(255) NOT NULL,
creation_date TIMESTAMP NOT NULL
);
CREATE TABLE IF NOT EXISTS posts (
post_id SERIAL PRIMARY KEY,
title VARCHAR(50) NOT NULL,
category VARCHAR(50) NOT NULL,
description TEXT NOT NULL,
picture BYTEA NOT NULL,
creation_date TIMESTAMP NOT NULL,
author_id INT NOT NULL,
FOREIGN KEY(author_id) REFERENCES users(user_id)
);
CREATE TABLE IF NOT EXISTS comments (
comment_id SERIAL PRIMARY KEY,
content TEXT NOT NULL,
creation_date TIMESTAMP NOT NULL,
author_id INT NOT NULL,
post_id INT NOT NULL,
FOREIGN KEY(author_id) REFERENCES users(user_id),
FOREIGN KEY(post_id) REFERENCES posts(post_id)
);
CREATE TABLE IF NOT EXISTS likes (
like_id SERIAL PRIMARY KEY,
creation_date TIMESTAMP NOT NULL,
author_id INT NOT NULL,
post_id INT NOT NULL,
FOREIGN KEY(author_id) REFERENCES users(user_id),
FOREIGN KEY(post_id) REFERENCES posts(post_id)
);