Added index to the history table.
[gnucomo.git] / src / database / create.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: create.sql,v $
15 --  Revision 1.15  2003-08-05 07:43:24  arjen
16 --  Added index to the history table.
17 --
18 --  Revision 1.14  2003/07/09 07:14:59  arjen
19 --  New database tables: notification_check, notification_check_buffer,
20 --  notification_check_line and object_statistics.
21 --
22 --  Revision 1.13  2003/03/29 08:27:05  arjen
23 --  New columns in the table 'log_adv_daemon_email': size, pri, relay,
24 --  status_details and dsn.
25 --  Added several indices for the table 'log_adv_daemon_email'.
26 --
27 --  Revision 1.12  2003/02/21 08:38:38  arjen
28 --  Added new table to the database: log_adv_daemon_email.
29 --
30 --  Revision 1.11  2003/02/16 08:24:38  arjen
31 --  Added a new entry to the action table: Notification was displayed in the listing
32 --
33 --  Revision 1.10  2003/02/14 06:32:27  arjen
34 --  Setup the groups and database permissions. The three groups
35 --  are: view, ops and admin.
36 --  Added a new entry to the action table.
37 --
38 --  Revision 1.9  2003/02/13 08:46:54  arjen
39 --  Added log, notification and parameter counters to the 'object' table.
40 --  Counting these things at the time a user interface needs them is
41 --  too slow. Other programs, like gcm_daemon en gcm_input should prepare
42 --  these counters for quick retrieval.
43 --
44 --  Revision 1.8  2003/02/08 07:36:41  arjen
45 --  Added new table to the database : log_adv_daemon
46 --
47 --  Revision 1.7  2003/02/05 09:29:08  arjen
48 --  Bug fix: action.statuscode was in upper case.
49 --
50 --  Revision 1.6  2003/01/20 07:29:48  arjen
51 --  Added new tables to the database: parameter_class and parameter_notification
52 --
53 --  Revision 1.5  2003/01/18 08:46:48  arjen
54 --  Added new records to the 'type_of_issue' table.
55 --  Changed semantics of actionid 9 in the 'action' table.
56 --
57 --
58
59 CREATE SEQUENCE "action_actionid_seq";
60
61 CREATE TABLE "action"
62 (
63         "actionid" bigint DEFAULT nextval('"action_actionid_seq"'::text) NOT NULL,
64         "actionname" text,
65         "statuscode" character varying(3),
66         "description" text
67 );
68
69
70 COPY "action" FROM stdin;
71 1       Entry in the system     new     This indicates that a notification has been entered into the system.
72 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
73 3       Remarks added   pen     Remarks have been added to the notification.
74 4       Priority changed manually       pen     The priority of the notification has been changed by the user.
75 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.
76 6       Action taken    pen     An action has been taken.
77 7       Assignment to user      pen     The notification has been assigned to an user.
78 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.
79 9       Investigation completed pen     Investigation has been done. Information is available to fix the problem.
80 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.
81 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.
82 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.
83 13      Action verified cls     A check has been done and the results were approved. The notification has been closed.
84 15      SMS sent        opn     An SMS has been sent.
85 14      E-mail sent     opn     An e-mail has been sent.
86 16      Fax sent        opn     An fax has been sent.
87 17      Log entries shown       \N      The log entries relevant to the notification have been shown.
88 18      Notification closed     cls     The notification has been closed.
89 19      Notification reopend    opn     The notification has been reopend.
90 20      Redisplayed to user     \N      The notification has been presented to a user. This is not the first time
91 21      Displayed in list       \N      The notification has been presented in a list with other notifications.
92 \.
93
94 CREATE UNIQUE INDEX action_actionid_key ON "action" USING btree (actionid);
95
96 CREATE UNIQUE INDEX act_pk ON "action" USING btree (actionid);
97
98 CREATE UNIQUE INDEX act_actionname ON "action" USING btree (actionname);
99
100 CREATE INDEX act_statuscode ON "action" USING btree (statuscode);
101
102 SELECT setval ('"action_actionid_seq"', 19, true);
103
104 --
105 --
106
107 CREATE SEQUENCE "action_user_actionstepid_seq";
108
109 CREATE TABLE "action_user"
110 (
111         "actionstepid" bigint DEFAULT
112             nextval('"action_user_actionstepid_seq"'::text) NOT NULL,
113         "actionid" bigint,
114         "username" text,
115         "notificationid" bigint,
116         "timestamp" timestamp with time zone,
117         "statuscode" character varying(3),
118         "remarks" text
119 );
120
121 CREATE UNIQUE INDEX action_user_actionstepid_key ON action_user USING btree (actionstepid);
122
123 CREATE INDEX anu_actionid ON action_user USING btree (actionid);
124
125 CREATE INDEX anu_username ON action_user USING btree (username);
126
127 CREATE INDEX anu_notificationid ON action_user USING btree (notificationid);
128
129 CREATE INDEX anu_timestamp ON action_user USING btree ("timestamp");
130
131 CREATE INDEX anu_statuscode ON action_user USING btree (statuscode);
132
133 SELECT setval ('"action_user_actionstepid_seq"', 1, false);
134
135 --
136 --
137
138 CREATE TABLE "db_value"
139 (
140         "setting" text,
141         "setting_value" text
142 );
143
144
145 COPY "db_value" FROM stdin;
146 db_version      41
147 gcm_daemon_version      5
148 log_processing  0
149 last_notification       0
150 \.
151
152 --
153 --
154
155 CREATE TABLE "history"
156 (
157    paramid            bigint,
158    modified           timestamp,
159    change_nature      text,       --  CREATED, MODIFIED or REMOVED
160    changed_property   text,
161    new_value          text,
162    remark             text
163
164 );
165
166 CREATE INDEX history_pid_mod  ON history(paramid, modified);
167
168 --
169 --
170
171 CREATE SEQUENCE "log_logid_seq";
172
173 CREATE TABLE "log"
174 (
175         "logid" bigint DEFAULT nextval('"log_logid_seq"'::text) NOT NULL,
176         "objectid" bigint,
177         "original_filename" text,
178         "servicecode" text,
179         "object_timestamp" timestamp with time zone,
180         "timestamp" timestamp with time zone,
181         "rawdata" text,
182         "processed" boolean DEFAULT false,
183         "recognized" boolean DEFAULT false
184 );
185
186 CREATE UNIQUE INDEX log_logid_key ON log USING btree (logid);
187
188 CREATE INDEX log_objectid ON log USING btree (objectid);
189
190 CREATE INDEX log_original_filename ON log USING btree (original_filename);
191
192 CREATE INDEX log_servicecode ON log USING btree (servicecode);
193
194 CREATE INDEX log_object_timestmap ON log USING btree ("timestamp");
195
196 CREATE INDEX log_timestmap ON log USING btree ("timestamp");
197
198 CREATE INDEX log_timestamp ON log USING btree (object_timestamp);
199
200 CREATE INDEX log_processed ON log USING btree (processed);
201
202 SELECT setval ('"log_logid_seq"', 1, false);
203
204
205 --
206 --
207
208 CREATE SEQUENCE "log_advid_seq";
209
210
211 CREATE TABLE "log_adv"
212 (
213         "log_advid" bigint DEFAULT
214               nextval('"log_advid_seq"'::text) NOT NULL,
215         "logid" bigint NOT NULL,
216         "detailed_table"    text
217 );
218
219
220 CREATE INDEX log_adv_logid ON log_adv USING btree (logid);
221
222 CREATE UNIQUE INDEX log_adv_log_advid ON log_adv USING btree (log_advid);
223
224 SELECT setval ('"log_advid_seq"', 1, false);
225
226 CREATE TABLE log_adv_kernel_network
227 (
228        device_in         text,
229        device_out        text,
230        hw_address        text, 
231        source_ip         INET,
232        destination_ip    INET,
233        packet_length     bigint, 
234        tos_bit           text, 
235        prec_bit          text,
236        ttl               int,
237        header_id         bigint,
238        source_port       int, 
239        destination_port  int,
240        body_length       int,
241        protocol          text, 
242        body_len          int,
243        window            text,
244        urgp              int,
245        syn               boolean DEFAULT false,
246        type              int,
247        code              int,
248        sequence_number   int,
249        res               text,
250        rst               boolean,
251        df                boolean
252 ) INHERITS (log_adv);
253
254 CREATE TABLE log_adv_daemon
255 (
256        service TEXT,
257        event   TEXT
258 ) INHERITS (log_adv);
259
260 CREATE INDEX log_adv_daemon_service ON log_adv_daemon (service);
261
262 CREATE TABLE log_adv_daemon_email
263 (
264      source_ip            INET,
265      destination_ip       INET,
266      internal_messageid   TEXT, 
267      external_messageid   TEXT,
268      to_email             TEXT,
269      from_email           TEXT,
270      delay                TIME,
271      xdelay               TIME,
272      mailer               TEXT,
273      status               TEXT,
274      pid                  INT,
275      size                 INT,
276      pri                  INT,
277      relay                TEXT,
278      status_details       TEXT,
279      dsn                  TEXT
280 ) INHERITS (log_adv_daemon);
281
282 CREATE INDEX log_adv_daemon_email_s_ip ON log_adv_daemon_email (source_ip);
283 CREATE INDEX log_adv_daemon_email_d_ip ON log_adv_daemon_email (destination_ip);
284 CREATE INDEX log_adv_daemon_email_to   ON log_adv_daemon_email (to_email);
285 CREATE INDEX log_adv_daemon_email_from ON log_adv_daemon_email (from_email);
286 CREATE INDEX log_adv_email_status      ON log_adv_daemon_email (status);
287
288
289 /*
290 CREATE TRUSTED PROCEDURAL LANGUAGE 'plpgsql' HANDLER "plpgsql_call_handler" LANCOMPILER '';
291 CREATE FUNCTION "funct_processlog" () RETURNS opaque AS '
292 -- Initial date: September 18th 2002
293 -- Update: November 13th 2002
294 -- Author: Brenno J.S.A.A.F. de Winter
295 -- Abstract: This routine sets a flag
296 DECLARE
297    var_value    VARCHAR;
298    var_setting  VARCHAR;
299
300 BEGIN
301
302     UPDATE db_value SET setting_value = ''TRUE'' WHERE setting = ''log_flag'';
303     RETURN NULL;
304 END;
305  ' LANGUAGE 'plpgsql';
306
307
308 CREATE TRIGGER "log_insert" AFTER INSERT ON "log"  FOR EACH ROW EXECUTE PROCEDURE "funct_processlog" ();
309 */
310 --
311 --
312
313 CREATE TABLE "log_notification"
314 (
315         "notificationid" bigint,
316         "logid" bigint
317 );
318
319 CREATE UNIQUE INDEX lon_pk ON log_notification USING btree (notificationid, logid);
320
321 CREATE UNIQUE INDEX lon_notificationid ON log_notification USING btree (notificationid);
322
323 CREATE UNIQUE INDEX lon_logid ON log_notification USING btree (logid);
324
325 --
326 --
327
328 CREATE SEQUENCE "notification_notificationid_seq";
329
330 CREATE TABLE "notification"
331 (
332         "notificationid" bigint DEFAULT
333             nextval('"notification_notificationid_seq"'::text) NOT NULL,
334         "objectid" bigint,
335         "type_of_issueid" bigint,
336         "timestamp" timestamp with time zone,
337         "statuscode" character varying(3),
338         "priority" integer,
339         "escalation_count_timestamp" timestamp with time zone,
340         "repeat_notification_timestamp" timestamp with time zone,
341         "securitylevel_view" integer,
342         "securitylevel_add" integer,
343         "securitylevel_close" integer
344 );
345
346 CREATE UNIQUE INDEX notification_notificationid_key ON notification USING btree (notificationid);
347
348 CREATE INDEX not_objectid ON notification USING btree (objectid);
349
350 CREATE INDEX not_type_of_issueid ON notification USING btree (type_of_issueid);
351
352 CREATE INDEX not_timestamp ON notification USING btree ("timestamp");
353
354 CREATE INDEX not_statuscode ON notification USING btree (statuscode);
355
356 CREATE INDEX not_priority ON notification USING btree (priority);
357
358 CREATE INDEX not_escalation_count_timestamp ON notification USING btree (escalation_count_timestamp);
359
360 CREATE INDEX not_repeat_notification_timesta ON notification USING btree (repeat_notification_timestamp);
361
362 SELECT setval ('"notification_notificationid_seq"', 1, false);
363
364 --
365 --
366
367 CREATE SEQUENCE checkid_seq;
368     
369 CREATE TABLE notification_check
370 (
371      checkid                 bigint DEFAULT nextval('checkid_seq'::text) NOT NULL,
372      checkname               TEXT,
373      description             TEXT,
374      time_between_executions INTERVAL, 
375      last_execution          DATETIME,
376      execution_counter       BIGINT,
377      notificationcounter     BIGINT,
378      decreasinglist          BOOLEAN default false,
379      type_of_issueid         BIGINT
380 );
381
382 CREATE UNIQUE INDEX not_check_checkid ON notification_check (checkid);
383
384 CREATE UNIQUE INDEX not_check_checkname ON notification_check (checkname);
385
386 CREATE INDEX not_check_check_lastexec ON notification_check (last_execution);
387
388 --
389 --
390
391 CREATE TABLE notification_check_buffer
392 (
393     checkid     BIGINT,
394     sortorder   INTEGER,
395     pid         INTEGER,
396     logid       bigint
397 );
398
399 CREATE INDEX notcheckbuffer_checkid ON notification_check_buffer(checkid);
400      
401 CREATE INDEX notcheckbuffer_sort ON notification_check_buffer(sortorder);
402
403 CREATE INDEX notcheckbuffer_pid ON notification_check_buffer(pid);
404      
405 CREATE INDEX notcheckbuffer_logid ON notification_check_buffer(logid);
406
407 --
408 --
409
410 CREATE SEQUENCE checklineid_seq;
411      
412 CREATE TABLE notification_check_line
413 (
414     checklineid             BIGINT DEFAULT nextval('checklineid_seq'::text) NOT NULL,
415     checkid                 BIGINT,
416     sortorder               INTEGER,
417     last_logid              BIGINT default 0,
418     historicboundary        INTERVAL default 0,
419     use_logid               BOOLEAN default false,
420     sql_query               TEXT
421 );
422      
423 CREATE UNIQUE INDEX notcheckline_checklineid ON notification_check_line (checklineid);
424
425 CREATE INDEX notcheckline_checkid            ON notification_check_line (checkid);
426
427 CREATE INDEX notcheckline_sort               ON notification_check_line (sortorder);
428
429 CREATE INDEX notcheckline_check_sort         ON notification_check_line (checkid, sortorder);
430
431 --
432 --
433
434 CREATE SEQUENCE "object_objectid_seq";
435
436 CREATE TABLE "object"
437 (
438         "objectid" bigint DEFAULT nextval('"object_objectid_seq"'::text) NOT NULL,
439         "objectname" text,
440         "objectcode" text,
441         "scp_enabled" boolean,
442         "scp_inet" inet,
443         "mail_enabled" boolean,
444         "mail_from" text,
445         "sms_enabled" boolean,
446         "sms_number" text,
447         "fax_enabled" boolean,
448         "fax_number" text,
449         "object_description" text,
450         "object_owner" text,
451         "physical_location" text,
452         "timezone" text,
453         "remark" text,
454         "os"     text,
455         "os_version"   text,
456         "log_count"    bigint,
457         "notification_count"   bigint,
458         "parameter_count"      bigint
459 );
460
461 CREATE UNIQUE INDEX object_objectid_key ON object USING btree (objectid);
462
463 CREATE UNIQUE INDEX obj_objectname ON object USING btree (objectname);
464
465 CREATE UNIQUE INDEX obj_objectcode ON object USING btree (objectcode);
466
467 CREATE INDEX obj_mail_from ON object USING btree (mail_from);
468
469 CREATE INDEX os ON object (os);
470
471 CREATE INDEX os_version ON object (os, os_version);
472
473 SELECT setval ('"object_objectid_seq"', 1, false);
474
475 --
476 --
477
478 CREATE TABLE "object_issue"
479 (
480         "objectid" bigint,
481         "type_of_issueid" bigint,
482         "default_priority" integer,
483         "escalation" boolean,
484         "escalation_time" time without time zone,
485         "max_priority" integer,
486         "adjust_setting" text
487 );
488
489 CREATE UNIQUE INDEX obj_pk ON object_issue USING btree (objectid, type_of_issueid);
490
491 CREATE INDEX obj_objectid ON object_issue USING btree (objectid);
492
493 CREATE UNIQUE INDEX obj_type_of_notificationid ON object_issue USING btree (type_of_issueid);
494
495 --
496 --
497
498 CREATE TABLE "object_priority"
499 (
500         "objectid" bigint,
501         "priorityid" integer,
502         "send_mail" boolean,
503         "send_sms" boolean,
504         "send_fax" boolean,
505         "repeat_notification" boolean,
506         "interval_for_repeat" time without time zone
507 );
508
509 CREATE UNIQUE INDEX obi_pk ON object_priority USING btree (objectid, priorityid);
510
511 CREATE INDEX obi_objectid ON object_priority USING btree (objectid);
512
513 CREATE INDEX obi_priorityid ON object_priority USING btree (priorityid);
514
515 --
516 --
517
518 CREATE TABLE "object_service"
519 (
520         "objectid" bigint,
521         "servicecode" text,
522         "expected_interval" bigint,
523         "last_entry" timestamp with time zone,
524         "default_priority" integer,
525         "maximum_priority" integer,
526         "accepted" boolean
527 );
528
529 CREATE UNIQUE INDEX obs_pk ON object_service USING btree (objectid, servicecode);
530
531 CREATE INDEX obs_objectid ON object_service USING btree (objectid);
532
533 CREATE INDEX obs_servicecode ON object_service USING btree (servicecode);
534
535 CREATE INDEX obs_accepted ON object_service USING btree (accepted);
536
537 --
538 --
539
540 CREATE TABLE object_statistics
541 (
542     objectid       bigint,
543     statname       text,
544     statvalue      double precision,
545
546     primary key (objectid, statname)
547 );
548
549 CREATE INDEX obj_stat_objid ON object_statistics USING btree (objectid);
550
551 --
552 --
553
554 CREATE TABLE "object_user"
555 (
556         "objectid" bigint,
557         "username" text,
558         "security_level" integer
559 );
560
561 CREATE UNIQUE INDEX ous_pk ON object_user USING btree (objectid, username);
562
563 CREATE INDEX ous_objectid ON object_user USING btree (objectid);
564
565 CREATE INDEX ous_username ON object_user USING btree (username);
566
567 CREATE INDEX ous_security_level ON object_user USING btree (security_level);
568
569 --
570 --
571
572 CREATE SEQUENCE "paramid_seq";
573
574 CREATE TABLE "parameter"
575 (
576         "paramid" bigint DEFAULT nextval('"paramid_seq"'::text) NOT NULL,
577         "objectid" bigint,
578         "name" text,
579         "class" text,
580         "description" text,
581
582         primary key (paramid)
583 );
584
585 CREATE UNIQUE INDEX param_obj_name ON parameter USING btree (objectid, name, class);
586
587 SELECT setval ('"paramid_seq"', 1, true);
588
589 --
590 --
591
592 CREATE TABLE "parameter_class"
593 (
594    "name"             text,     --  Name of the class: see parameter.class
595    "property_name"    text,
596    "description"      text,
597    "property_type"    text,     --  STATIC or DYNAMIC
598    "min"              float,    --  Default minimum value
599    "max"              float,    --  Default maximum value
600    "notify"           boolean,  --  Notify if something changes ?
601
602    primary key (name, property_name)
603 );
604
605 INSERT INTO parameter_class (name, property_name, description, property_type, notify)
606   VALUES ('package', 'version', 'The installed version of the package', 'STATIC', 't');
607
608 --
609 --
610
611 CREATE TABLE "parameter_notification"
612 (
613    "notificationid" bigint,
614    "paramid"        bigint,
615
616    primary key (notificationid, paramid)
617 );
618
619 --
620 --
621
622 CREATE TABLE "priority"
623 (
624         "priority" integer,
625         "send_mail" boolean,
626         "send_sms" boolean,
627         "send_fax" boolean,
628         "repeat_notification" boolean,
629         "interval_for_repeat" time without time zone
630 );
631
632
633 CREATE UNIQUE INDEX pri_pk ON priority USING btree (priority);
634
635 --
636 --
637
638 CREATE TABLE "property"
639 (
640    paramid bigint,
641    name    text,
642    value   text,
643    type    text,   --   STATIC or DYNAMIC
644    min     float,
645    max     float,
646
647    primary key (paramid, name)
648 );
649
650 --
651 --
652
653 CREATE TABLE "service"
654 (
655         "servicecode" text,
656         "servicename" text,
657         "default_priority" integer,
658         "max_priority" integer
659 );
660
661 COPY "service" FROM stdin;
662 httpd   httpd   1       5
663 imap    imap    1       5
664 imapd   imapd   1       5
665 kernel  kernel  1       5
666 sshd    sshd    1       5
667 su      su      1       5
668 syslogd syslogd 1       5
669 \.
670
671 CREATE UNIQUE INDEX ser_pk ON service USING btree (servicecode);
672
673 CREATE UNIQUE INDEX ser_servicename ON service USING btree (servicename);
674
675 --
676
677 CREATE TABLE "status"
678 (
679         "statuscode" character varying(3),
680         "statusname" text,
681         "open_notification" boolean,
682         "description" text
683 );
684
685
686 COPY "status" FROM stdin;
687 new     new entry       t       Just detected, but nothing has been done yet
688 opn     open notification       t       The notification has been displayed to a user or a user has been notified. However nothing has been done yet.
689 pen     pending t       The notification is currently being worked on.
690 ver     waiting for verification        t       The notification has been worked on and is currently awaiting the approval/verification.
691 rej     rejected        f       The notification has been identified as a false postive and was reject. The notification is now closed
692 cls     closed  f       The notification has been closed
693 inv     needs investigation     t       The notification is currently under investigation and is awaiting additional details before one can work on this again.
694 \.
695
696 CREATE UNIQUE INDEX sta_pk ON status USING btree (statuscode);
697
698 CREATE UNIQUE INDEX sta_statusname ON status USING btree (statusname);
699
700 CREATE INDEX sta_open_notification ON status USING btree (open_notification);
701
702 --
703 --
704
705 CREATE TABLE supported_os
706 (
707     os_name text,
708     remarks text
709 );
710
711 CREATE UNIQUE INDEX spp_os ON supported_os (os_name);
712
713 --
714 --
715
716 CREATE SEQUENCE "type_of_issue_type_of_issue_seq";
717
718 CREATE TABLE "type_of_issue"
719 (
720         "type_of_issueid" bigint DEFAULT
721            nextval('"type_of_issue_type_of_issue_seq"'::text) NOT NULL,
722         "name" text,
723         "suggested_priority" text,
724         "description" text,
725         "active" boolean,
726         automated_check       boolean,
727         alert_level           int,
728         last_run              timestamp,
729         recheck_interval      timestamp
730 );
731
732
733 COPY "type_of_issue" FROM stdin;
734 1       manual entry    4       A manual entry of a notification        t
735 2       parameter created       3       A new parameter was created     t
736 3       property modified       3       The STATIC property of a parameter was modified t
737 4       parameter removed       3       A parameter was removed t
738 \.
739
740 CREATE UNIQUE INDEX type_of_issue_type_of_issue_key ON type_of_issue USING btree (type_of_issueid);
741
742 CREATE UNIQUE INDEX toi_name ON type_of_issue USING btree (name);
743
744 CREATE INDEX toi_active ON type_of_issue USING btree (active);
745
746 SELECT setval ('"type_of_issue_type_of_issue_seq"', 4, true);
747
748 --
749 --
750
751 CREATE TABLE "usr"
752 (
753         "username" text NOT NULL,
754         "active_sessionid" bigint,
755         "account_active" boolean,
756         "security_level" integer
757 );
758
759 CREATE UNIQUE INDEX usr_username ON usr USING btree (username);
760
761 CREATE UNIQUE INDEX usr_active_sessionid ON usr USING btree (active_sessionid);
762
763 CREATE INDEX usr_account_active ON usr USING btree (account_active);
764
765 CREATE INDEX usr_security_level ON usr USING btree (security_level);
766
767 --
768 --  Set up user groups and grant permissions in the proper places.
769
770 CREATE GROUP view;
771 CREATE GROUP ops;
772 CREATE GROUP admin;
773
774 GRANT SELECT ON action TO GROUP view, GROUP ops, GROUP admin;
775 GRANT SELECT ON action_user TO GROUP view, GROUP ops, GROUP admin;
776 GRANT SELECT ON db_value TO GROUP view, GROUP ops, GROUP admin;
777 GRANT SELECT ON history TO GROUP view, GROUP ops, GROUP admin;
778 GRANT SELECT ON log TO GROUP view, GROUP ops, GROUP admin;
779 GRANT SELECT ON log_adv TO GROUP view, GROUP ops, GROUP admin;
780 GRANT SELECT ON log_adv_daemon TO GROUP view, GROUP ops, GROUP admin;
781 GRANT SELECT ON log_adv_kernel_network TO GROUP view, GROUP ops, GROUP admin;
782 GRANT SELECT ON log_notification TO GROUP view, GROUP ops, GROUP admin;
783 GRANT SELECT ON notification TO GROUP view, GROUP ops, GROUP admin;
784 GRANT SELECT ON object TO GROUP view, GROUP ops, GROUP admin;
785 GRANT SELECT ON object_issue TO GROUP view, GROUP ops, GROUP admin;
786 GRANT SELECT ON object_priority TO GROUP view, GROUP ops, GROUP admin;
787 GRANT SELECT ON object_service TO GROUP view, GROUP ops, GROUP admin;
788 GRANT SELECT ON object_user TO GROUP view, GROUP ops, GROUP admin;
789 GRANT SELECT ON parameter TO GROUP view, GROUP ops, GROUP admin;
790 GRANT SELECT ON parameter_class TO GROUP view, GROUP ops, GROUP admin;
791 GRANT SELECT ON parameter_notification TO GROUP view, GROUP ops, GROUP admin;
792 GRANT SELECT ON priority TO GROUP view, GROUP ops, GROUP admin;
793 GRANT SELECT ON property TO GROUP view, GROUP ops, GROUP admin;
794 GRANT SELECT ON service TO GROUP view, GROUP ops, GROUP admin;
795 GRANT SELECT ON status TO GROUP view, GROUP ops, GROUP admin;
796 GRANT SELECT ON supported_os TO GROUP view, GROUP ops, GROUP admin;
797 GRANT SELECT ON type_of_issue TO GROUP view, GROUP ops, GROUP admin;
798 GRANT SELECT ON usr TO GROUP view, GROUP ops, GROUP admin;
799
800 GRANT INSERT ON action_user TO GROUP ops, GROUP admin;
801 GRANT UPDATE ON notification TO GROUP ops, GROUP admin;
802 GRANT INSERT ON object GROUP admin;
803 GRANT UPDATE ON object TO GROUP ops, GROUP admin;
804 GRANT DELETE ON object GROUP admin;
805 GRANT UPDATE ON usr TO GROUP view, GROUP ops, GROUP admin;
806 GRANT INSERT ON usr TO GROUP admin;
807 GRANT DELETE ON usr TO GROUP admin;