Tests the database upgrade with gcm_daemon
[gnucomo.git] / test / create_v1.sql
1 --*************************************************************************
2 --  (c) Copyright 2002, De Winter Information Solutions
3 -- This is free software; you can redistribute it and/or modify it under the
4 -- terms of the GNU General Public License, see the file COPYING.
5 --*************************************************************************/
6 --
7 -- Gnucomo database creation script.
8 --
9 --
10 -- This SQL script creates the initial tables for the Gnucomo database.
11 -- Before running this script with 'psql -f', you should have your
12 -- DBA create the database and give access permissions.
13 --
14 --  $log$
15 --
16
17 CREATE SEQUENCE "action_actionid_seq";
18
19 CREATE TABLE "action"
20 (
21         "actionid" bigint DEFAULT nextval('"action_actionid_seq"'::text) NOT NULL,
22         "actionname" text,
23         "statuscode" character varying(3),
24         "description" text
25 );
26
27
28 COPY "action" FROM stdin;
29 1       Entry in the system     NEW     This indicates that a notification has been entered into the system.
30 2       Display to user OPN     The notification has been displayed to the user. It doesn't mean that the user actually read the notification, but he/she should be aware. For that reason we consider the notification to be OPEN
31 3       Remarks added   PEN     Remarks have been added to the notification.
32 4       Priority changed manually       PEN     The priority of the notification has been changed by the user.
33 5       Priority changed automatically  PEN     The priority of the notification has been changed by the system. This can be the result of an action by the user or an automatical escalation.
34 6       Action taken    PEN     An action has been taken.
35 7       Assignment to user      PEN     The notification has been assigned to an user.
36 8       More information or research needed.    INV     The notification is relevant and will be handled, however more information or research will be needed. For that reason the status has been altered to UNDER INVESTIGATION.
37 9       Make output reference   REF     The automated output from an object was sent to gnucomo. The input has been identified as a valid reference for the future. For that reason the status is now REFERENCE
38 10      Job output no longer valid      CLS     By making a newer job output a valid reference, this data has been obsoleted. Since it was a reference once the output isn't interesting anymore and thus the notification can be closed.
39 11      Action taken - please verify    CLS     An action has been taken and things should have been resolved. Before the notification can be closed a verification has to be done. The new status is now VERIFY.
40 12      Action not verified     PEN     A check has been done and the results were not good. New verification is needed. The status has been changed back to PEN.
41 13      Action verified CLS     A check has been done and the results were approved. The notification has been closed.
42 15      SMS sent        OPN     An SMS has been sent.
43 14      E-mail sent     OPN     An e-mail has been sent.
44 16      Fax sent        OPN     An fax has been sent.
45 17      Log entries shown       \N      The log entries relevant to the notification have been shown.
46 18      Notification closed     CLS     The notification has been closed.
47 19      Notification reopend    OPN     The notification has been reopend.
48 \.
49
50 CREATE UNIQUE INDEX action_actionid_key ON "action" USING btree (actionid);
51
52 CREATE UNIQUE INDEX act_pk ON "action" USING btree (actionid);
53
54 CREATE UNIQUE INDEX act_actionname ON "action" USING btree (actionname);
55
56 CREATE INDEX act_statuscode ON "action" USING btree (statuscode);
57
58 SELECT setval ('"action_actionid_seq"', 19, true);
59
60 --
61 --
62
63 CREATE SEQUENCE "action_user_actionstepid_seq";
64
65 CREATE TABLE "action_user"
66 (
67         "actionstepid" bigint DEFAULT
68             nextval('"action_user_actionstepid_seq"'::text) NOT NULL,
69         "actionid" bigint,
70         "username" text,
71         "notificationid" bigint,
72         "timestamp" timestamp with time zone,
73         "statuscode" character varying(3),
74         "remarks" text
75 );
76
77 CREATE UNIQUE INDEX action_user_actionstepid_key ON action_user USING btree (actionstepid);
78
79 CREATE INDEX anu_actionid ON action_user USING btree (actionid);
80
81 CREATE INDEX anu_username ON action_user USING btree (username);
82
83 CREATE INDEX anu_notificationid ON action_user USING btree (notificationid);
84
85 CREATE INDEX anu_timestamp ON action_user USING btree ("timestamp");
86
87 CREATE INDEX anu_statuscode ON action_user USING btree (statuscode);
88
89 SELECT setval ('"action_user_actionstepid_seq"', 1, false);
90
91 --
92 --
93
94 CREATE TABLE "db_value"
95 (
96         "setting" text,
97         "setting_value" text
98 );
99
100
101 COPY "db_value" FROM stdin;
102 db_version      1
103 \.
104
105 --
106 --
107
108 CREATE TABLE "history"
109 (
110    paramid            bigint,
111    modified           timestamp,
112    change_nature      text,       --  CREATED, MODIFIED or REMOVED
113    changed_property   text,
114    new_value          text,
115    remark             text
116
117 );
118
119 --
120 --
121
122 CREATE SEQUENCE "log_logid_seq";
123
124 CREATE TABLE "log"
125 (
126         "logid" bigint DEFAULT nextval('"log_logid_seq"'::text) NOT NULL,
127         "objectid" bigint,
128         "original_filename" text,
129         "servicecode" text,
130         "object_timestamp" timestamp with time zone,
131         "timestamp" timestamp with time zone,
132         "rawdata" text,
133         "processed" boolean
134 );
135
136 CREATE UNIQUE INDEX log_logid_key ON log USING btree (logid);
137
138 CREATE INDEX log_objectid ON log USING btree (objectid);
139
140 CREATE INDEX log_original_filename ON log USING btree (original_filename);
141
142 CREATE INDEX log_servicecode ON log USING btree (servicecode);
143
144 CREATE INDEX log_object_timestmap ON log USING btree ("timestamp");
145
146 CREATE INDEX log_timestmap ON log USING btree ("timestamp");
147
148 CREATE INDEX log_timestamp ON log USING btree (object_timestamp);
149
150 CREATE INDEX log_processed ON log USING btree (processed);
151
152 SELECT setval ('"log_logid_seq"', 1, false);
153
154
155 CREATE RULE log_update AS ON UPDATE TO log DO INSTEAD NOTHING;
156
157 --
158 --
159
160 CREATE SEQUENCE "log_advid_seq";
161
162
163 CREATE TABLE "log_adv"
164 (
165         "log_advid" bigint DEFAULT
166               nextval('"log_advid_seq"'::text) NOT NULL,
167         "logid" bigint NOT NULL
168 );
169
170
171 CREATE INDEX log_adv_logid ON log_adv USING btree (logid);
172
173 CREATE UNIQUE INDEX log_adv_log_advid ON log_adv USING btree (log_advid);
174
175 SELECT setval ('"log_advid_seq"', 1, false);
176
177
178 /*
179 CREATE TRUSTED PROCEDURAL LANGUAGE 'plpgsql' HANDLER "plpgsql_call_handler" LANCOMPILER '';
180 CREATE FUNCTION "funct_processlog" () RETURNS opaque AS '
181 -- Initial date: September 18th 2002
182 -- Update: November 13th 2002
183 -- Author: Brenno J.S.A.A.F. de Winter
184 -- Abstract: This routine sets a flag
185 DECLARE
186    var_value    VARCHAR;
187    var_setting  VARCHAR;
188
189 BEGIN
190
191     UPDATE db_value SET setting_value = ''TRUE'' WHERE setting = ''log_flag'';
192     RETURN NULL;
193 END;
194  ' LANGUAGE 'plpgsql';
195
196
197 CREATE TRIGGER "log_insert" AFTER INSERT ON "log"  FOR EACH ROW EXECUTE PROCEDURE "funct_processlog" ();
198 */
199 --
200 --
201
202 CREATE TABLE "log_notification"
203 (
204         "notificationid" bigint,
205         "logid" bigint
206 );
207
208 CREATE UNIQUE INDEX lon_pk ON log_notification USING btree (notificationid, logid);
209
210 CREATE UNIQUE INDEX lon_notificationid ON log_notification USING btree (notificationid);
211
212 CREATE UNIQUE INDEX lon_logid ON log_notification USING btree (logid);
213
214 --
215 --
216
217 CREATE SEQUENCE "notification_notificationid_seq";
218
219 CREATE TABLE "notification"
220 (
221         "notificationid" bigint DEFAULT
222             nextval('"notification_notificationid_seq"'::text) NOT NULL,
223         "objectid" bigint,
224         "type_of_issueid" bigint,
225         "timestamp" timestamp with time zone,
226         "statuscode" character varying(3),
227         "priority" integer,
228         "escalation_count_timestamp" timestamp with time zone,
229         "repeat_notification_timestamp" timestamp with time zone,
230         "securitylevel_view" integer,
231         "securitylevel_add" integer,
232         "securitylevel_close" integer
233 );
234
235 CREATE UNIQUE INDEX notification_notificationid_key ON notification USING btree (notificationid);
236
237 CREATE INDEX not_objectid ON notification USING btree (objectid);
238
239 CREATE INDEX not_type_of_issueid ON notification USING btree (type_of_issueid);
240
241 CREATE INDEX not_timestamp ON notification USING btree ("timestamp");
242
243 CREATE INDEX not_statuscode ON notification USING btree (statuscode);
244
245 CREATE INDEX not_priority ON notification USING btree (priority);
246
247 CREATE INDEX not_escalation_count_timestamp ON notification USING btree (escalation_count_timestamp);
248
249 CREATE INDEX not_repeat_notification_timesta ON notification USING btree (repeat_notification_timestamp);
250
251 SELECT setval ('"notification_notificationid_seq"', 1, false);
252
253 --
254 --
255
256 CREATE SEQUENCE "object_objectid_seq";
257
258 CREATE TABLE "object"
259 (
260         "objectid" bigint DEFAULT nextval('"object_objectid_seq"'::text) NOT NULL,
261         "objectname" text,
262         "objectcode" text,
263         "scp_enabled" boolean,
264         "scp_inet" inet,
265         "mail_enabled" boolean,
266         "mail_from" text,
267         "sms_enabled" boolean,
268         "sms_number" text,
269         "fax_enabled" boolean,
270         "fax_number" text,
271         "object_description" text,
272         "object_owner" text,
273         "physical_location" text,
274         "timezone" text,
275         "remark" text
276 );
277
278 CREATE UNIQUE INDEX object_objectid_key ON object USING btree (objectid);
279
280 CREATE UNIQUE INDEX obj_objectname ON object USING btree (objectname);
281
282 CREATE UNIQUE INDEX obj_objectcode ON object USING btree (objectcode);
283
284 CREATE INDEX obj_mail_from ON object USING btree (mail_from);
285
286 SELECT setval ('"object_objectid_seq"', 1, false);
287
288 --
289 --
290
291 CREATE TABLE "object_issue"
292 (
293         "objectid" bigint,
294         "type_of_issueid" bigint,
295         "default_priority" integer,
296         "escalation" boolean,
297         "escalation_time" time without time zone,
298         "max_priority" integer,
299         "adjust_setting" text
300 );
301
302 CREATE UNIQUE INDEX obj_pk ON object_issue USING btree (objectid, type_of_issueid);
303
304 CREATE INDEX obj_objectid ON object_issue USING btree (objectid);
305
306 CREATE UNIQUE INDEX obj_type_of_notificationid ON object_issue USING btree (type_of_issueid);
307
308 --
309 --
310
311 CREATE TABLE "object_priority"
312 (
313         "objectid" bigint,
314         "priorityid" integer,
315         "send_mail" boolean,
316         "send_sms" boolean,
317         "send_fax" boolean,
318         "repeat_notification" boolean,
319         "interval_for_repeat" time without time zone
320 );
321
322 CREATE UNIQUE INDEX obi_pk ON object_priority USING btree (objectid, priorityid);
323
324 CREATE INDEX obi_objectid ON object_priority USING btree (objectid);
325
326 CREATE INDEX obi_priorityid ON object_priority USING btree (priorityid);
327
328 --
329 --
330
331 CREATE TABLE "object_service"
332 (
333         "objectid" bigint,
334         "servicecode" text,
335         "expected_interval" bigint,
336         "last_entry" timestamp with time zone,
337         "default_priority" integer,
338         "maximum_priority" integer,
339         "accepted" boolean
340 );
341
342 CREATE UNIQUE INDEX obs_pk ON object_service USING btree (objectid, servicecode);
343
344 CREATE INDEX obs_objectid ON object_service USING btree (objectid);
345
346 CREATE INDEX obs_servicecode ON object_service USING btree (servicecode);
347
348 CREATE INDEX obs_accepted ON object_service USING btree (accepted);
349
350 --
351 --
352
353 CREATE TABLE "object_user"
354 (
355         "objectid" bigint,
356         "username" text,
357         "security_level" integer
358 );
359
360 CREATE UNIQUE INDEX ous_pk ON object_user USING btree (objectid, username);
361
362 CREATE INDEX ous_objectid ON object_user USING btree (objectid);
363
364 CREATE INDEX ous_username ON object_user USING btree (username);
365
366 CREATE INDEX ous_security_level ON object_user USING btree (security_level);
367
368 --
369 --
370
371 CREATE SEQUENCE "paramid_seq";
372
373 CREATE TABLE "parameter"
374 (
375         "paramid" bigint DEFAULT nextval('"paramid_seq"'::text) NOT NULL,
376         "objectid" bigint,
377         "name" text,
378         "class" text,
379         "description" text,
380
381         primary key (paramid)
382 );
383
384 CREATE UNIQUE INDEX param_obj_name ON parameter USING btree (objectid, name, class);
385
386 SELECT setval ('"paramid_seq"', 1, true);
387
388 --
389 --
390
391 CREATE TABLE "priority"
392 (
393         "priority" integer,
394         "send_mail" boolean,
395         "send_sms" boolean,
396         "send_fax" boolean,
397         "repeat_notification" boolean,
398         "interval_for_repeat" time without time zone
399 );
400
401
402 CREATE UNIQUE INDEX pri_pk ON priority USING btree (priority);
403
404 --
405 --
406
407 CREATE TABLE "property"
408 (
409    paramid bigint,
410    name    text,
411    value   text,
412    type    text,   --   STATIC or DYNAMIC
413    min     float,
414    max     float,
415
416    primary key (paramid, name)
417 );
418
419 --
420 --
421
422 CREATE TABLE "service"
423 (
424         "servicecode" text,
425         "servicename" text,
426         "default_priority" integer,
427         "max_priority" integer
428 );
429
430 COPY "service" FROM stdin;
431 httpd   httpd   1       5
432 imap    imap    1       5
433 imapd   imapd   1       5
434 kernel  kernel  1       5
435 sshd    sshd    1       5
436 su      su      1       5
437 syslogd syslogd 1       5
438 \.
439
440 CREATE UNIQUE INDEX ser_pk ON service USING btree (servicecode);
441
442 CREATE UNIQUE INDEX ser_servicename ON service USING btree (servicename);
443
444 --
445
446 CREATE TABLE "status"
447 (
448         "statuscode" character varying(3),
449         "statusname" text,
450         "open_notification" boolean,
451         "description" text
452 );
453
454
455 COPY "status" FROM stdin;
456 new     new entry       t       Just detected, but nothing has been done yet
457 opn     open notification       t       The notification has been displayed to a user or a user has been notified. However nothing has been done yet.
458 pen     pending t       The notification is currently being worked on.
459 ver     waiting for verification        t       The notification has been worked on and is currently awaiting the approval/verification.
460 rej     rejected        f       The notification has been identified as a false postive and was reject. The notification is now closed
461 cls     closed  f       The notification has been closed
462 inv     needs investigation     t       The notification is currently under investigation and is awaiting additional details before one can work on this again.
463 \.
464
465 CREATE UNIQUE INDEX sta_pk ON status USING btree (statuscode);
466
467 CREATE UNIQUE INDEX sta_statusname ON status USING btree (statusname);
468
469 CREATE INDEX sta_open_notification ON status USING btree (open_notification);
470
471 --
472 --
473
474 CREATE SEQUENCE "type_of_issue_type_of_issue_seq";
475
476 CREATE TABLE "type_of_issue"
477 (
478         "type_of_issueid" bigint DEFAULT
479            nextval('"type_of_issue_type_of_issue_seq"'::text) NOT NULL,
480         "name" text,
481         "suggested_priority" text,
482         "description" text,
483         "active" boolean
484 );
485
486
487 COPY "type_of_issue" FROM stdin;
488 1       manual entry    4       A manual entry of a notification        t
489 \.
490
491 CREATE UNIQUE INDEX type_of_issue_type_of_issue_key ON type_of_issue USING btree (type_of_issueid);
492
493 CREATE UNIQUE INDEX toi_name ON type_of_issue USING btree (name);
494
495 CREATE INDEX toi_active ON type_of_issue USING btree (active);
496
497 SELECT setval ('"type_of_issue_type_of_issue_seq"', 1, true);
498
499 --
500 --
501
502 CREATE TABLE "usr"
503 (
504         "username" text NOT NULL,
505         "active_sessionid" bigint,
506         "account_active" boolean,
507         "security_level" integer
508 );
509
510 CREATE UNIQUE INDEX usr_username ON usr USING btree (username);
511
512 CREATE UNIQUE INDEX usr_active_sessionid ON usr USING btree (active_sessionid);
513
514 CREATE INDEX usr_account_active ON usr USING btree (account_active);
515
516 CREATE INDEX usr_security_level ON usr USING btree (security_level);
517