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