-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase-schema.sql
59 lines (54 loc) · 2.04 KB
/
database-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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
drop database if exists socialmediaproject;
create database socialmediaproject;
use socialmediaproject;
create table user (
`id` int not null primary key auto_increment,
`username` varchar(50) unique not null,
`password` char(60) not null, # BCrypt password field
`email` varchar(254) unique not null,
`creationDate` datetime not null,
`currentLikes` decimal(15,2) not null,
`hasPublicLikes` boolean not null default true, # Whether other user can view likes
`hasAdminPermissions` boolean not null default false,
`hasModeratorPermissions` boolean not null default false,
`isDeleted` boolean not null default false
);
create table post (
`id` int not null primary key auto_increment,
`title` varchar(100) not null,
`imageId` varchar(36), # Refers to an image named with a UUID, without the file extension
`text` text,
`user` int not null,
`timestamp` datetime not null,
`deleted` boolean not null default false,
foreign key (user) references user (id)
);
create table comment (
`id` int not null primary key auto_increment,
`imageId` varchar(36),
`text` varchar(5000) not null,
`user` int not null,
`post` int not null,
`timestamp` datetime not null,
`deleted` boolean not null default false,
foreign key (user) references user(id),
foreign key (post) references post(id)
);
# Likes purchased by the user
create table purchase (
`id` int not null primary key auto_increment,
`pricePaid` decimal(13, 4) not null, # GAAP compatible money field
`likesBought` int not null,
`user` int not null,
`timestamp` datetime not null,
foreign key (user) references user(id)
);
# Likes spent on post
create table postlikes (
`likesUsed` int not null,
`post` int not null,
`user` int not null,
primary key (post, user),
foreign key (post) references post(id),
foreign key (user) references user(id)
);