-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdatabase.sql
374 lines (346 loc) · 11.9 KB
/
database.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
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
BEGIN;
CREATE TABLE "public"."cl_config" (
"id" text NOT NULL,
"value" text,
"type" text,
"dtupdated" timestamp DEFAULT timezone('utc'::text, now()),
PRIMARY KEY ("id")
);
CREATE TABLE "public"."cl_status" (
"id" text NOT NULL,
"name" text,
"icon" text,
"color" text,
"sortindex" int2 DEFAULT 0,
PRIMARY KEY ("id")
);
CREATE TABLE "public"."cl_notification" (
"id" text NOT NULL,
"name" text,
"icon" text,
"color" text,
PRIMARY KEY ("id")
);
CREATE TABLE "public"."tbl_user" (
"id" text NOT NULL,
"photo" text,
"name" text,
"nick" text,
"email" text,
"search" text,
"language" text,
"reference" text,
"token" text,
"password" text,
"permissions" _text,
"notifyurl" text,
"sa" bool DEFAULT false,
"notifications" bool DEFAULT true,
"isinactive" bool DEFAULT false,
"isdisabled" bool DEFAULT false,
"isonline" bool DEFAULT false,
"isremoved" bool DEFAULT false,
"dtlogged" timestamp,
"dtupdated" timestamp,
"dtcreated" timestamp DEFAULT timezone('utc'::text, now()),
PRIMARY KEY ("id")
);
CREATE TABLE "public"."tbl_folder" (
"id" text NOT NULL,
"parentid" text,
"name" text,
"reference" text,
"icon" text,
"color" text,
"email" text,
"phone" text,
"customer" text,
"sortindex" int2 DEFAULT 0,
"ispinned" bool DEFAULT false,
"isprivate" bool DEFAULT false,
"isarchived" bool DEFAULT false,
"isbillable" bool DEFAULT false,
"isdisabled" bool DEFAULT false,
"dtticket" timestamp,
"dtupdated" timestamp,
"dtcreated" timestamp DEFAULT timezone('utc'::text, now()),
CONSTRAINT "tbl_folder_parentid_fkey" FOREIGN KEY ("parentid") REFERENCES "public"."tbl_folder"("id") ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY ("id")
);
CREATE TABLE "public"."tbl_tag" (
"id" text NOT NULL,
"folderid" text,
"name" text,
"search" text,
"color" text,
"icon" text,
"sortindex" int2 DEFAULT 0,
"dtupdated" timestamp,
"dtcreated" timestamp DEFAULT timezone('utc'::text, now()),
CONSTRAINT "tbl_tag_folderid_fkey" FOREIGN KEY ("folderid") REFERENCES "public"."tbl_folder"("id") ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY ("id")
);
CREATE TABLE "public"."tbl_ticket" (
"id" text NOT NULL,
"folderid" text,
"statusid" text,
"parentid" text,
"ownerid" text,
"typeid" text,
"userid" _text,
"watcherid" _text,
"source" text,
"reference" text,
"changed" text,
"name" text,
"search" text,
"html" text,
"markdown" text,
"attachments" json,
"note" text,
"callback" text,
"tags" _text,
"comments" int2 DEFAULT 0,
"worked" int4 DEFAULT 0,
"estimate" int4 DEFAULT 0,
"ispublic" bool DEFAULT false,
"isbillable" bool DEFAULT true,
"ispriority" int2 DEFAULT 0,
"isprocessed" bool DEFAULT false,
"isremoved" bool DEFAULT false,
"date" timestamp,
"dtparent" timestamp,
"deadline" timestamp,
"dtstatus" timestamp,
"dtupdated" timestamp,
"dtprocessed" timestamp,
"dtremoved" timestamp,
"dtcreated" timestamp DEFAULT timezone('utc'::text, now()),
CONSTRAINT "tbl_ticket_parentid_fkey" FOREIGN KEY ("parentid") REFERENCES "public"."tbl_ticket"("id") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "tbl_ticket_ownerid_fkey" FOREIGN KEY ("ownerid") REFERENCES "public"."tbl_user"("id") ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT "tbl_ticket_statusid_fkey" FOREIGN KEY ("statusid") REFERENCES "public"."cl_status"("id") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "tbl_ticket_projectid_fkey" FOREIGN KEY ("folderid") REFERENCES "public"."tbl_folder"("id") ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY ("id")
);
CREATE TABLE "public"."tbl_ticket_bookmark" (
"id" text NOT NULL,
"ticketid" text,
"userid" text,
CONSTRAINT "tbl_ticket_bookmark_userid_fkey" FOREIGN KEY ("userid") REFERENCES "public"."tbl_user"("id") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "tbl_ticket_bookmark_ticketid_fkey" FOREIGN KEY ("ticketid") REFERENCES "public"."tbl_ticket"("id") ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY ("id")
);
CREATE TABLE "public"."tbl_ticket_comment" (
"id" text NOT NULL,
"ticketid" text,
"userid" text,
"username" text,
"userphoto" text,
"line" int4,
"markdown" text,
"dtcreated" timestamp DEFAULT timezone('utc'::text, now()),
"dtupdated" timestamp,
CONSTRAINT "tbl_ticket_comment_ticketid_fkey" FOREIGN KEY ("ticketid") REFERENCES "public"."tbl_ticket"("id") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "tbl_ticket_comment_userid_fkey" FOREIGN KEY ("userid") REFERENCES "public"."tbl_user"("id") ON DELETE SET NULL ON UPDATE CASCADE,
PRIMARY KEY ("id")
);
CREATE TABLE "public"."tbl_ticket_data" (
"id" text NOT NULL,
"ticketid" text NOT NULL,
"widget" text,
"config" json,
"sortindex" int2,
"dtupdated" timestamp DEFAULT timezone('utc'::text, now()),
CONSTRAINT "tbl_ticket_data_ticketid_fkey" FOREIGN KEY ("ticketid") REFERENCES "public"."tbl_ticket"("id") ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY ("id")
);
CREATE TABLE "public"."tbl_notification" (
"id" text NOT NULL,
"ticketid" text,
"userid" text,
"typeid" text,
"createdby" text,
"reference" text,
"value" text,
"isprocessed" bool DEFAULT false,
"dtcreated" timestamp DEFAULT timezone('utc'::text, now()),
CONSTRAINT "tbl_notification_ticketid_fkey" FOREIGN KEY ("ticketid") REFERENCES "public"."tbl_ticket"("id") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "tbl_notification_userid_fkey" FOREIGN KEY ("userid") REFERENCES "public"."tbl_user"("id") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "tbl_notification_typeid_fkey" FOREIGN KEY ("typeid") REFERENCES "public"."cl_notification"("id") ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY ("id")
);
CREATE TABLE "public"."tbl_ticket_time" (
"id" text NOT NULL,
"ticketid" text,
"userid" text,
"minutes" int4 DEFAULT 0,
"name" text,
"date" timestamp,
"start" timestamp,
"dtcreated" timestamp DEFAULT timezone('utc'::text, now()),
CONSTRAINT "tbl_ticket_time_userid_fkey" FOREIGN KEY ("userid") REFERENCES "public"."tbl_user"("id") ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT "tbl_ticket_time_ticketid_fkey" FOREIGN KEY ("ticketid") REFERENCES "public"."tbl_ticket"("id") ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY ("id")
);
CREATE TABLE "public"."tbl_ticket_unread" (
"id" text NOT NULL,
"ticketid" text,
"userid" text,
"notificationid" text,
"iscomment" bool DEFAULT false,
"isunread" bool DEFAULT true,
"isprocessed" bool DEFAULT false,
"dtupdated" timestamp,
CONSTRAINT "tbl_ticket_unread_ticketid_fkey" FOREIGN KEY ("ticketid") REFERENCES "public"."tbl_ticket"("id") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "tbl_ticket_unread_userid_fkey" FOREIGN KEY ("userid") REFERENCES "public"."tbl_user"("id") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "tbl_ticket_unread_notificationid_fkey" FOREIGN KEY ("notificationid") REFERENCES "public"."tbl_notification"("id") ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY ("id")
);
CREATE TABLE "public"."tbl_file" (
"id" text NOT NULL,
"ticketid" text,
"folderid" text,
"userid" text,
"name" text,
"search" text,
"ext" text,
"url" text,
"type" text,
"width" int2 DEFAULT 0,
"height" int2 DEFAULT 0,
"size" int4 DEFAULT 0,
"isremoved" bool DEFAULT false,
"dtcreated" timestamp DEFAULT timezone('utc'::text, now()),
CONSTRAINT "tbl_file_ticketid_fkey" FOREIGN KEY ("ticketid") REFERENCES "public"."tbl_ticket"("id") ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT "tbl_file_folderid_fkey" FOREIGN KEY ("folderid") REFERENCES "public"."tbl_folder"("id") ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT "tbl_file_userid_fkey" FOREIGN KEY ("userid") REFERENCES "public"."tbl_user"("id") ON DELETE SET NULL ON UPDATE CASCADE,
PRIMARY KEY ("id")
);
CREATE TABLE "public"."tbl_session" (
"id" text NOT NULL,
"userid" text,
"ua" text,
"ip" text,
"device" text,
"logged" int4 DEFAULT 0,
"isreset" bool DEFAULT false,
"isonline" bool DEFAULT false,
"dtexpire" timestamp,
"dtlogged" timestamp,
"dtcreated" timestamp DEFAULT timezone('utc'::text, now()),
CONSTRAINT "tbl_session_userid_fkey" FOREIGN KEY ("userid") REFERENCES "public"."tbl_user"("id") ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY ("id")
);
CREATE TABLE "public"."tbl_ticket_backup" (
"id" text NOT NULL,
"ticketid" text,
"userid" text,
"markdown" text,
"ip" text,
"ua" text,
"dtcreated" timestamp DEFAULT timezone('utc'::text, now()),
CONSTRAINT "tbl_ticket_backup_ticketid_fkey" FOREIGN KEY ("ticketid") REFERENCES "public"."tbl_ticket"("id") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "tbl_ticket_backup_userid_fkey" FOREIGN KEY ("userid") REFERENCES "public"."tbl_user"("id") ON DELETE SET NULL ON UPDATE CASCADE,
PRIMARY KEY ("id")
);
CREATE VIEW view_ticket AS
SELECT
a.id,
a.folderid,
a.ownerid,
a.statusid,
a.parentid,
a.userid,
a.watcherid,
a.name,
a.worked,
a.estimate,
a.comments,
a.ispriority,
b.name AS folder,
b.color AS folder_color,
b.icon AS folder_icon,
a.attachments,
a.tags,
a.date,
a.dtstatus,
a.dtupdated,
a.deadline,
a.isbillable,
d.name AS status,
d.sortindex,
d.icon AS status_icon,
d.color AS status_color,
a.search,
b.isprivate,
a.html,
a.dtparent,
a.dtcreated,
a.reference,
a.source,
a.markdown,
a.ispublic,
a.note
FROM tbl_ticket a
LEFT JOIN tbl_folder b ON b.id = a.folderid
LEFT JOIN cl_status d ON d.id = a.statusid
WHERE
a.isremoved = false;
CREATE VIEW view_ticket_time AS
SELECT
a.id,
a.userid,
a.ticketid,
b.folderid,
a.name,
a.dtcreated,
a.minutes,
a.date,
b."name" as ticket_name,
c.name AS user_name,
b.isbillable,
a.start
FROM tbl_ticket_time a
JOIN tbl_ticket b ON b.id = a.ticketid AND b.isremoved = false
LEFT JOIN tbl_user c ON c.id = a.userid;
-- DATA
INSERT INTO "public"."cl_notification" ("id", "name", "icon", "color") VALUES
('comment', 'Comment', 'ti ti-comment', '#5599F8'),
('content', 'Changed content', 'ti ti-layout', '#7327F5'),
('logwork', 'Logged work', 'ti ti-stopwatch', '#3B80F7'),
('metadata', 'Changed metadata', 'ti ti-invoice', '#83C83C'),
('status', 'Changed status', 'ti ti-traffic-light', '#62C9CA'),
('user', 'Assigned user', 'ti ti-check-circle', '#83C83C');
INSERT INTO "public"."cl_status" ("id", "name", "icon", "color", "sortindex") VALUES
('closed', 'Closed', 'ti ti-check-circle', '#C0C0C0', 6),
('note', 'Note', 'ti ti-book-open', '#62C9CA', 5),
('open', 'In progress', 'ti ti-spinner', '#4285F4', 1),
('pending', 'Pending', 'ti ti-hourglass', '#EA71B0', 2),
('postponed', 'Postponed', 'ti ti-history', '#8C42F6', 4),
('review', 'Review', 'ti ti-clean', '#EC8632', 3);
INSERT INTO "public"."tbl_user" ("id", "name", "search", "email", "password", "permissions", "sa", "dtcreated") VALUES
('{id}', 'John Connor', 'johnconor', '[email protected]', '{password}', '{}', 't', timezone('utc'::text, now()));
-- INDEXES
CREATE INDEX "tbl_ticket_idxstatus" ON "public"."tbl_ticket" USING BTREE ("statusid", "folderid", "userid");
CREATE INDEX "tbl_ticket_idxparent" ON "public"."tbl_ticket" USING BTREE ("parentid");
CREATE INDEX "tbl_ticket_data_idx" ON "public"."tbl_ticket_data" USING BTREE ("ticketid");
CREATE INDEX "tbl_ticket_time_idxuser" ON "public"."tbl_ticket_time" USING BTREE ("userid", "start");
CREATE INDEX "tbl_ticket_time_idxticket" ON "public"."tbl_ticket_time" USING BTREE ("ticketid");
CREATE INDEX "tbl_ticket_unread_idxuserid" ON "public"."tbl_ticket_unread" USING BTREE ("userid", "isunread");
CREATE INDEX "tbl_ticket_comment_idxticket" ON "public"."tbl_ticket_comment" USING BTREE ("ticketid");
CREATE INDEX "tbl_notification_idxticket" ON "public"."tbl_notification" USING BTREE ("ticketid", "userid");
-- =============================================
-- DATA
-- =============================================
INSERT INTO "public"."cl_config" ("id", "value", "type") VALUES
('allow_tms', 'false', 'boolean'),
('cdn', '//cdn.componentator.com', 'string'),
('name', 'Todomator', 'string'),
('token', '', 'string'),
('language', 'eu', 'string'),
('minlogtime', '10', 'number'),
('auth_cookie_expire', '1 month', 'string'),
('auth_secret', '{secret}', 'string'),
('auth_cookie', SUBSTRING(MD5(RANDOM()::text), 0, 5), 'string'),
('salt', SUBSTRING(MD5(RANDOM()::text), 0, 13), 'string');
COMMIT;