(1.0.D002) Create Database
authorarjen <arjen>
Mon, 9 Sep 2002 07:18:29 +0000 (07:18 +0000)
committerarjen <arjen>
Mon, 9 Sep 2002 07:18:29 +0000 (07:18 +0000)
src/database/create.sql [new file with mode: 0644]
src/database/destroy.sql [new file with mode: 0644]
test/t0002a.sh [new file with mode: 0644]

diff --git a/src/database/create.sql b/src/database/create.sql
new file mode 100644 (file)
index 0000000..9ade001
--- /dev/null
@@ -0,0 +1,463 @@
+--
+-- Gnucomo database creation script.
+--
+--
+-- This SQL script creates the initial tables for the Gnucomo database.
+-- Before running this script with 'psql -f', you should have your
+-- DBA create the database and give access permissions.
+--
+--
+
+CREATE SEQUENCE "action_actionid_seq";
+
+CREATE TABLE "action"
+(
+       "actionid" bigint DEFAULT nextval('"action_actionid_seq"'::text) NOT NULL,
+       "actionname" text,
+       "statuscode" character varying(3),
+       "description" text
+);
+
+
+COPY "action" FROM stdin;
+1      Entry in the system     NEW     This indicates that a notification has been entered into the system.
+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
+3      Remarks added   PEN     Remarks have been added to the notification.
+4      Priority changed manually       PEN     The priority of the notification has been changed by the user.
+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.
+6      Action taken    PEN     An action has been taken.
+7      Assignment to user      PEN     The notification has been assigned to an user.
+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.
+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
+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.
+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.
+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.
+13     Action verified CLS     A check has been done and the results were approved. The notification has been closed.
+15     SMS sent        OPN     An SMS has been sent.
+14     E-mail sent     OPN     An e-mail has been sent.
+16     Fax sent        OPN     An fax has been sent.
+17     Log entries shown       \N      The log entries relevant to the notification have been shown.
+18     Notification closed     CLS     The notification has been closed.
+19     Notification reopend    OPN     The notification has been reopend.
+\.
+
+CREATE UNIQUE INDEX action_actionid_key ON "action" USING btree (actionid);
+
+CREATE UNIQUE INDEX act_pk ON "action" USING btree (actionid);
+
+CREATE UNIQUE INDEX act_actionname ON "action" USING btree (actionname);
+
+CREATE INDEX act_statuscode ON "action" USING btree (statuscode);
+
+SELECT setval ('"action_actionid_seq"', 19, true);
+
+--
+--
+
+CREATE SEQUENCE "action_user_actionstepid_seq";
+
+CREATE TABLE "action_user"
+(
+       "actionstepid" bigint DEFAULT
+            nextval('"action_user_actionstepid_seq"'::text) NOT NULL,
+       "actionid" bigint,
+       "username" text,
+       "notificationid" bigint,
+       "timestamp" timestamp with time zone,
+       "statuscode" character varying(3),
+       "remarks" text
+);
+
+CREATE UNIQUE INDEX action_user_actionstepid_key ON action_user USING btree (actionstepid);
+
+CREATE INDEX anu_actionid ON action_user USING btree (actionid);
+
+CREATE INDEX anu_username ON action_user USING btree (username);
+
+CREATE INDEX anu_notificationid ON action_user USING btree (notificationid);
+
+CREATE INDEX anu_timestamp ON action_user USING btree ("timestamp");
+
+CREATE INDEX anu_statuscode ON action_user USING btree (statuscode);
+
+SELECT setval ('"action_user_actionstepid_seq"', 1, false);
+
+--
+--
+
+CREATE SEQUENCE "log_logid_seq";
+
+CREATE TABLE "log"
+(
+       "logid" bigint DEFAULT nextval('"log_logid_seq"'::text) NOT NULL,
+       "objectid" bigint,
+       "original_filename" text,
+       "servicecode" text,
+       "object_timestamp" timestamp with time zone,
+       "timestamp" timestamp with time zone,
+       "rawdata" text
+);
+
+CREATE UNIQUE INDEX log_logid_key ON log USING btree (logid);
+
+CREATE INDEX log_objectid ON log USING btree (objectid);
+
+CREATE INDEX log_original_filename ON log USING btree (original_filename);
+
+CREATE INDEX log_servicecode ON log USING btree (servicecode);
+
+CREATE INDEX log_object_timestmap ON log USING btree ("timestamp");
+
+CREATE INDEX log_timestmap ON log USING btree ("timestamp");
+
+CREATE INDEX log_timestamp ON log USING btree (object_timestamp);
+
+SELECT setval ('"log_logid_seq"', 1, false);
+
+--
+--
+
+CREATE TABLE "log_adv"
+(
+       "logid" bigint,
+       "source_ip" inet,
+       "destination_ip" inet,
+       "mac_address" macaddr,
+       "packetlength" integer,
+       "protocol" text,
+       "source_port" integer,
+       "destination_port" integer,
+       "messageid" text,
+       "system_username" text,
+       "networkdevice" text
+);
+
+CREATE INDEX loa_logid ON log_adv USING btree (logid);
+
+CREATE INDEX loa_source_ip ON log_adv USING btree (source_ip);
+
+CREATE INDEX loa_destination_ip ON log_adv USING btree (destination_ip);
+
+CREATE INDEX loa_mac_address ON log_adv USING btree (mac_address);
+
+CREATE INDEX loa_packetlength ON log_adv USING btree (packetlength);
+
+CREATE INDEX loa_protocol ON log_adv USING btree (protocol);
+
+CREATE INDEX loa_source_port ON log_adv USING btree (source_port);
+
+CREATE INDEX loa_destination_port ON log_adv USING btree (destination_port);
+
+CREATE INDEX loa_messageid ON log_adv USING btree (messageid);
+
+CREATE INDEX loa_system_username ON log_adv USING btree (system_username);
+
+CREATE INDEX loa_networkdevice ON log_adv USING btree (networkdevice);
+
+--
+--
+
+CREATE TABLE "log_notification"
+(
+       "notificationid" bigint,
+       "logid" bigint
+);
+
+CREATE UNIQUE INDEX lon_pk ON log_notification USING btree (notificationid, logid);
+
+CREATE UNIQUE INDEX lon_notificationid ON log_notification USING btree (notificationid);
+
+CREATE UNIQUE INDEX lon_logid ON log_notification USING btree (logid);
+
+--
+--
+
+CREATE SEQUENCE "notification_notificationid_seq";
+
+CREATE TABLE "notification"
+(
+       "notificationid" bigint DEFAULT
+            nextval('"notification_notificationid_seq"'::text) NOT NULL,
+       "objectid" bigint,
+       "type_of_notificationid" bigint,
+       "timestamp" timestamp with time zone,
+       "statuscode" character varying(3),
+       "priority" integer,
+       "escalation_count_timestamp" timestamp with time zone,
+       "repeat_notification_timestamp" timestamp with time zone,
+       "securitylevel_view" integer,
+       "securitylevel_add" integer,
+       "securitylevel_close" integer
+);
+
+CREATE UNIQUE INDEX notification_notificationid_key ON notification USING btree (notificationid);
+
+CREATE INDEX not_objectid ON notification USING btree (objectid);
+
+CREATE INDEX not_type_of_notificationid ON notification USING btree (type_of_notificationid);
+
+CREATE INDEX not_timestamp ON notification USING btree ("timestamp");
+
+CREATE INDEX not_statuscode ON notification USING btree (statuscode);
+
+CREATE INDEX not_priority ON notification USING btree (priority);
+
+CREATE INDEX not_escalation_count_timestamp ON notification USING btree (escalation_count_timestamp);
+
+CREATE INDEX not_repeat_notification_timesta ON notification USING btree (repeat_notification_timestamp);
+
+SELECT setval ('"notification_notificationid_seq"', 1, false);
+
+--
+--
+
+CREATE SEQUENCE "object_objectid_seq";
+
+CREATE TABLE "object"
+(
+       "objectid" bigint DEFAULT nextval('"object_objectid_seq"'::text) NOT NULL,
+       "objectname" text,
+       "objectcode" text,
+       "scp_enabled" boolean,
+       "scp_inet" inet,
+       "mail_enabled" boolean,
+       "mail_from" text,
+       "sms_enabled" boolean,
+       "sms_number" text,
+       "fax_enabled" boolean,
+       "fax_number" text,
+       "object_description" text,
+       "object_owner" text,
+       "physical_location" text,
+       "timezone" text,
+       "remark" text
+);
+
+CREATE UNIQUE INDEX object_objectid_key ON object USING btree (objectid);
+
+CREATE UNIQUE INDEX obj_objectname ON object USING btree (objectname);
+
+CREATE UNIQUE INDEX obj_objectcode ON object USING btree (objectcode);
+
+CREATE INDEX obj_mail_from ON object USING btree (mail_from);
+
+SELECT setval ('"object_objectid_seq"', 1, false);
+
+--
+--
+
+CREATE TABLE "object_issue"
+(
+       "objectid" bigint,
+       "type_of_notificationid" bigint,
+       "default_priority" integer,
+       "escalation" boolean,
+       "escalation_time" time without time zone,
+       "max_priority" integer,
+       "adjust_setting" text
+);
+
+CREATE UNIQUE INDEX obj_pk ON object_issue USING btree (objectid, type_of_notificationid);
+
+CREATE INDEX obj_objectid ON object_issue USING btree (objectid);
+
+CREATE UNIQUE INDEX obj_type_of_notificationid ON object_issue USING btree (type_of_notificationid);
+
+--
+--
+
+CREATE TABLE "object_priority"
+(
+       "objectid" bigint,
+       "priorityid" integer,
+       "send_mail" boolean,
+       "send_sms" boolean,
+       "send_fax" boolean,
+       "repeat_notification" boolean,
+       "interval_for_repeat" time without time zone
+);
+
+CREATE UNIQUE INDEX obi_pk ON object_priority USING btree (objectid, priorityid);
+
+CREATE INDEX obi_objectid ON object_priority USING btree (objectid);
+
+CREATE INDEX obi_priorityid ON object_priority USING btree (priorityid);
+
+--
+--
+
+CREATE TABLE "object_service"
+(
+       "objectid" bigint,
+       "servicecode" text,
+       "expected_interval" bigint,
+       "last_entry" timestamp with time zone,
+       "default_priority" integer,
+       "maximum_priority" integer,
+       "accepted" boolean
+);
+
+CREATE UNIQUE INDEX obs_pk ON object_service USING btree (objectid, servicecode);
+
+CREATE INDEX obs_objectid ON object_service USING btree (objectid);
+
+CREATE INDEX obs_servicecode ON object_service USING btree (servicecode);
+
+CREATE INDEX obs_accepted ON object_service USING btree (accepted);
+
+--
+--
+
+CREATE TABLE "object_system_user"
+(
+       "objectid" bigint,
+       "system_username" text,
+       "can_login" boolean,
+       "can_be_root" boolean
+);
+
+CREATE UNIQUE INDEX osu_pk ON object_system_user USING btree (objectid, system_username);
+
+CREATE INDEX osu_objectid ON object_system_user USING btree (objectid);
+
+CREATE INDEX osu_system_username ON object_system_user USING btree (system_username);
+
+--
+--
+
+CREATE TABLE "object_user"
+(
+       "objectid" bigint,
+       "username" text,
+       "security_level" integer
+);
+
+CREATE UNIQUE INDEX ous_pk ON object_user USING btree (objectid, username);
+
+CREATE INDEX ous_objectid ON object_user USING btree (objectid);
+
+CREATE INDEX ous_username ON object_user USING btree (username);
+
+CREATE INDEX ous_security_level ON object_user USING btree (security_level);
+
+--
+--
+
+CREATE TABLE "priority"
+(
+       "priority" integer,
+       "send_mail" boolean,
+       "send_sms" boolean,
+       "send_fax" boolean,
+       "repeat_notification" boolean,
+       "interval_for_repeat" time without time zone
+);
+
+
+CREATE UNIQUE INDEX pri_pk ON priority USING btree (priority);
+
+--
+--
+
+CREATE TABLE "service"
+(
+       "servicecode" text,
+       "servicename" text,
+       "default_priority" integer,
+       "max_priority" integer
+);
+
+CREATE UNIQUE INDEX ser_pk ON service USING btree (servicecode);
+
+CREATE UNIQUE INDEX ser_servicename ON service USING btree (servicename);
+
+--
+--
+
+CREATE TABLE "status"
+(
+       "statuscode" character varying(3),
+       "statusname" text,
+       "open_notification" boolean,
+       "description" text
+);
+
+
+COPY "status" FROM stdin;
+new    new entry       t       Just detected, but nothing has been done yet
+opn    open notification       t       The notification has been displayed to a user or a user has been notified. However nothing has been done yet.
+pen    pending t       The notification is currently being worked on.
+ver    waiting for verification        t       The notification has been worked on and is currently awaiting the approval/verification.
+rej    rejected        f       The notification has been identified as a false postive and was reject. The notification is now closed
+cls    closed  f       The notification has been closed
+inv    needs investigation     t       The notification is currently under investigation and is awaiting additional details before one can work on this again.
+\.
+
+CREATE UNIQUE INDEX sta_pk ON status USING btree (statuscode);
+
+CREATE UNIQUE INDEX sta_statusname ON status USING btree (statusname);
+
+CREATE INDEX sta_open_notification ON status USING btree (open_notification);
+
+--
+--
+
+CREATE SEQUENCE "type_of_issue_type_of_issue_seq";
+
+CREATE TABLE "type_of_issue"
+(
+       "type_of_issueid" bigint DEFAULT
+           nextval('"type_of_issue_type_of_issue_seq"'::text) NOT NULL,
+       "name" text,
+       "suggested_priority" text,
+       "description" text,
+       "active" boolean
+);
+
+
+COPY "type_of_issue" FROM stdin;
+1      manual entry    4       A manual entry of a notification        t
+\.
+
+CREATE UNIQUE INDEX type_of_issue_type_of_issue_key ON type_of_issue USING btree (type_of_issueid);
+
+CREATE UNIQUE INDEX toi_name ON type_of_issue USING btree (name);
+
+CREATE INDEX toi_active ON type_of_issue USING btree (active);
+
+SELECT setval ('"type_of_issue_type_of_issue_seq"', 1, true);
+
+--
+--
+
+CREATE SEQUENCE "unprocessed_l_unprocessedid_seq";
+
+CREATE TABLE "unprocessed_log"
+(
+       "unprocessedid" bigint DEFAULT
+           nextval('"unprocessed_l_unprocessedid_seq"'::text) NOT NULL,
+       "objectid" bigint,
+       "servicecode" text
+);
+
+CREATE UNIQUE INDEX unprocessed_l_unprocessedid_key ON unprocessed_log USING btree (unprocessedid);
+
+SELECT setval ('"unprocessed_l_unprocessedid_seq"', 1, false);
+
+--
+--
+
+CREATE TABLE "user_gnucomo"
+(
+       "username" text,
+       "password" text,
+       "active_sessionid" bigint,
+       "account_active" boolean,
+       "security_level" integer
+);
+
+CREATE UNIQUE INDEX usr_pk ON user_gnucomo USING btree (username);
+
+CREATE INDEX usr_active_sessionid ON user_gnucomo USING btree (active_sessionid);
+
+
diff --git a/src/database/destroy.sql b/src/database/destroy.sql
new file mode 100644 (file)
index 0000000..68e9a11
--- /dev/null
@@ -0,0 +1,60 @@
+--
+-- Gnucomo database destruction script.
+--
+--
+-- This SQL script drops all tables and sequences from the database
+-- It is primarily used for testing, where we clean up after performing
+-- a test.
+--
+--
+
+DROP SEQUENCE "action_actionid_seq";
+
+DROP TABLE "action";
+
+DROP SEQUENCE "action_user_actionstepid_seq";
+
+DROP TABLE "action_user";
+
+DROP SEQUENCE "log_logid_seq";
+
+DROP TABLE "log";
+
+DROP TABLE "log_adv";
+
+DROP TABLE "log_notification";
+
+DROP SEQUENCE "notification_notificationid_seq";
+
+DROP TABLE "notification";
+
+DROP SEQUENCE "object_objectid_seq";
+
+DROP TABLE "object";
+
+DROP TABLE "object_issue";
+
+DROP TABLE "object_priority";
+
+DROP TABLE "object_service";
+
+DROP TABLE "object_system_user";
+
+DROP TABLE "object_user";
+
+DROP TABLE "priority";
+
+DROP TABLE "service";
+
+DROP TABLE "status";
+
+DROP SEQUENCE "type_of_issue_type_of_issue_seq";
+
+DROP TABLE "type_of_issue";
+
+DROP SEQUENCE "unprocessed_l_unprocessedid_seq";
+
+DROP TABLE "unprocessed_log";
+
+DROP TABLE "user_gnucomo";
+
diff --git a/test/t0002a.sh b/test/t0002a.sh
new file mode 100644 (file)
index 0000000..7ccb431
--- /dev/null
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+if psql gnucomo_test -f src/create.sql
+then
+   psql gnucomo_test -c 'select statuscode from status'
+   result=$?
+   psql gnucomo_test -f src/destroy.sql
+   exit $result
+else
+   echo Can not create test database
+   exit 1
+fi