-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.sql
More file actions
68 lines (58 loc) · 2.12 KB
/
init.sql
File metadata and controls
68 lines (58 loc) · 2.12 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
-- MariaDB SQL Script to initialize the database schema for Circle application
DROP DATABASE IF EXISTS circle;
CREATE DATABASE IF NOT EXISTS circle;
USE circle;
CREATE TABLE IF NOT EXISTS circles (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
username VARCHAR(255) NOT NULL UNIQUE,
bio TEXT DEFAULT '',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
password_hash VARCHAR(255) NOT NULL
);
CREATE TABLE IF NOT EXISTS bubbles (
id INT AUTO_INCREMENT PRIMARY KEY,
content TEXT NOT NULL,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
circle_id INT NOT NULL,
anchor INT,
FOREIGN KEY (circle_id) REFERENCES circles(id) ON DELETE CASCADE,
FOREIGN KEY (anchor) REFERENCES bubbles(id) ON DELETE SET NULL
);
CREATE TABLE IF NOT EXISTS joins (
joiner_id INT NOT NULL,
joinee_id INT NOT NULL,
joined_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (joiner_id, joinee_id),
FOREIGN KEY (joiner_id) REFERENCES circles(id) ON DELETE CASCADE,
FOREIGN KEY (joinee_id) REFERENCES circles(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS auths (
circle_id INT,
token VARCHAR(255) NOT NULL UNIQUE,
agent VARCHAR(255),
issued_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (circle_id) REFERENCES circles(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS pops (
popper_id INT NOT NULL,
popped_id INT NOT NULL,
popped_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
emoji VARCHAR(10) NOT NULL,
PRIMARY KEY (popper_id, popped_id, emoji),
FOREIGN KEY (popper_id) REFERENCES circles(id) ON DELETE CASCADE,
FOREIGN KEY (popped_id) REFERENCES bubbles(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS medias (
bubble_id INT PRIMARY KEY,
url VARCHAR(255) NOT NULL,
FOREIGN KEY (bubble_id) REFERENCES bubbles(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS notifications (
id INT AUTO_INCREMENT PRIMARY KEY,
circle_id INT NOT NULL,
content TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
is_read BOOLEAN DEFAULT FALSE,
FOREIGN KEY (circle_id) REFERENCES circles(id) ON DELETE CASCADE
);