-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit_mysql.sql
59 lines (51 loc) · 1.93 KB
/
init_mysql.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
CREATE DATABASE IF NOT EXISTS stackoverflow;
CREATE TABLE IF NOT EXISTS stackoverflow.post (
id INTEGER PRIMARY KEY,
title VARCHAR(256) NOT NULL,
body TEXT NOT NULL,
accepted_answer_id INTEGER,
creation_date TIMESTAMP NOT NULL
);
CREATE TABLE IF NOT EXISTS stackoverflow.post_answer (
id INTEGER PRIMARY KEY,
post_id INTEGER NOT NULL,
answer_id INTEGER NOT NULL,
score INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS stackoverflow.stack (
id INTEGER AUTO_INCREMENT PRIMARY KEY,
language VARCHAR(256) NOT NULL
);
CREATE TABLE IF NOT EXISTS stackoverflow.post_stack (
id INTEGER AUTO_INCREMENT PRIMARY KEY,
post_id INTEGER NOT NULL,
stack_id INTEGER NOT NULL,
position INTEGER NOT NULL,
FOREIGN KEY(post_id) REFERENCES stackoverflow.post(id),
FOREIGN KEY(stack_id) REFERENCES stackoverflow.stack(id)
);
CREATE TABLE IF NOT EXISTS stackoverflow.frame (
id INTEGER AUTO_INCREMENT PRIMARY KEY,
method_name VARCHAR(256) NOT NULL,
file_name VARCHAR(256) NOT NULL,
line_number INTEGER NOT NULL,
UNIQUE frame_unicity (method_name, file_name, line_number)
);
CREATE TABLE IF NOT EXISTS stackoverflow.link (
id INTEGER AUTO_INCREMENT PRIMARY KEY,
parent_frame_id INTEGER NOT NULL,
child_frame_id INTEGER NOT NULL,
next_id INTEGER NULL,
UNIQUE link_unicity (parent_frame_id, child_frame_id, next_id),
FOREIGN KEY(parent_frame_id) REFERENCES stackoverflow.frame(id),
FOREIGN KEY(child_frame_id) REFERENCES stackoverflow.frame(id),
FOREIGN KEY(next_id) REFERENCES stackoverflow.link(id)
);
CREATE TABLE IF NOT EXISTS stackoverflow.stack_link (
id INTEGER AUTO_INCREMENT PRIMARY KEY,
stack_id INTEGER NOT NULL,
link_id INTEGER NOT NULL,
FOREIGN KEY(stack_id) REFERENCES stackoverflow.stack(id),
FOREIGN KEY(link_id) REFERENCES stackoverflow.link(id)
);
GRANT ALL ON stackoverflow.* TO 'stackoverflow'@'%' IDENTIFIED BY 'stackoverflow' WITH GRANT OPTION;