-
Notifications
You must be signed in to change notification settings - Fork 0
/
tables.go
336 lines (305 loc) · 13.2 KB
/
tables.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
package tests
const (
// UsersDropTableV1 SQL statement for table drop
UsersDropTableV1 string = `DROP TABLE IF EXISTS users_v1;`
// UsersTableV1 SQL statement for the users table
UsersTableV1 string = `create table IF NOT EXISTS users_v1 (
id serial primary key not null,
login varchar(100) not null unique,
password varchar(100) not null,
role integer not null,
created timestamptz not null,
last_name varchar(100) not null,
first_name varchar(100) not null,
email varchar(100) not null,
phone varchar(100)
);`
// GroupsDropTableV1 SQL statement for table drop
GroupsDropTableV1 string = `DROP TABLE IF EXISTS user_groups_v1;`
// GroupsTableV1 SQL statement for the groups table
GroupsTableV1 string = `create table IF NOT EXISTS user_groups_v1 (
id serial primary key not null,
name varchar(100) not null UNIQUE
);`
//UserMembershipsDropTableV1 SQL statement for table drop
UserMembershipsDropTableV1 string = `DROP TABLE IF EXISTS user_memberships_v1;`
// UserMembershipsTableV1 SQL statement for the user memberships table
UserMembershipsTableV1 string = `create table IF NOT EXISTS user_memberships_v1 (
user_id integer REFERENCES users_v1 (id),
group_id integer REFERENCES user_groups_v1 (id),
role integer,
PRIMARY KEY(user_id, group_id)
);`
// RulesDropTableV1 SQL statement for table drop
RulesDropTableV1 string = `DROP TABLE IF EXISTS rules_v1;`
// RulesTableV1 SQL statement for the rules table
RulesTableV1 string = `CREATE TABLE IF NOT EXISTS rules_v1 (
id serial PRIMARY KEY,
name varchar(100) not null UNIQUE,
enabled boolean not null,
calendar_id integer REFERENCES calendar_v1 (id),
last_modified timestamptz not null
);`
// RuleVersionsDropTableV1 SQL statement for table drop
RuleVersionsDropTableV1 string = `DROP TABLE IF EXISTS rule_versions_v1;`
// RuleVersionsTableV1 SQL statement for the rules table
RuleVersionsTableV1 string = `CREATE TABLE IF NOT EXISTS rule_versions_v1 (
rule_id INTEGER REFERENCES rules_v1 (id),
version_number INTEGER not null,
data json not null,
creation_datetime timestamptz not null,
PRIMARY KEY(rule_id, version_number)
);`
//SituationHistoryDropTableV1 SQL statement for table drop
SituationHistoryDropTableV1 string = `DROP TABLE IF EXISTS situation_history_v1;`
// SituationHistoryTableV1 SQL statement for the situation history
SituationHistoryTableV1 string = `create table situation_history_v1 (
id integer,
ts timestamptz not null,
situation_instance_id integer,
facts_ids json,
parameters json,
expression_facts jsonb,
metadatas json,
evaluated boolean,
primary key (id, ts, situation_instance_id)
);`
//FactHistoryDropTableV1 SQL statement for table drop
FactHistoryDropTableV1 string = `DROP TABLE IF EXISTS fact_history_v1;`
// FactHistoryTableV1 SQL statement for the fact history
FactHistoryTableV1 string = `create table if not exists fact_history_v1 (
id integer not null,
ts timestamptz not null,
situation_id integer,
situation_instance_id integer,
result jsonb,
success boolean,
primary key (id, ts, situation_id, situation_instance_id)
);`
//FactDefinitionDropTableV1 SQL statement for table drop
FactDefinitionDropTableV1 string = `DROP TABLE IF EXISTS fact_definition_v1;`
// FactDefinitionTableV1 SQL statement for the fact definition table
FactDefinitionTableV1 string = `create table fact_definition_v1 (
id serial primary key,
name varchar(100) not null unique,
definition json,
last_modified timestamptz not null
);`
// SituationDefinitionDropTableV1 SQL statement for table drop
SituationDefinitionDropTableV1 string = `DROP TABLE IF EXISTS situation_definition_v1;`
// SituationDefinitionTableV1 SQL statement for the situation definition table
SituationDefinitionTableV1 string = `create table situation_definition_v1 (
id serial primary key,
name varchar(100) not null unique,
definition json,
is_template boolean,
is_object boolean,
calendar_id integer REFERENCES calendar_v1 (id),
last_modified timestamptz not null
);`
// SituationTemplateInstancesDropTableV1 SQL statement to drop table situation_template_instances_v1
SituationTemplateInstancesDropTableV1 string = `DROP TABLE IF EXISTS situation_template_instances_v1;`
// SituationTemplateInstancesTableV1 SQL statement to create table situation_template_instances_v1
SituationTemplateInstancesTableV1 string = `create table situation_template_instances_v1 (
id serial primary key,
name varchar(100) not null unique,
situation_id integer REFERENCES situation_definition_v1 (id),
parameters json,
calendar_id integer REFERENCES calendar_v1 (id),
last_modified timestamptz not null
);`
// SituationFactsDropTableV1 SQL statement for table drop
SituationFactsDropTableV1 string = `DROP TABLE IF EXISTS situation_facts_v1;`
// SituationFactsTableV1 SQL statement for the situation facts table
SituationFactsTableV1 string = `create table situation_facts_v1 (
situation_id integer REFERENCES situation_definition_v1 (id),
fact_id integer REFERENCES fact_definition_v1 (id),
PRIMARY KEY(situation_id, fact_id)
);`
// NotificationHistoryDropTableV1 SQL statement for table drop
NotificationHistoryDropTableV1 string = `DROP TABLE IF EXISTS notifications_history_v1;`
// NotificationHistoryTableV1 SQL statement for the notification history
NotificationHistoryTableV1 string = `create table notifications_history_v1 (
id serial primary key not null,
groups integer[] not null,
data json,
created_at timestamptz not null,
isread boolean default FALSE
);`
// JobSchedulesDropTableV1 SQL statement for table drop job schedules
JobSchedulesDropTableV1 string = `DROP TABLE IF EXISTS job_schedules_v1;`
// JobSchedulesTableV1 SQL statement for the job schedules
JobSchedulesTableV1 string = `CREATE TABLE job_schedules_v1 (
id serial primary key,
name varchar(100) not null,
cronexpr varchar(100) not null,
job_type varchar(100) not null,
job_data json not null,
last_modified timestamptz not null
);`
// IssuesDropTableV1 SQL statement for table drop
IssuesDropTableV1 string = `DROP TABLE IF EXISTS issues_v1;`
// IssuesTableV1 SQL statement for the issues table
IssuesTableV1 string = `create table issues_v1 (
id serial primary key,
key varchar(100) not null,
name varchar(100) not null,
level varchar(100) not null,
situation_id integer REFERENCES situation_definition_v1 (id),
situation_instance_id integer,
situation_date timestamptz not null,
expiration_date timestamptz not null,
rule_data JSONB,
state varchar(100) not null,
last_modified timestamptz not null,
created_at timestamptz not null,
detection_rating_avg real,
assigned_at timestamptz,
assigned_to varchar(100),
closed_at timestamptz,
closed_by varchar(100),
comment text
);`
// RefRootCauseDropTableV1 SQL statement for table drop
RefRootCauseDropTableV1 string = `DROP TABLE IF EXISTS ref_rootcause_v1;`
// RefRootCauseTableV1 SQL statement for the rootcause references
RefRootCauseTableV1 string = `create table ref_rootcause_v1 (
id serial primary key,
name varchar(100) not null,
description varchar(500) not null,
situation_id integer REFERENCES situation_definition_v1 (id),
rule_id integer REFERENCES rules_v1 (id),
CONSTRAINT unq_name_situationid UNIQUE(name,situation_id)
);`
// RefActionDropTableV1 SQL statement for table drop
RefActionDropTableV1 string = `DROP TABLE IF EXISTS ref_action_v1;`
// RefActionTableV1 SQL statement for the action references
RefActionTableV1 string = `create table ref_action_v1 (
id serial primary key,
name varchar(100) not null,
description varchar(500) not null,
rootcause_id integer REFERENCES ref_rootcause_v1 (id),
CONSTRAINT unq_name_rootcauseid UNIQUE(name,rootcause_id)
);`
// IssueResolutionDropTableV1 SQL statement for table drop
IssueResolutionDropTableV1 string = `DROP TABLE IF EXISTS issue_resolution_v1;`
// IssueResolutionTableV1 SQL statement for the issue resolution statistics
IssueResolutionTableV1 string = `create table issue_resolution_v1 (
feedback_date timestamptz not null,
issue_id integer REFERENCES issues_v1 (id),
rootcause_id integer REFERENCES ref_rootcause_v1 (id),
action_id integer REFERENCES ref_action_v1 (id),
CONSTRAINT unq_issue_rc_action UNIQUE(issue_id,rootcause_id,action_id)
);`
// IssueResolutionDraftDropTableV1 SQL statement for table drop
IssueResolutionDraftDropTableV1 string = `DROP TABLE IF EXISTS issue_resolution_draft_v1;`
// IssueResolutionDraftTableV1 SQL statement for the issue resolution statistics
IssueResolutionDraftTableV1 string = `create table issue_resolution_draft_v1 (
issue_id integer REFERENCES issues_v1 (id) primary key,
concurrency_uuid varchar(100) unique not null,
last_modified timestamptz not null,
data JSONB not null
);`
// SituationRulesDropTableV1 SQL statement to drop table situation_rules_v1
SituationRulesDropTableV1 string = `DROP TABLE IF EXISTS situation_rules_v1;`
// SituationRulesTableV1 SQL statement to create table situation_rules_v1
SituationRulesTableV1 string = `create table situation_rules_v1 (
situation_id integer REFERENCES situation_definition_v1 (id),
rule_id integer REFERENCES rules_v1 (id),
execution_order integer,
PRIMARY KEY(situation_id, rule_id)
);`
// ModelDropTableV1 SQL statement to drop table model_v1
ModelDropTableV1 string = `DROP TABLE IF EXISTS model_v1;`
// ModelTableV1 SQL statement to create table model_v1
ModelTableV1 string = `create table IF NOT EXISTS model_v1 (
id serial primary key,
name varchar(100) unique not null,
definition JSONB
);`
// EsIndicesDropTableV1 SQL statement to drop table elasticsearch_indices_v1
EsIndicesDropTableV1 string = `DROP TABLE IF EXISTS elasticsearch_indices_v1;`
// EsIndicesTableV1 SQL statement to create table elasticsearch_indices_v1
EsIndicesTableV1 string = `create table IF NOT EXISTS elasticsearch_indices_v1 (
id serial primary key,
logical varchar(100) not null,
technical varchar(100) not null,
creation_date timestamptz not null
);`
// IssueFeedbackDropTableV3 SQL statement to drop table issue_detection_feedback_v3
IssueFeedbackDropTableV3 string = `DROP TABLE IF EXISTS issue_detection_feedback_v3;`
// IssueFeedbackTableV3 SQL statement to create table issue_detection_feedback_v3
IssueFeedbackTableV3 string = ` create table issue_detection_feedback_v3 (
id serial primary key,
issue_id integer references issues_v1(id) not null,
user_id integer references users_v1(id) not null,
date timestamptz not null,
rating integer,
CONSTRAINT unq_issueid_userid UNIQUE(issue_id,user_id)
);`
// CalendarDropTableV3 SQL statement to drop table calendar_v1
CalendarDropTableV3 string = `DROP TABLE IF EXISTS calendar_V1;`
// CalendarTableV3 SQL statement to create table calendar_v1
CalendarTableV3 string = `create table calendar_v1 (
id serial primary key,
name varchar(100) not null,
description varchar(500) not null,
timezone varchar(100) not null default 'Europe/Paris',
period_data JSONB not null,
enabled boolean not null,
creation_date timestamptz not null,
last_modified timestamptz not null
);`
// CalendarUnionDropTableV3 SQL statement to drop table calendar_union_v1
CalendarUnionDropTableV3 string = `DROP TABLE IF EXISTS calendar_union_v1;`
// CalendarUnionTableV3 SQL statement to create table calendar_union_v1
CalendarUnionTableV3 string = `create table calendar_union_v1 (
calendar_id integer REFERENCES calendar_v1 (id),
sub_calendar_id integer REFERENCES calendar_v1 (id),
priority integer,
PRIMARY KEY(calendar_id, sub_calendar_id)
);`
//ConnectorExecutionsLogsDropTableV1 SQL statement to drop table connectors_executions_log_v1
ConnectorExecutionsLogsDropTableV1 string = `DROP TABLE IF EXISTS connectors_executions_log_v1;`
//ConnectorExecutionsLogsTableV1 SQL statement to create table connectors_executions_log_v1
ConnectorExecutionsLogsTableV1 string = `create table connectors_executions_log_v1 (
id serial primary key not null,
connector_id varchar(100) not null,
name varchar(100) not null,
ts timestamptz not null,
success boolean
);`
UsersDropTableV4 string = `drop table if exists users_v4;`
UsersCreateTableV4 string = `create table users_v4 (
id uuid primary key not null,
login varchar(100) not null unique,
password varchar(100) not null,
created timestamptz not null,
last_name varchar(100) not null,
first_name varchar(100) not null,
email varchar(100) not null,
phone varchar(100)
);`
RolesDropTableV4 string = `drop table if exists roles_v4;`
RolesCreateTableV4 string = `create table roles_v4 (
id uuid primary key,
name varchar(100) not null UNIQUE
);`
PermissionsDropTableV4 string = `drop table if exists permissions_v4;`
PermissionsCreateTableV4 string = `create table permissions_v4 (
id uuid primary key,
resource_type varchar(100) not null,
resource_id varchar(100) not null,
action varchar(100) not null
);`
UsersRolesDropTableV4 string = `drop table if exists users_roles_v4;`
UsersRolesCreateTableV4 string = `create table users_roles_v4 (
user_id uuid REFERENCES users_v4 (id),
role_id uuid REFERENCES roles_v4 (id)
);`
RolesPermissionsDropTableV4 string = `drop table if exists roles_permissions_v4;`
RolesPermissionsCreateTableV4 string = `create table roles_permissions_v4 (
role_id uuid REFERENCES roles_v4 (id),
permission_id uuid REFERENCES permissions_v4 (id)
);`
)