-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase_query.sql
63 lines (55 loc) · 1.49 KB
/
database_query.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
60
61
62
63
-- Drop the tables that exist in the database
DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS quotes;
DROP TABLE IF EXISTS reports;
DROP TABLE IF EXISTS logs;
DROP TABLE IF EXISTS likes;
DROP TABLE IF EXISTS comments;
DROP TABLE IF EXISTS bans;
-- Create the tables in the database
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
email TEXT UNIQUE NOT NULL,
password_hash TEXT NOT NULL,
created_at INTEGER NOT NULL,
style TEXT DEFAULT 'light',
plevel INTEGER NOT NULL
);
CREATE TABLE `quotes` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`author` TEXT DEFAULT 'Unknown',
`year` TEXT NOT NULL,
`quote` TEXT NOT NULL,
`likes` INTEGER DEFAULT 0
);
CREATE TABLE `reports` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`user_id` INTEGER REFERENCES users (id) ON DELETE CASCADE,
`quote_id` INTEGER REFERENCES quotes (id) ON DELETE CASCADE,
`reason` TEXT NOT NULL,
`details` TEXT,
`status` INTEGER
);
CREATE TABLE `logs` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`user_id` INTEGER REFERENCES users (id) ON DELETE CASCADE,
`action` TEXT,
`message` TEXT,
`time` TEXT,
`ip` TEXT,
`agent` TEXT
);
CREATE TABLE `likes` (
`user_id` INTEGER REFERENCES users (id) ON DELETE CASCADE,
`quote_id` INTEGER REFERENCES quotes (id) ON DELETE CASCADE
);
CREATE TABLE `comments` (
`user_id` INTEGER REFERENCES users(id) ON DELETE CASCADE,
`quote_id` INTEGER REFERENCES quotes (id) ON DELETE CASCADE,
`comment` TEXT
);
CREATE TABLE `bans` (
`user_id` INTEGER UNIQUE REFERENCES users(id) ON DELETE CASCADE,
`reason` TEXT
)