-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathmysql.sql
More file actions
293 lines (266 loc) · 11.8 KB
/
mysql.sql
File metadata and controls
293 lines (266 loc) · 11.8 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
-- knowledgeroot2 dump for mysql
BEGIN;
-- tables
-- table: user
CREATE TABLE `user` (
id integer NOT NULL AUTO_INCREMENT,
first_name varchar(255) DEFAULT '' NOT NULL,
last_name varchar(255) DEFAULT '' NOT NULL,
login varchar(255) DEFAULT '' NOT NULL,
email varchar(255) DEFAULT '' NOT NULL,
password varchar(255) DEFAULT '' NOT NULL,
language varchar(10) DEFAULT '' NOT NULL,
timezone varchar(50) DEFAULT 'UTC' NOT NULL,
time_start datetime NULL,
time_end datetime NULL,
active tinyint(1) DEFAULT false NOT NULL,
created_by integer NOT NULL,
create_date datetime NOT NULL,
changed_by integer NOT NULL,
change_date datetime NOT NULL,
deleted tinyint(1) DEFAULT false NOT NULL,
PRIMARY KEY (id)
) ENGINE=INNODB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
-- table: group
CREATE TABLE `group` (
id integer NOT NULL AUTO_INCREMENT,
name varchar(255) DEFAULT '' NOT NULL,
description text DEFAULT '' NOT NULL,
time_start datetime NULL,
time_end datetime NULL,
active tinyint(1) DEFAULT false NOT NULL,
created_by integer NOT NULL,
create_date datetime NOT NULL,
changed_by integer NOT NULL,
change_date datetime NOT NULL,
deleted tinyint(1) DEFAULT false NOT NULL,
PRIMARY KEY (id)
) ENGINE=INNODB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
-- table: user_group
CREATE TABLE group_member (
id integer NOT NULL AUTO_INCREMENT,
group_id integer NOT NULL,
member_id integer NOT NULL,
member_type ENUM('user', 'group') NOT NULL,
PRIMARY KEY (id)
) ENGINE=INNODB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
-- table: acl
CREATE TABLE acl (
id integer NOT NULL AUTO_INCREMENT,
role_id varchar(255) NOT NULL,
resource varchar(255) NOT NULL,
action ENUM('new','edit','delete','show','new_content','permission','print','export') NOT NULL,
`right` ENUM('allow', 'deny') NOT NULL,
PRIMARY KEY (id)
) ENGINE=INNODB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
-- table: page
CREATE TABLE page (
id integer NOT NULL AUTO_INCREMENT,
parent integer DEFAULT 0 NOT NULL,
name varchar(255) DEFAULT '' NOT NULL,
subtitle varchar(255) DEFAULT '' NOT NULL,
description text DEFAULT '' NOT NULL,
tooltip varchar(255) DEFAULT '' NOT NULL,
icon varchar(255) DEFAULT '' NOT NULL,
alias varchar(255) DEFAULT '' NOT NULL,
content_collapse tinyint(1) DEFAULT TRUE NOT NULL,
content_position ENUM('start', 'end') DEFAULT 'end' NOT NULL,
show_content_description tinyint(1) DEFAULT FALSE NOT NULL,
show_table_of_content tinyint(1) DEFAULT FALSE NOT NULL,
sorting integer DEFAULT 0 NOT NULL,
time_start datetime NULL,
time_end datetime NULL,
created_by integer NOT NULL,
create_date datetime NOT NULL,
changed_by integer NOT NULL,
change_date datetime NOT NULL,
active tinyint(1) DEFAULT false NOT NULL,
deleted tinyint(1) DEFAULT false NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (created_by) REFERENCES `user` (id) ON DELETE RESTRICT,
FOREIGN KEY (changed_by) REFERENCES `user` (id) ON DELETE RESTRICT
) ENGINE=INNODB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
-- table: page
CREATE TABLE page_history (
id integer NOT NULL AUTO_INCREMENT,
page_id integer DEFAULT 0 NOT NULL,
version integer DEFAULT 0 NOT NULL,
parent integer DEFAULT 0 NOT NULL,
name varchar(255) DEFAULT '' NOT NULL,
subtitle varchar(255) DEFAULT '' NOT NULL,
description text DEFAULT '' NOT NULL,
tooltip varchar(255) DEFAULT '' NOT NULL,
icon varchar(255) DEFAULT '' NOT NULL,
alias varchar(255) DEFAULT '' NOT NULL,
content_collapse tinyint(1) DEFAULT TRUE NOT NULL,
content_position ENUM('start', 'end') DEFAULT 'end' NOT NULL,
show_content_description tinyint(1) DEFAULT FALSE NOT NULL,
show_table_of_content tinyint(1) DEFAULT FALSE NOT NULL,
sorting integer DEFAULT 0 NOT NULL,
time_start datetime NULL,
time_end datetime NULL,
created_by integer NOT NULL,
create_date datetime NOT NULL,
changed_by integer NOT NULL,
change_date datetime NOT NULL,
active tinyint(1) DEFAULT false NOT NULL,
deleted tinyint(1) DEFAULT false NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (page_id) REFERENCES page (id) ON DELETE CASCADE
) ENGINE=INNODB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
-- table: content
CREATE TABLE content (
id integer NOT NULL AUTO_INCREMENT,
parent integer DEFAULT 0 NOT NULL,
name varchar(255) DEFAULT '' NOT NULL,
content text DEFAULT '' NOT NULL,
type varchar(255) DEFAULT 'text' NOT NULL,
sorting integer DEFAULT 0 NOT NULL,
time_start datetime NULL,
time_end datetime NULL,
created_by integer NOT NULL,
create_date datetime NOT NULL,
changed_by integer NOT NULL,
change_date datetime NOT NULL,
active tinyint(1) DEFAULT false NOT NULL,
deleted tinyint(1) DEFAULT false NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (parent) REFERENCES page (id) ON DELETE CASCADE,
FOREIGN KEY (created_by) REFERENCES `user` (id) ON DELETE RESTRICT,
FOREIGN KEY (changed_by) REFERENCES `user` (id) ON DELETE RESTRICT
) ENGINE=INNODB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
-- table: content
CREATE TABLE content_history (
id integer NOT NULL AUTO_INCREMENT,
content_id integer DEFAULT 0 NOT NULL,
version integer DEFAULT 0 NOT NULL,
parent integer DEFAULT 0 NOT NULL,
name varchar(255) DEFAULT '' NOT NULL,
content text DEFAULT '' NOT NULL,
type varchar(255) DEFAULT 'text' NOT NULL,
sorting integer DEFAULT 0 NOT NULL,
time_start datetime NULL,
time_end datetime NULL,
created_by integer NOT NULL,
create_date datetime NOT NULL,
changed_by integer NOT NULL,
change_date datetime NOT NULL,
active tinyint(1) DEFAULT false NOT NULL,
deleted tinyint(1) DEFAULT false NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (content_id) REFERENCES content (id) ON DELETE CASCADE
) ENGINE=INNODB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
-- table: file
CREATE TABLE file (
id integer NOT NULL AUTO_INCREMENT,
parent integer DEFAULT 0 NOT NULL,
hash varchar(32) DEFAULT '' NOT NULL,
name varchar(255) DEFAULT '' NOT NULL,
size integer DEFAULT 0 NOT NULL,
type varchar(255) DEFAULT 'application/octet-stream',
downloads integer DEFAULT 0 NOT NULL,
created_by integer NOT NULL,
create_date datetime NOT NULL,
changed_by integer NOT NULL,
change_date datetime NOT NULL,
deleted tinyint(1) DEFAULT false NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (parent) REFERENCES content (id) ON DELETE CASCADE,
FOREIGN KEY (created_by) REFERENCES `user` (id) ON DELETE RESTRICT,
FOREIGN KEY (changed_by) REFERENCES `user` (id) ON DELETE RESTRICT
) ENGINE=INNODB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
-- table: file_history
CREATE TABLE file_history (
id integer NOT NULL AUTO_INCREMENT,
file_id integer DEFAULT 0 NOT NULL,
version integer DEFAULT 0 NOT NULL,
parent integer DEFAULT 0 NOT NULL,
hash varchar(32) DEFAULT '' NOT NULL,
name varchar(255) DEFAULT '' NOT NULL,
size integer DEFAULT 0 NOT NULL,
type varchar(255) DEFAULT 'application/octet-stream',
downloads integer DEFAULT 0 NOT NULL,
created_by integer NOT NULL,
create_date datetime NOT NULL,
changed_by integer NOT NULL,
change_date datetime NOT NULL,
deleted tinyint(1) DEFAULT false NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (file_id) REFERENCES file (id) ON DELETE CASCADE
) ENGINE=INNODB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
-- tags
-- table: tag
CREATE TABLE tag (
id integer NOT NULL AUTO_INCREMENT,
name varchar(255) DEFAULT '' NOT NULL,
PRIMARY KEY (id)
) ENGINE=INNODB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
-- table: tag_content
CREATE TABLE tag_content (
id integer NOT NULL AUTO_INCREMENT,
tag_id integer NOT NULL,
content_id integer NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (tag_id) REFERENCES tag (id) ON DELETE CASCADE,
FOREIGN KEY (content_id) REFERENCES content (id) ON DELETE CASCADE
) ENGINE=INNODB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
-- content ratings
-- functions
-- trigger function for content table
DELIMITER ||
CREATE TRIGGER contentHistory_trigger_insert AFTER INSERT ON content FOR EACH ROW
BEGIN
INSERT INTO content_history (content_id, `version`, `parent`, `name`, `content`, `type`, sorting, time_start, time_end, created_by, create_date, changed_by, change_date, active, deleted)
VALUES (NEW.id, 1, NEW.parent, NEW.name, NEW.content, NEW.type, NEW.sorting, NEW.time_start, NEW.time_end, NEW.created_by, NEW.create_date, NEW.changed_by, NEW.change_date, NEW.active, NEW.deleted);
END
||
DELIMITER ;
DELIMITER ||
CREATE TRIGGER contentHistory_trigger_update AFTER UPDATE ON content FOR EACH ROW
BEGIN
INSERT INTO content_history (content_id, `version`, `parent`, `name`, `content`, `type`, sorting, time_start, time_end, created_by, create_date, changed_by, change_date, active, deleted)
VALUES (NEW.id, (SELECT max(x.version)+1 FROM (SELECT * FROM content_history) x WHERE x.content_id = NEW.id), NEW.parent, NEW.name, NEW.content, NEW.type, NEW.sorting, NEW.time_start, NEW.time_end, NEW.created_by, NEW.create_date, NEW.changed_by, NEW.change_date, NEW.active, NEW.deleted);
END
||
DELIMITER ;
-- trigger function for page table
DELIMITER ||
CREATE TRIGGER pageHistory_trigger_insert AFTER INSERT ON page FOR EACH ROW
BEGIN
INSERT INTO page_history (page_id, version, parent, name, subtitle, description, tooltip, icon, alias, content_collapse, content_position, show_content_description, show_table_of_content, sorting, time_start, time_end, created_by, create_date, changed_by, change_date, active, deleted)
VALUES (NEW.id, 1, NEW.parent, NEW.name, NEW.subtitle, NEW.description, NEW.tooltip, NEW.icon, NEW.alias, NEW.content_collapse, NEW.content_position, NEW.show_content_description, NEW.show_table_of_content, NEW.sorting, NEW.time_start, NEW.time_end, NEW.created_by, NEW.create_date, NEW.changed_by, NEW.change_date, NEW.active, NEW.deleted);
END
||
DELIMITER ;
DELIMITER ||
CREATE TRIGGER pageHistory_trigger_update AFTER UPDATE ON page FOR EACH ROW
BEGIN
INSERT INTO page_history (page_id, version, parent, name, subtitle, description, tooltip, icon, alias, content_collapse, content_position, show_content_description, show_table_of_content, sorting, time_start, time_end, created_by, create_date, changed_by, change_date, active, deleted)
VALUES (NEW.id, (SELECT max(x.version)+1 FROM (SELECT * FROM page_history) x WHERE x.page_id = NEW.id), NEW.parent, NEW.name, NEW.subtitle, NEW.description, NEW.tooltip, NEW.icon, NEW.alias, NEW.content_collapse, NEW.content_position, NEW.show_content_description, NEW.show_table_of_content, NEW.sorting, NEW.time_start, NEW.time_end, NEW.created_by, NEW.create_date, NEW.changed_by, NEW.change_date, NEW.active, NEW.deleted);
END
||
DELIMITER ;
-- trigger function for file table
DELIMITER ||
CREATE TRIGGER fileHistory_trigger_insert AFTER INSERT ON file FOR EACH ROW
BEGIN
INSERT INTO file_history (file_id, version, parent, hash, name, size, type, downloads, created_by, create_date, changed_by, change_date, deleted)
VALUES (NEW.id, 1, NEW.parent, NEW.hash, NEW.name, NEW.size, NEW.type, NEW.downloads, NEW.created_by, NEW.create_date, NEW.changed_by, NEW.change_date, NEW.deleted);
END
||
DELIMITER ;
DELIMITER ||
CREATE TRIGGER fileHistory_trigger_update AFTER UPDATE ON file FOR EACH ROW
BEGIN
INSERT INTO file_history (file_id, version, parent, hash, name, size, type, downloads, created_by, create_date, changed_by, change_date, deleted)
VALUES (NEW.id, (SELECT max(x.version)+1 FROM (SELECT * FROM file_history) x WHERE x.file_id = NEW.id), NEW.parent, NEW.hash, NEW.name, NEW.size, NEW.type, NEW.downloads, NEW.created_by, NEW.create_date, NEW.changed_by, NEW.change_date, NEW.deleted);
END
||
DELIMITER ;
-- indexes
-- data
-- guest user
INSERT INTO `user` (id, first_name, last_name, login, email, `password`, language, timezone, active, created_by, create_date, changed_by, change_date, deleted)
VALUES (0, 'knowledgeroot', 'guest', 'guest', 'guest@localhost', 'XXX', 'en_US', 'Europe/Berlin', true, 0, '20121001 22:00:00', 0, '20121001 22:00:00', false);
UPDATE `user` SET id=0 WHERE login='guest';
COMMIT;