-
Notifications
You must be signed in to change notification settings - Fork 0
/
labeddit-back.sql
93 lines (79 loc) · 2.8 KB
/
labeddit-back.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
-- Active: 1704906717292@@127.0.0.1@3306
CREATE TABLE users(
id TEXT PRIMARY KEY UNIQUE NOT NULL,
name TEXT NOT NULL,
email TEXT UNIQUE NOT NULL,
password TEXT NOT NULL,
created_at TEXT DEFAULT(DATETIME()) NOT NULL
);
INSERT INTO users (id, name, email, password )
VALUES
('u001', 'Fulano', '[email protected]', '$2a$12$qPQj5Lm1dQK2auALLTC0dOWedtr/Th.aSFf3.pdK5jCmYelFrYadC'),
('u002', 'Beltrana', '[email protected]', '$2a$12$qPQj5Lm1dQK2auALLTC0dOWedtr/Th.aSFf3.pdK5jCmYelFrYadC'),
('u003', 'Astrodev', '[email protected]', '$2a$12$lHyD.hKs3JDGu2nIbBrxYujrnfIX5RW5oq/B41HCKf7TSaq9RgqJ.');
CREATE TABLE posts(
id TEXT PRIMARY KEY NOT NULL UNIQUE,
creator_id TEXT NOT NULL,
content TEXT NOT NULL,
likes INTEGER DEFAULT(0) NOT NULL,
dislikes INTEGER DEFAULT(0) NOT NULL,
created_at TEXT DEFAULT(DATETIME()) NOT NULL,
updated_at TEXT DEFAULT(DATETIME()) NOT NULL,
FOREIGN KEY (creator_id) REFERENCES users(id)
ON UPDATE CASCADE
ON DELETE CASCADE
);
INSERT INTO posts (id, creator_id, content)
VALUES
('p001', 'u001', 'Qual super poder voce gostaria de ter?'),
('p002', 'u002', 'Porque os devs gostam de linux?'),
('p003', 'u002', '3 livros para levar para um ilha isolada?'),
('p004', 'u003', 'JS eh a melhor linguagem de programacao e eu posso provar!');
CREATE TABLE comments(
id TEXT PRIMARY KEY UNIQUE NOT NULL,
creator_id TEXT NOT NULL,
post_id TEXT NOT NULL,
content TEXT NOT NULL,
likes INTEGER DEFAULT(0) NOT NULL,
dislikes INTEGER DEFAULT(0) NOT NULL,
FOREIGN KEY (creator_id) REFERENCES users(id)
ON UPDATE CASCADE
ON DELETE CASCADE,
FOREIGN KEY (post_id) REFERENCES posts(id)
ON UPDATE CASCADE
ON DELETE CASCADE
);
INSERT INTO comments (id, creator_id, post_id, content)
VALUES
('c001', 'u002', 'p001', 'Muito legal! Invisibilidade!'),
('c002', 'u001', 'p001', 'Ler mentes, com certeza!');
CREATE TABLE posts_likes_dislikes (
user_id TEXT NOT NULL,
post_id TEXT NOT NULL,
like INTEGER NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id)
ON UPDATE CASCADE
ON DELETE CASCADE,
FOREIGN KEY (post_id) REFERENCES posts(id)
ON UPDATE CASCADE
ON DELETE CASCADE
);
INSERT INTO posts_likes_dislikes (user_id, post_id, like)
VALUES
('u001', 'p001', 1),
('u002', 'p001', 0);
CREATE TABLE comments_likes_dislikes (
user_id TEXT NOT NULL,
comment_id TEXT NOT NULL,
like INTEGER NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id)
ON UPDATE CASCADE
ON DELETE CASCADE,
FOREIGN KEY (comment_id) REFERENCES comments(id)
ON UPDATE CASCADE
ON DELETE CASCADE
);
INSERT INTO comments_likes_dislikes (user_id, comment_id, like)
VALUES
('u001', 'c001', 1),
('u002', 'c001', 0);