-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
136 lines (121 loc) · 4.17 KB
/
schema.sql
File metadata and controls
136 lines (121 loc) · 4.17 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
DROP SCHEMA IF EXISTS `story_app`;
CREATE SCHEMA `story_app`;
USE `story_app`;
CREATE TABLE `users` (
`id` BIGINT AUTO_INCREMENT PRIMARY KEY,
`username` VARCHAR(255) NOT NULL,
`email` VARCHAR(255) NOT NULL,
`password` VARCHAR(255) NOT NULL,
`is_admin` BOOLEAN NOT NULL DEFAULT FALSE,
`date_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`date_modified` TIMESTAMP NULL,
UNIQUE (`username`),
UNIQUE (`email`)
);
CREATE TABLE `characters` (
`id` BIGINT AUTO_INCREMENT PRIMARY KEY,
`title` VARCHAR(255) NOT NULL,
`body` MEDIUMTEXT NOT NULL,
`username` VARCHAR(255) NOT NULL,
`date_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`date_modified` TIMESTAMP NULL,
UNIQUE (`title`)
);
CREATE TABLE `timeline` (
`id` BIGINT AUTO_INCREMENT PRIMARY KEY,
`username` VARCHAR(255) NOT NULL,
`date_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`date_modified` TIMESTAMP NULL,
`timeline` INT NOT NULL
);
CREATE TABLE `scenes` (
`id` BIGINT AUTO_INCREMENT PRIMARY KEY,
`title` VARCHAR(255) NOT NULL,
`body` MEDIUMTEXT NOT NULL,
`username` VARCHAR(255) NOT NULL,
`date_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`date_modified` TIMESTAMP NULL,
`timeline_start_id` BIGINT,
`timeline_end_id` BIGINT,
FOREIGN KEY (`timeline_start_id`) REFERENCES `timeline` (`id`),
FOREIGN KEY (`timeline_end_id`) REFERENCES `timeline` (`id`),
UNIQUE (`title`)
);
CREATE TABLE `regions` (
`id` BIGINT AUTO_INCREMENT PRIMARY KEY,
`title` VARCHAR(255) NOT NULL,
`body` MEDIUMTEXT NOT NULL,
`username` VARCHAR(255) NOT NULL,
`date_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`date_modified` TIMESTAMP NULL,
UNIQUE (`title`)
);
CREATE TABLE `organizations` (
`id` BIGINT AUTO_INCREMENT PRIMARY KEY,
`title` VARCHAR(255) NOT NULL,
`body` MEDIUMTEXT NOT NULL,
`username` VARCHAR(255) NOT NULL,
`date_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`date_modified` TIMESTAMP NULL,
UNIQUE (`title`)
);
CREATE TABLE `locations` (
`id` BIGINT AUTO_INCREMENT PRIMARY KEY,
`title` VARCHAR(255) NOT NULL,
`body` MEDIUMTEXT NOT NULL,
`username` VARCHAR(255) NOT NULL,
`date_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`date_modified` TIMESTAMP NULL,
UNIQUE (`title`)
);
CREATE TABLE `conflicts` (
`id` BIGINT AUTO_INCREMENT PRIMARY KEY,
`title` VARCHAR(255) NOT NULL,
`body` MEDIUMTEXT NOT NULL,
`username` VARCHAR(255) NOT NULL,
`date_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`date_modified` TIMESTAMP NULL,
UNIQUE (`title`)
);
CREATE TABLE `character_scene` (
`character_id` BIGINT NOT NULL,
`scene_id` BIGINT NOT NULL,
PRIMARY KEY (`character_id`, `scene_id`),
FOREIGN KEY (`character_id`) REFERENCES `characters` (`id`),
FOREIGN KEY (`scene_id`) REFERENCES `scenes` (`id`)
);
CREATE TABLE `character_conflict` (
`character_id` BIGINT NOT NULL,
`conflict_id` BIGINT NOT NULL,
PRIMARY KEY (`character_id`, `conflict_id`),
FOREIGN KEY (`character_id`) REFERENCES `characters` (`id`),
FOREIGN KEY (`conflict_id`) REFERENCES `conflicts` (`id`)
);
CREATE TABLE `character_organization` (
`character_id` BIGINT NOT NULL,
`organization_id` BIGINT NOT NULL,
PRIMARY KEY (`character_id`, `organization_id`),
FOREIGN KEY (`character_id`) REFERENCES `characters` (`id`),
FOREIGN KEY (`organization_id`) REFERENCES `organizations` (`id`)
);
CREATE TABLE `region_organization` (
`region_id` BIGINT NOT NULL,
`organization_id` BIGINT NOT NULL,
PRIMARY KEY (`region_id`, `organization_id`),
FOREIGN KEY (`region_id`) REFERENCES `regions` (`id`),
FOREIGN KEY (`organization_id`) REFERENCES `organizations` (`id`)
);
CREATE TABLE `organization_location` (
`location_id` BIGINT NOT NULL,
`organization_id` BIGINT NOT NULL,
PRIMARY KEY (`location_id`, `organization_id`),
FOREIGN KEY (`location_id`) REFERENCES `locations` (`id`),
FOREIGN KEY (`organization_id`) REFERENCES `organizations` (`id`)
);
CREATE TABLE `organization_scene` (
`scene_id` BIGINT NOT NULL,
`organization_id` BIGINT NOT NULL,
PRIMARY KEY (`organization_id`, `scene_id`),
FOREIGN KEY (`organization_id`) REFERENCES `organizations` (`id`),
FOREIGN KEY (`scene_id`) REFERENCES `scenes` (`id`)
);