-
Notifications
You must be signed in to change notification settings - Fork 0
/
table-creation.sql
48 lines (40 loc) · 1.19 KB
/
table-creation.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
40
41
42
43
44
45
46
47
48
create schema forum_app;
set search_path to forum_app;
CREATE TABLE user_roles (
id int generated always as identity primary key,
role_name varchar not null unique
);
CREATE TABLE app_users (
id int generated always as identity primary key,
first_name varchar NOT NULL,
last_name varchar NOT NULL,
username varchar unique NOT NULL check(length(username) >= 4),
password varchar NOT NULL check(length(password) >= 7),
profile_pic varchar,
role_id int default 1,
constraint app_users_fk
foreign key (role_id)
references user_roles(id)
);
CREATE TABLE categories (
id int generated always as identity primary key,
category_name varchar not null unique
);
CREATE TABLE app_posts (
id int generated always as identity primary key,
title varchar not null,
description text not null,
thumbnail_url varchar,
video_url varchar,
likes int default 0,
dislikes int default 0,
owner_id int,
category_id int,
created_at timestamp default current_timestamp,
constraint appPosts_owner_fk
foreign key (owner_id)
references app_users(id),
constraint appPosts_category_fk
foreign key (category_id)
references categories(id)
);