/ db /
/db/makewarningtables.m4
1 dnl Copyright (C) 2015 The Meme Factory, Inc., http://www.meme.com/
2 dnl
3 dnl This file is part of Gombe-MI.
4 dnl
5 dnl Gombe-MI is free software; you can redistribute it and/or modify
6 dnl it under the terms of the GNU General Public License as published by
7 dnl the Free Software Foundation; either version 3 of the License, or
8 dnl (at your option) any later version.
9 dnl
10 dnl This program is distributed in the hope that it will be useful,
11 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
12 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 dnl GNU General Public License for more details.
14 dnl
15 dnl You should have received a copy of the GNU General Public License
16 dnl along with Gombe-MI. If not, see <http://www.gnu.org/licenses/>.
17 dnl
18 dnl Karl O. Pinc <kop@meme.com>
19 dnl
20 dnl Remarks:
21 dnl A separate file from maketables.m4 since it's purpose is orthogonal.
22 dnl
23 dnl m4 includes
24 include(`copyright.m4')
25 include(`constants.m4')
26 include(`grants.m4')
27 include(`types.m4')
28 include(`tablemacros.m4')
29
30
31 --
32 -- Support Tables
33 --
34
35 -- The key, descr support tables.
36
37 -- support`'_table(`foo', `fookey', `SMALLINT', `')
38 -- support`'_table(`bar', `barkey', `CHAR(1)'
39 -- , `empty_`'string_check(`barkey')')
40
41 support_table(`IQTYPES', `IQType', `VARCHAR(warn_iqtype_len)'
42 , `empty_string_check(`IQType')
43 space_not_allowed_check(`IQType')')
44
45 support_table(`WARNING_REMARKS', `WRID', `VARCHAR(warn_wrid_len)'
46 , `empty_string_check(`WRID')
47 space_not_allowed_check(`WRID')')
48
49 --
50 -- The primary tables
51 --
52
53 -- integrity_queries
54 CREATE TABLE integrity_queries (
55 iqname VARCHAR(warn_iqname_len) PRIMARY KEY
56 empty_string_check(`IQName')
57 space_not_allowed_check(`IQName')
58 , error BOOLEAN NOT NULL
59 , type VARCHAR(warn_iqtype_len) NOT NULL
60 CONSTRAINT "Type on IQTypes" REFERENCES iqtypes
61 , first_run TIMESTAMP(0) WITHOUT TIME ZONE
62 , last_run TIMESTAMP(0) WITHOUT TIME ZONE
63 CONSTRAINT "Last_Run must be >= First_Run"
64 CHECK(last_run IS NULL
65 OR first_run IS NULL
66 OR first_run <= last_run)
67 , query TEXT NOT NULL
68 empty_string_check(`Query')
69 , comment TEXT
70 empty_string_check(`Comment')
71 );
72
73 grant_priv(`INTEGRITY_QUERIES')
74
75 -- integrity_warnings
76 CREATE TABLE integrity_warnings (
77 iwid SERIAL PRIMARY KEY
78 , iqname VARCHAR(warn_iqname_len) NOT NULL
79 , first_seen TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL
80 , last_seen TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL
81 CONSTRAINT "Last_Seen must be >= First_Seen"
82 CHECK(first_seen <= last_seen)
83 , resolved TIMESTAMP(0) WITHOUT TIME ZONE
84 CONSTRAINT "Resolved must be >= First_Seen"
85 CHECK(resolved IS NULL OR first_seen <= resolved)
86 , deferred_to TIMESTAMP(0) WITHOUT TIME ZONE
87 CONSTRAINT "Either Resolved or Deferred_To or both must be NULL"
88 CHECK(NOT(resolved IS NOT NULL AND deferred_to IS NOT NULL))
89 CONSTRAINT "Deferred_To must be >= First_Seen"
90 CHECK(deferred_to IS NULL OR first_seen <= deferred_to)
91 , category VARCHAR(warn_wrid_len)
92 CONSTRAINT "Category on WARNING_REMARKS"
93 REFERENCES warning_remarks
94 , warning_id TEXT NOT NULL
95 empty_string_check(`Warning_ID')
96 , warning_message TEXT NOT NULL
97 empty_string_check(`Warning_Message')
98 , notes TEXT
99 empty_string_check(`Notes')
100 );
101
102 -- Let editors update everything but warning_id and warning_message.
103 grant_priv(`INTEGRITY_WARNINGS')
104 grant_seq_priv(`INTEGRITY_WARNINGS', `IWID')