1CREATE TABLE users (
2	userid                   bigint                                    NOT NULL,
3	alias                    varchar(100)    DEFAULT ''                NOT NULL,
4	name                     varchar(100)    DEFAULT ''                NOT NULL,
5	surname                  varchar(100)    DEFAULT ''                NOT NULL,
6	passwd                   varchar(60)     DEFAULT ''                NOT NULL,
7	url                      varchar(255)    DEFAULT ''                NOT NULL,
8	autologin                integer         DEFAULT '0'               NOT NULL,
9	autologout               varchar(32)     DEFAULT '15m'             NOT NULL,
10	lang                     varchar(5)      DEFAULT 'en_GB'           NOT NULL,
11	refresh                  varchar(32)     DEFAULT '30s'             NOT NULL,
12	type                     integer         DEFAULT '1'               NOT NULL,
13	theme                    varchar(128)    DEFAULT 'default'         NOT NULL,
14	attempt_failed           integer         DEFAULT 0                 NOT NULL,
15	attempt_ip               varchar(39)     DEFAULT ''                NOT NULL,
16	attempt_clock            integer         DEFAULT 0                 NOT NULL,
17	rows_per_page            integer         DEFAULT 50                NOT NULL,
18	PRIMARY KEY (userid)
19);
20CREATE UNIQUE INDEX users_1 ON users (alias);
21CREATE TABLE maintenances (
22	maintenanceid            bigint                                    NOT NULL,
23	name                     varchar(128)    DEFAULT ''                NOT NULL,
24	maintenance_type         integer         DEFAULT '0'               NOT NULL,
25	description              text            DEFAULT ''                NOT NULL,
26	active_since             integer         DEFAULT '0'               NOT NULL,
27	active_till              integer         DEFAULT '0'               NOT NULL,
28	tags_evaltype            integer         DEFAULT '0'               NOT NULL,
29	PRIMARY KEY (maintenanceid)
30);
31CREATE INDEX maintenances_1 ON maintenances (active_since,active_till);
32CREATE UNIQUE INDEX maintenances_2 ON maintenances (name);
33CREATE TABLE hosts (
34	hostid                   bigint                                    NOT NULL,
35	proxy_hostid             bigint                                    NULL,
36	host                     varchar(128)    DEFAULT ''                NOT NULL,
37	status                   integer         DEFAULT '0'               NOT NULL,
38	disable_until            integer         DEFAULT '0'               NOT NULL,
39	error                    varchar(2048)   DEFAULT ''                NOT NULL,
40	available                integer         DEFAULT '0'               NOT NULL,
41	errors_from              integer         DEFAULT '0'               NOT NULL,
42	lastaccess               integer         DEFAULT '0'               NOT NULL,
43	ipmi_authtype            integer         DEFAULT '-1'              NOT NULL,
44	ipmi_privilege           integer         DEFAULT '2'               NOT NULL,
45	ipmi_username            varchar(16)     DEFAULT ''                NOT NULL,
46	ipmi_password            varchar(20)     DEFAULT ''                NOT NULL,
47	ipmi_disable_until       integer         DEFAULT '0'               NOT NULL,
48	ipmi_available           integer         DEFAULT '0'               NOT NULL,
49	snmp_disable_until       integer         DEFAULT '0'               NOT NULL,
50	snmp_available           integer         DEFAULT '0'               NOT NULL,
51	maintenanceid            bigint                                    NULL,
52	maintenance_status       integer         DEFAULT '0'               NOT NULL,
53	maintenance_type         integer         DEFAULT '0'               NOT NULL,
54	maintenance_from         integer         DEFAULT '0'               NOT NULL,
55	ipmi_errors_from         integer         DEFAULT '0'               NOT NULL,
56	snmp_errors_from         integer         DEFAULT '0'               NOT NULL,
57	ipmi_error               varchar(2048)   DEFAULT ''                NOT NULL,
58	snmp_error               varchar(2048)   DEFAULT ''                NOT NULL,
59	jmx_disable_until        integer         DEFAULT '0'               NOT NULL,
60	jmx_available            integer         DEFAULT '0'               NOT NULL,
61	jmx_errors_from          integer         DEFAULT '0'               NOT NULL,
62	jmx_error                varchar(2048)   DEFAULT ''                NOT NULL,
63	name                     varchar(128)    DEFAULT ''                NOT NULL,
64	flags                    integer         DEFAULT '0'               NOT NULL,
65	templateid               bigint                                    NULL,
66	description              text            DEFAULT ''                NOT NULL,
67	tls_connect              integer         DEFAULT '1'               NOT NULL,
68	tls_accept               integer         DEFAULT '1'               NOT NULL,
69	tls_issuer               varchar(1024)   DEFAULT ''                NOT NULL,
70	tls_subject              varchar(1024)   DEFAULT ''                NOT NULL,
71	tls_psk_identity         varchar(128)    DEFAULT ''                NOT NULL,
72	tls_psk                  varchar(512)    DEFAULT ''                NOT NULL,
73	proxy_address            varchar(255)    DEFAULT ''                NOT NULL,
74	auto_compress            integer         DEFAULT '1'               NOT NULL,
75	discover                 integer         DEFAULT '0'               NOT NULL,
76	PRIMARY KEY (hostid)
77);
78CREATE INDEX hosts_1 ON hosts (host);
79CREATE INDEX hosts_2 ON hosts (status);
80CREATE INDEX hosts_3 ON hosts (proxy_hostid);
81CREATE INDEX hosts_4 ON hosts (name);
82CREATE INDEX hosts_5 ON hosts (maintenanceid);
83CREATE TABLE hstgrp (
84	groupid                  bigint                                    NOT NULL,
85	name                     varchar(255)    DEFAULT ''                NOT NULL,
86	internal                 integer         DEFAULT '0'               NOT NULL,
87	flags                    integer         DEFAULT '0'               NOT NULL,
88	PRIMARY KEY (groupid)
89);
90CREATE INDEX hstgrp_1 ON hstgrp (name);
91CREATE TABLE group_prototype (
92	group_prototypeid        bigint                                    NOT NULL,
93	hostid                   bigint                                    NOT NULL,
94	name                     varchar(255)    DEFAULT ''                NOT NULL,
95	groupid                  bigint                                    NULL,
96	templateid               bigint                                    NULL,
97	PRIMARY KEY (group_prototypeid)
98);
99CREATE INDEX group_prototype_1 ON group_prototype (hostid);
100CREATE TABLE group_discovery (
101	groupid                  bigint                                    NOT NULL,
102	parent_group_prototypeid bigint                                    NOT NULL,
103	name                     varchar(64)     DEFAULT ''                NOT NULL,
104	lastcheck                integer         DEFAULT '0'               NOT NULL,
105	ts_delete                integer         DEFAULT '0'               NOT NULL,
106	PRIMARY KEY (groupid)
107);
108CREATE TABLE screens (
109	screenid                 bigint                                    NOT NULL,
110	name                     varchar(255)                              NOT NULL,
111	hsize                    integer         DEFAULT '1'               NOT NULL,
112	vsize                    integer         DEFAULT '1'               NOT NULL,
113	templateid               bigint                                    NULL,
114	userid                   bigint                                    NULL,
115	private                  integer         DEFAULT '1'               NOT NULL,
116	PRIMARY KEY (screenid)
117);
118CREATE INDEX screens_1 ON screens (templateid);
119CREATE TABLE screens_items (
120	screenitemid             bigint                                    NOT NULL,
121	screenid                 bigint                                    NOT NULL,
122	resourcetype             integer         DEFAULT '0'               NOT NULL,
123	resourceid               bigint          DEFAULT '0'               NOT NULL,
124	width                    integer         DEFAULT '320'             NOT NULL,
125	height                   integer         DEFAULT '200'             NOT NULL,
126	x                        integer         DEFAULT '0'               NOT NULL,
127	y                        integer         DEFAULT '0'               NOT NULL,
128	colspan                  integer         DEFAULT '1'               NOT NULL,
129	rowspan                  integer         DEFAULT '1'               NOT NULL,
130	elements                 integer         DEFAULT '25'              NOT NULL,
131	valign                   integer         DEFAULT '0'               NOT NULL,
132	halign                   integer         DEFAULT '0'               NOT NULL,
133	style                    integer         DEFAULT '0'               NOT NULL,
134	url                      varchar(255)    DEFAULT ''                NOT NULL,
135	dynamic                  integer         DEFAULT '0'               NOT NULL,
136	sort_triggers            integer         DEFAULT '0'               NOT NULL,
137	application              varchar(255)    DEFAULT ''                NOT NULL,
138	max_columns              integer         DEFAULT '3'               NOT NULL,
139	PRIMARY KEY (screenitemid)
140);
141CREATE INDEX screens_items_1 ON screens_items (screenid);
142CREATE TABLE screen_user (
143	screenuserid             bigint                                    NOT NULL,
144	screenid                 bigint                                    NOT NULL,
145	userid                   bigint                                    NOT NULL,
146	permission               integer         DEFAULT '2'               NOT NULL,
147	PRIMARY KEY (screenuserid)
148);
149CREATE UNIQUE INDEX screen_user_1 ON screen_user (screenid,userid);
150CREATE TABLE screen_usrgrp (
151	screenusrgrpid           bigint                                    NOT NULL,
152	screenid                 bigint                                    NOT NULL,
153	usrgrpid                 bigint                                    NOT NULL,
154	permission               integer         DEFAULT '2'               NOT NULL,
155	PRIMARY KEY (screenusrgrpid)
156);
157CREATE UNIQUE INDEX screen_usrgrp_1 ON screen_usrgrp (screenid,usrgrpid);
158CREATE TABLE slideshows (
159	slideshowid              bigint                                    NOT NULL,
160	name                     varchar(255)    DEFAULT ''                NOT NULL,
161	delay                    varchar(32)     DEFAULT '30s'             NOT NULL,
162	userid                   bigint                                    NOT NULL,
163	private                  integer         DEFAULT '1'               NOT NULL,
164	PRIMARY KEY (slideshowid)
165);
166CREATE UNIQUE INDEX slideshows_1 ON slideshows (name);
167CREATE TABLE slideshow_user (
168	slideshowuserid          bigint                                    NOT NULL,
169	slideshowid              bigint                                    NOT NULL,
170	userid                   bigint                                    NOT NULL,
171	permission               integer         DEFAULT '2'               NOT NULL,
172	PRIMARY KEY (slideshowuserid)
173);
174CREATE UNIQUE INDEX slideshow_user_1 ON slideshow_user (slideshowid,userid);
175CREATE TABLE slideshow_usrgrp (
176	slideshowusrgrpid        bigint                                    NOT NULL,
177	slideshowid              bigint                                    NOT NULL,
178	usrgrpid                 bigint                                    NOT NULL,
179	permission               integer         DEFAULT '2'               NOT NULL,
180	PRIMARY KEY (slideshowusrgrpid)
181);
182CREATE UNIQUE INDEX slideshow_usrgrp_1 ON slideshow_usrgrp (slideshowid,usrgrpid);
183CREATE TABLE slides (
184	slideid                  bigint                                    NOT NULL,
185	slideshowid              bigint                                    NOT NULL,
186	screenid                 bigint                                    NOT NULL,
187	step                     integer         DEFAULT '0'               NOT NULL,
188	delay                    varchar(32)     DEFAULT '0'               NOT NULL,
189	PRIMARY KEY (slideid)
190);
191CREATE INDEX slides_1 ON slides (slideshowid);
192CREATE INDEX slides_2 ON slides (screenid);
193CREATE TABLE drules (
194	druleid                  bigint                                    NOT NULL,
195	proxy_hostid             bigint                                    NULL,
196	name                     varchar(255)    DEFAULT ''                NOT NULL,
197	iprange                  varchar(2048)   DEFAULT ''                NOT NULL,
198	delay                    varchar(255)    DEFAULT '1h'              NOT NULL,
199	nextcheck                integer         DEFAULT '0'               NOT NULL,
200	status                   integer         DEFAULT '0'               NOT NULL,
201	PRIMARY KEY (druleid)
202);
203CREATE INDEX drules_1 ON drules (proxy_hostid);
204CREATE UNIQUE INDEX drules_2 ON drules (name);
205CREATE TABLE dchecks (
206	dcheckid                 bigint                                    NOT NULL,
207	druleid                  bigint                                    NOT NULL,
208	type                     integer         DEFAULT '0'               NOT NULL,
209	key_                     varchar(2048)   DEFAULT ''                NOT NULL,
210	snmp_community           varchar(255)    DEFAULT ''                NOT NULL,
211	ports                    varchar(255)    DEFAULT '0'               NOT NULL,
212	snmpv3_securityname      varchar(64)     DEFAULT ''                NOT NULL,
213	snmpv3_securitylevel     integer         DEFAULT '0'               NOT NULL,
214	snmpv3_authpassphrase    varchar(64)     DEFAULT ''                NOT NULL,
215	snmpv3_privpassphrase    varchar(64)     DEFAULT ''                NOT NULL,
216	uniq                     integer         DEFAULT '0'               NOT NULL,
217	snmpv3_authprotocol      integer         DEFAULT '0'               NOT NULL,
218	snmpv3_privprotocol      integer         DEFAULT '0'               NOT NULL,
219	snmpv3_contextname       varchar(255)    DEFAULT ''                NOT NULL,
220	host_source              integer         DEFAULT '1'               NOT NULL,
221	name_source              integer         DEFAULT '0'               NOT NULL,
222	PRIMARY KEY (dcheckid)
223);
224CREATE INDEX dchecks_1 ON dchecks (druleid,host_source,name_source);
225CREATE TABLE applications (
226	applicationid            bigint                                    NOT NULL,
227	hostid                   bigint                                    NOT NULL,
228	name                     varchar(255)    DEFAULT ''                NOT NULL,
229	flags                    integer         DEFAULT '0'               NOT NULL,
230	PRIMARY KEY (applicationid)
231);
232CREATE UNIQUE INDEX applications_2 ON applications (hostid,name);
233CREATE TABLE httptest (
234	httptestid               bigint                                    NOT NULL,
235	name                     varchar(64)     DEFAULT ''                NOT NULL,
236	applicationid            bigint                                    NULL,
237	nextcheck                integer         DEFAULT '0'               NOT NULL,
238	delay                    varchar(255)    DEFAULT '1m'              NOT NULL,
239	status                   integer         DEFAULT '0'               NOT NULL,
240	agent                    varchar(255)    DEFAULT 'Zabbix'          NOT NULL,
241	authentication           integer         DEFAULT '0'               NOT NULL,
242	http_user                varchar(64)     DEFAULT ''                NOT NULL,
243	http_password            varchar(64)     DEFAULT ''                NOT NULL,
244	hostid                   bigint                                    NOT NULL,
245	templateid               bigint                                    NULL,
246	http_proxy               varchar(255)    DEFAULT ''                NOT NULL,
247	retries                  integer         DEFAULT '1'               NOT NULL,
248	ssl_cert_file            varchar(255)    DEFAULT ''                NOT NULL,
249	ssl_key_file             varchar(255)    DEFAULT ''                NOT NULL,
250	ssl_key_password         varchar(64)     DEFAULT ''                NOT NULL,
251	verify_peer              integer         DEFAULT '0'               NOT NULL,
252	verify_host              integer         DEFAULT '0'               NOT NULL,
253	PRIMARY KEY (httptestid)
254);
255CREATE INDEX httptest_1 ON httptest (applicationid);
256CREATE UNIQUE INDEX httptest_2 ON httptest (hostid,name);
257CREATE INDEX httptest_3 ON httptest (status);
258CREATE INDEX httptest_4 ON httptest (templateid);
259CREATE TABLE httpstep (
260	httpstepid               bigint                                    NOT NULL,
261	httptestid               bigint                                    NOT NULL,
262	name                     varchar(64)     DEFAULT ''                NOT NULL,
263	no                       integer         DEFAULT '0'               NOT NULL,
264	url                      varchar(2048)   DEFAULT ''                NOT NULL,
265	timeout                  varchar(255)    DEFAULT '15s'             NOT NULL,
266	posts                    text            DEFAULT ''                NOT NULL,
267	required                 varchar(255)    DEFAULT ''                NOT NULL,
268	status_codes             varchar(255)    DEFAULT ''                NOT NULL,
269	follow_redirects         integer         DEFAULT '1'               NOT NULL,
270	retrieve_mode            integer         DEFAULT '0'               NOT NULL,
271	post_type                integer         DEFAULT '0'               NOT NULL,
272	PRIMARY KEY (httpstepid)
273);
274CREATE INDEX httpstep_1 ON httpstep (httptestid);
275CREATE TABLE interface (
276	interfaceid              bigint                                    NOT NULL,
277	hostid                   bigint                                    NOT NULL,
278	main                     integer         DEFAULT '0'               NOT NULL,
279	type                     integer         DEFAULT '1'               NOT NULL,
280	useip                    integer         DEFAULT '1'               NOT NULL,
281	ip                       varchar(64)     DEFAULT '127.0.0.1'       NOT NULL,
282	dns                      varchar(255)    DEFAULT ''                NOT NULL,
283	port                     varchar(64)     DEFAULT '10050'           NOT NULL,
284	PRIMARY KEY (interfaceid)
285);
286CREATE INDEX interface_1 ON interface (hostid,type);
287CREATE INDEX interface_2 ON interface (ip,dns);
288CREATE TABLE valuemaps (
289	valuemapid               bigint                                    NOT NULL,
290	name                     varchar(64)     DEFAULT ''                NOT NULL,
291	PRIMARY KEY (valuemapid)
292);
293CREATE UNIQUE INDEX valuemaps_1 ON valuemaps (name);
294CREATE TABLE items (
295	itemid                   bigint                                    NOT NULL,
296	type                     integer         DEFAULT '0'               NOT NULL,
297	snmp_oid                 varchar(512)    DEFAULT ''                NOT NULL,
298	hostid                   bigint                                    NOT NULL,
299	name                     varchar(255)    DEFAULT ''                NOT NULL,
300	key_                     varchar(2048)   DEFAULT ''                NOT NULL,
301	delay                    varchar(1024)   DEFAULT '0'               NOT NULL,
302	history                  varchar(255)    DEFAULT '90d'             NOT NULL,
303	trends                   varchar(255)    DEFAULT '365d'            NOT NULL,
304	status                   integer         DEFAULT '0'               NOT NULL,
305	value_type               integer         DEFAULT '0'               NOT NULL,
306	trapper_hosts            varchar(255)    DEFAULT ''                NOT NULL,
307	units                    varchar(255)    DEFAULT ''                NOT NULL,
308	formula                  varchar(255)    DEFAULT ''                NOT NULL,
309	logtimefmt               varchar(64)     DEFAULT ''                NOT NULL,
310	templateid               bigint                                    NULL,
311	valuemapid               bigint                                    NULL,
312	params                   text            DEFAULT ''                NOT NULL,
313	ipmi_sensor              varchar(128)    DEFAULT ''                NOT NULL,
314	authtype                 integer         DEFAULT '0'               NOT NULL,
315	username                 varchar(64)     DEFAULT ''                NOT NULL,
316	password                 varchar(64)     DEFAULT ''                NOT NULL,
317	publickey                varchar(64)     DEFAULT ''                NOT NULL,
318	privatekey               varchar(64)     DEFAULT ''                NOT NULL,
319	flags                    integer         DEFAULT '0'               NOT NULL,
320	interfaceid              bigint                                    NULL,
321	description              text            DEFAULT ''                NOT NULL,
322	inventory_link           integer         DEFAULT '0'               NOT NULL,
323	lifetime                 varchar(255)    DEFAULT '30d'             NOT NULL,
324	evaltype                 integer         DEFAULT '0'               NOT NULL,
325	jmx_endpoint             varchar(255)    DEFAULT ''                NOT NULL,
326	master_itemid            bigint                                    NULL,
327	timeout                  varchar(255)    DEFAULT '3s'              NOT NULL,
328	url                      varchar(2048)   DEFAULT ''                NOT NULL,
329	query_fields             varchar(2048)   DEFAULT ''                NOT NULL,
330	posts                    text            DEFAULT ''                NOT NULL,
331	status_codes             varchar(255)    DEFAULT '200'             NOT NULL,
332	follow_redirects         integer         DEFAULT '1'               NOT NULL,
333	post_type                integer         DEFAULT '0'               NOT NULL,
334	http_proxy               varchar(255)    DEFAULT ''                NOT NULL,
335	headers                  text            DEFAULT ''                NOT NULL,
336	retrieve_mode            integer         DEFAULT '0'               NOT NULL,
337	request_method           integer         DEFAULT '0'               NOT NULL,
338	output_format            integer         DEFAULT '0'               NOT NULL,
339	ssl_cert_file            varchar(255)    DEFAULT ''                NOT NULL,
340	ssl_key_file             varchar(255)    DEFAULT ''                NOT NULL,
341	ssl_key_password         varchar(64)     DEFAULT ''                NOT NULL,
342	verify_peer              integer         DEFAULT '0'               NOT NULL,
343	verify_host              integer         DEFAULT '0'               NOT NULL,
344	allow_traps              integer         DEFAULT '0'               NOT NULL,
345	discover                 integer         DEFAULT '0'               NOT NULL,
346	PRIMARY KEY (itemid)
347);
348CREATE INDEX items_1 ON items (hostid,key_);
349CREATE INDEX items_3 ON items (status);
350CREATE INDEX items_4 ON items (templateid);
351CREATE INDEX items_5 ON items (valuemapid);
352CREATE INDEX items_6 ON items (interfaceid);
353CREATE INDEX items_7 ON items (master_itemid);
354CREATE TABLE httpstepitem (
355	httpstepitemid           bigint                                    NOT NULL,
356	httpstepid               bigint                                    NOT NULL,
357	itemid                   bigint                                    NOT NULL,
358	type                     integer         DEFAULT '0'               NOT NULL,
359	PRIMARY KEY (httpstepitemid)
360);
361CREATE UNIQUE INDEX httpstepitem_1 ON httpstepitem (httpstepid,itemid);
362CREATE INDEX httpstepitem_2 ON httpstepitem (itemid);
363CREATE TABLE httptestitem (
364	httptestitemid           bigint                                    NOT NULL,
365	httptestid               bigint                                    NOT NULL,
366	itemid                   bigint                                    NOT NULL,
367	type                     integer         DEFAULT '0'               NOT NULL,
368	PRIMARY KEY (httptestitemid)
369);
370CREATE UNIQUE INDEX httptestitem_1 ON httptestitem (httptestid,itemid);
371CREATE INDEX httptestitem_2 ON httptestitem (itemid);
372CREATE TABLE media_type (
373	mediatypeid              bigint                                    NOT NULL,
374	type                     integer         DEFAULT '0'               NOT NULL,
375	name                     varchar(100)    DEFAULT ''                NOT NULL,
376	smtp_server              varchar(255)    DEFAULT ''                NOT NULL,
377	smtp_helo                varchar(255)    DEFAULT ''                NOT NULL,
378	smtp_email               varchar(255)    DEFAULT ''                NOT NULL,
379	exec_path                varchar(255)    DEFAULT ''                NOT NULL,
380	gsm_modem                varchar(255)    DEFAULT ''                NOT NULL,
381	username                 varchar(255)    DEFAULT ''                NOT NULL,
382	passwd                   varchar(255)    DEFAULT ''                NOT NULL,
383	status                   integer         DEFAULT '0'               NOT NULL,
384	smtp_port                integer         DEFAULT '25'              NOT NULL,
385	smtp_security            integer         DEFAULT '0'               NOT NULL,
386	smtp_verify_peer         integer         DEFAULT '0'               NOT NULL,
387	smtp_verify_host         integer         DEFAULT '0'               NOT NULL,
388	smtp_authentication      integer         DEFAULT '0'               NOT NULL,
389	exec_params              varchar(255)    DEFAULT ''                NOT NULL,
390	maxsessions              integer         DEFAULT '1'               NOT NULL,
391	maxattempts              integer         DEFAULT '3'               NOT NULL,
392	attempt_interval         varchar(32)     DEFAULT '10s'             NOT NULL,
393	content_type             integer         DEFAULT '1'               NOT NULL,
394	script                   text            DEFAULT ''                NOT NULL,
395	timeout                  varchar(32)     DEFAULT '30s'             NOT NULL,
396	process_tags             integer         DEFAULT '0'               NOT NULL,
397	show_event_menu          integer         DEFAULT '0'               NOT NULL,
398	event_menu_url           varchar(2048)   DEFAULT ''                NOT NULL,
399	event_menu_name          varchar(255)    DEFAULT ''                NOT NULL,
400	description              text            DEFAULT ''                NOT NULL,
401	PRIMARY KEY (mediatypeid)
402);
403CREATE UNIQUE INDEX media_type_1 ON media_type (name);
404CREATE TABLE media_type_param (
405	mediatype_paramid        bigint                                    NOT NULL,
406	mediatypeid              bigint                                    NOT NULL,
407	name                     varchar(255)    DEFAULT ''                NOT NULL,
408	value                    varchar(2048)   DEFAULT ''                NOT NULL,
409	PRIMARY KEY (mediatype_paramid)
410);
411CREATE INDEX media_type_param_1 ON media_type_param (mediatypeid);
412CREATE TABLE media_type_message (
413	mediatype_messageid      bigint                                    NOT NULL,
414	mediatypeid              bigint                                    NOT NULL,
415	eventsource              integer                                   NOT NULL,
416	recovery                 integer                                   NOT NULL,
417	subject                  varchar(255)    DEFAULT ''                NOT NULL,
418	message                  text            DEFAULT ''                NOT NULL,
419	PRIMARY KEY (mediatype_messageid)
420);
421CREATE UNIQUE INDEX media_type_message_1 ON media_type_message (mediatypeid,eventsource,recovery);
422CREATE TABLE usrgrp (
423	usrgrpid                 bigint                                    NOT NULL,
424	name                     varchar(64)     DEFAULT ''                NOT NULL,
425	gui_access               integer         DEFAULT '0'               NOT NULL,
426	users_status             integer         DEFAULT '0'               NOT NULL,
427	debug_mode               integer         DEFAULT '0'               NOT NULL,
428	PRIMARY KEY (usrgrpid)
429);
430CREATE UNIQUE INDEX usrgrp_1 ON usrgrp (name);
431CREATE TABLE users_groups (
432	id                       bigint                                    NOT NULL,
433	usrgrpid                 bigint                                    NOT NULL,
434	userid                   bigint                                    NOT NULL,
435	PRIMARY KEY (id)
436);
437CREATE UNIQUE INDEX users_groups_1 ON users_groups (usrgrpid,userid);
438CREATE INDEX users_groups_2 ON users_groups (userid);
439CREATE TABLE scripts (
440	scriptid                 bigint                                    NOT NULL,
441	name                     varchar(255)    DEFAULT ''                NOT NULL,
442	command                  varchar(255)    DEFAULT ''                NOT NULL,
443	host_access              integer         DEFAULT '2'               NOT NULL,
444	usrgrpid                 bigint                                    NULL,
445	groupid                  bigint                                    NULL,
446	description              text            DEFAULT ''                NOT NULL,
447	confirmation             varchar(255)    DEFAULT ''                NOT NULL,
448	type                     integer         DEFAULT '0'               NOT NULL,
449	execute_on               integer         DEFAULT '2'               NOT NULL,
450	PRIMARY KEY (scriptid)
451);
452CREATE INDEX scripts_1 ON scripts (usrgrpid);
453CREATE INDEX scripts_2 ON scripts (groupid);
454CREATE UNIQUE INDEX scripts_3 ON scripts (name);
455CREATE TABLE actions (
456	actionid                 bigint                                    NOT NULL,
457	name                     varchar(255)    DEFAULT ''                NOT NULL,
458	eventsource              integer         DEFAULT '0'               NOT NULL,
459	evaltype                 integer         DEFAULT '0'               NOT NULL,
460	status                   integer         DEFAULT '0'               NOT NULL,
461	esc_period               varchar(255)    DEFAULT '1h'              NOT NULL,
462	formula                  varchar(255)    DEFAULT ''                NOT NULL,
463	pause_suppressed         integer         DEFAULT '1'               NOT NULL,
464	PRIMARY KEY (actionid)
465);
466CREATE INDEX actions_1 ON actions (eventsource,status);
467CREATE UNIQUE INDEX actions_2 ON actions (name);
468CREATE TABLE operations (
469	operationid              bigint                                    NOT NULL,
470	actionid                 bigint                                    NOT NULL,
471	operationtype            integer         DEFAULT '0'               NOT NULL,
472	esc_period               varchar(255)    DEFAULT '0'               NOT NULL,
473	esc_step_from            integer         DEFAULT '1'               NOT NULL,
474	esc_step_to              integer         DEFAULT '1'               NOT NULL,
475	evaltype                 integer         DEFAULT '0'               NOT NULL,
476	recovery                 integer         DEFAULT '0'               NOT NULL,
477	PRIMARY KEY (operationid)
478);
479CREATE INDEX operations_1 ON operations (actionid);
480CREATE TABLE opmessage (
481	operationid              bigint                                    NOT NULL,
482	default_msg              integer         DEFAULT '1'               NOT NULL,
483	subject                  varchar(255)    DEFAULT ''                NOT NULL,
484	message                  text            DEFAULT ''                NOT NULL,
485	mediatypeid              bigint                                    NULL,
486	PRIMARY KEY (operationid)
487);
488CREATE INDEX opmessage_1 ON opmessage (mediatypeid);
489CREATE TABLE opmessage_grp (
490	opmessage_grpid          bigint                                    NOT NULL,
491	operationid              bigint                                    NOT NULL,
492	usrgrpid                 bigint                                    NOT NULL,
493	PRIMARY KEY (opmessage_grpid)
494);
495CREATE UNIQUE INDEX opmessage_grp_1 ON opmessage_grp (operationid,usrgrpid);
496CREATE INDEX opmessage_grp_2 ON opmessage_grp (usrgrpid);
497CREATE TABLE opmessage_usr (
498	opmessage_usrid          bigint                                    NOT NULL,
499	operationid              bigint                                    NOT NULL,
500	userid                   bigint                                    NOT NULL,
501	PRIMARY KEY (opmessage_usrid)
502);
503CREATE UNIQUE INDEX opmessage_usr_1 ON opmessage_usr (operationid,userid);
504CREATE INDEX opmessage_usr_2 ON opmessage_usr (userid);
505CREATE TABLE opcommand (
506	operationid              bigint                                    NOT NULL,
507	type                     integer         DEFAULT '0'               NOT NULL,
508	scriptid                 bigint                                    NULL,
509	execute_on               integer         DEFAULT '0'               NOT NULL,
510	port                     varchar(64)     DEFAULT ''                NOT NULL,
511	authtype                 integer         DEFAULT '0'               NOT NULL,
512	username                 varchar(64)     DEFAULT ''                NOT NULL,
513	password                 varchar(64)     DEFAULT ''                NOT NULL,
514	publickey                varchar(64)     DEFAULT ''                NOT NULL,
515	privatekey               varchar(64)     DEFAULT ''                NOT NULL,
516	command                  text            DEFAULT ''                NOT NULL,
517	PRIMARY KEY (operationid)
518);
519CREATE INDEX opcommand_1 ON opcommand (scriptid);
520CREATE TABLE opcommand_hst (
521	opcommand_hstid          bigint                                    NOT NULL,
522	operationid              bigint                                    NOT NULL,
523	hostid                   bigint                                    NULL,
524	PRIMARY KEY (opcommand_hstid)
525);
526CREATE INDEX opcommand_hst_1 ON opcommand_hst (operationid);
527CREATE INDEX opcommand_hst_2 ON opcommand_hst (hostid);
528CREATE TABLE opcommand_grp (
529	opcommand_grpid          bigint                                    NOT NULL,
530	operationid              bigint                                    NOT NULL,
531	groupid                  bigint                                    NOT NULL,
532	PRIMARY KEY (opcommand_grpid)
533);
534CREATE INDEX opcommand_grp_1 ON opcommand_grp (operationid);
535CREATE INDEX opcommand_grp_2 ON opcommand_grp (groupid);
536CREATE TABLE opgroup (
537	opgroupid                bigint                                    NOT NULL,
538	operationid              bigint                                    NOT NULL,
539	groupid                  bigint                                    NOT NULL,
540	PRIMARY KEY (opgroupid)
541);
542CREATE UNIQUE INDEX opgroup_1 ON opgroup (operationid,groupid);
543CREATE INDEX opgroup_2 ON opgroup (groupid);
544CREATE TABLE optemplate (
545	optemplateid             bigint                                    NOT NULL,
546	operationid              bigint                                    NOT NULL,
547	templateid               bigint                                    NOT NULL,
548	PRIMARY KEY (optemplateid)
549);
550CREATE UNIQUE INDEX optemplate_1 ON optemplate (operationid,templateid);
551CREATE INDEX optemplate_2 ON optemplate (templateid);
552CREATE TABLE opconditions (
553	opconditionid            bigint                                    NOT NULL,
554	operationid              bigint                                    NOT NULL,
555	conditiontype            integer         DEFAULT '0'               NOT NULL,
556	operator                 integer         DEFAULT '0'               NOT NULL,
557	value                    varchar(255)    DEFAULT ''                NOT NULL,
558	PRIMARY KEY (opconditionid)
559);
560CREATE INDEX opconditions_1 ON opconditions (operationid);
561CREATE TABLE conditions (
562	conditionid              bigint                                    NOT NULL,
563	actionid                 bigint                                    NOT NULL,
564	conditiontype            integer         DEFAULT '0'               NOT NULL,
565	operator                 integer         DEFAULT '0'               NOT NULL,
566	value                    varchar(255)    DEFAULT ''                NOT NULL,
567	value2                   varchar(255)    DEFAULT ''                NOT NULL,
568	PRIMARY KEY (conditionid)
569);
570CREATE INDEX conditions_1 ON conditions (actionid);
571CREATE TABLE config (
572	configid                 bigint                                    NOT NULL,
573	refresh_unsupported      varchar(32)     DEFAULT '10m'             NOT NULL,
574	work_period              varchar(255)    DEFAULT '1-5,09:00-18:00' NOT NULL,
575	alert_usrgrpid           bigint                                    NULL,
576	default_theme            varchar(128)    DEFAULT 'blue-theme'      NOT NULL,
577	authentication_type      integer         DEFAULT '0'               NOT NULL,
578	ldap_host                varchar(255)    DEFAULT ''                NOT NULL,
579	ldap_port                integer         DEFAULT 389               NOT NULL,
580	ldap_base_dn             varchar(255)    DEFAULT ''                NOT NULL,
581	ldap_bind_dn             varchar(255)    DEFAULT ''                NOT NULL,
582	ldap_bind_password       varchar(128)    DEFAULT ''                NOT NULL,
583	ldap_search_attribute    varchar(128)    DEFAULT ''                NOT NULL,
584	discovery_groupid        bigint                                    NOT NULL,
585	max_in_table             integer         DEFAULT '50'              NOT NULL,
586	search_limit             integer         DEFAULT '1000'            NOT NULL,
587	severity_color_0         varchar(6)      DEFAULT '97AAB3'          NOT NULL,
588	severity_color_1         varchar(6)      DEFAULT '7499FF'          NOT NULL,
589	severity_color_2         varchar(6)      DEFAULT 'FFC859'          NOT NULL,
590	severity_color_3         varchar(6)      DEFAULT 'FFA059'          NOT NULL,
591	severity_color_4         varchar(6)      DEFAULT 'E97659'          NOT NULL,
592	severity_color_5         varchar(6)      DEFAULT 'E45959'          NOT NULL,
593	severity_name_0          varchar(32)     DEFAULT 'Not classified'  NOT NULL,
594	severity_name_1          varchar(32)     DEFAULT 'Information'     NOT NULL,
595	severity_name_2          varchar(32)     DEFAULT 'Warning'         NOT NULL,
596	severity_name_3          varchar(32)     DEFAULT 'Average'         NOT NULL,
597	severity_name_4          varchar(32)     DEFAULT 'High'            NOT NULL,
598	severity_name_5          varchar(32)     DEFAULT 'Disaster'        NOT NULL,
599	ok_period                varchar(32)     DEFAULT '5m'              NOT NULL,
600	blink_period             varchar(32)     DEFAULT '2m'              NOT NULL,
601	problem_unack_color      varchar(6)      DEFAULT 'CC0000'          NOT NULL,
602	problem_ack_color        varchar(6)      DEFAULT 'CC0000'          NOT NULL,
603	ok_unack_color           varchar(6)      DEFAULT '009900'          NOT NULL,
604	ok_ack_color             varchar(6)      DEFAULT '009900'          NOT NULL,
605	problem_unack_style      integer         DEFAULT '1'               NOT NULL,
606	problem_ack_style        integer         DEFAULT '1'               NOT NULL,
607	ok_unack_style           integer         DEFAULT '1'               NOT NULL,
608	ok_ack_style             integer         DEFAULT '1'               NOT NULL,
609	snmptrap_logging         integer         DEFAULT '1'               NOT NULL,
610	server_check_interval    integer         DEFAULT '10'              NOT NULL,
611	hk_events_mode           integer         DEFAULT '1'               NOT NULL,
612	hk_events_trigger        varchar(32)     DEFAULT '365d'            NOT NULL,
613	hk_events_internal       varchar(32)     DEFAULT '1d'              NOT NULL,
614	hk_events_discovery      varchar(32)     DEFAULT '1d'              NOT NULL,
615	hk_events_autoreg        varchar(32)     DEFAULT '1d'              NOT NULL,
616	hk_services_mode         integer         DEFAULT '1'               NOT NULL,
617	hk_services              varchar(32)     DEFAULT '365d'            NOT NULL,
618	hk_audit_mode            integer         DEFAULT '1'               NOT NULL,
619	hk_audit                 varchar(32)     DEFAULT '365d'            NOT NULL,
620	hk_sessions_mode         integer         DEFAULT '1'               NOT NULL,
621	hk_sessions              varchar(32)     DEFAULT '365d'            NOT NULL,
622	hk_history_mode          integer         DEFAULT '1'               NOT NULL,
623	hk_history_global        integer         DEFAULT '0'               NOT NULL,
624	hk_history               varchar(32)     DEFAULT '90d'             NOT NULL,
625	hk_trends_mode           integer         DEFAULT '1'               NOT NULL,
626	hk_trends_global         integer         DEFAULT '0'               NOT NULL,
627	hk_trends                varchar(32)     DEFAULT '365d'            NOT NULL,
628	default_inventory_mode   integer         DEFAULT '-1'              NOT NULL,
629	custom_color             integer         DEFAULT '0'               NOT NULL,
630	http_auth_enabled        integer         DEFAULT '0'               NOT NULL,
631	http_login_form          integer         DEFAULT '0'               NOT NULL,
632	http_strip_domains       varchar(2048)   DEFAULT ''                NOT NULL,
633	http_case_sensitive      integer         DEFAULT '1'               NOT NULL,
634	ldap_configured          integer         DEFAULT '0'               NOT NULL,
635	ldap_case_sensitive      integer         DEFAULT '1'               NOT NULL,
636	db_extension             varchar(32)     DEFAULT ''                NOT NULL,
637	autoreg_tls_accept       integer         DEFAULT '1'               NOT NULL,
638	compression_status       integer         DEFAULT '0'               NOT NULL,
639	compression_availability integer         DEFAULT '0'               NOT NULL,
640	compress_older           varchar(32)     DEFAULT '7d'              NOT NULL,
641	instanceid               varchar(32)     DEFAULT ''                NOT NULL,
642	saml_auth_enabled        integer         DEFAULT '0'               NOT NULL,
643	saml_idp_entityid        varchar(1024)   DEFAULT ''                NOT NULL,
644	saml_sso_url             varchar(2048)   DEFAULT ''                NOT NULL,
645	saml_slo_url             varchar(2048)   DEFAULT ''                NOT NULL,
646	saml_username_attribute  varchar(128)    DEFAULT ''                NOT NULL,
647	saml_sp_entityid         varchar(1024)   DEFAULT ''                NOT NULL,
648	saml_nameid_format       varchar(2048)   DEFAULT ''                NOT NULL,
649	saml_sign_messages       integer         DEFAULT '0'               NOT NULL,
650	saml_sign_assertions     integer         DEFAULT '0'               NOT NULL,
651	saml_sign_authn_requests integer         DEFAULT '0'               NOT NULL,
652	saml_sign_logout_requests integer         DEFAULT '0'               NOT NULL,
653	saml_sign_logout_responses integer         DEFAULT '0'               NOT NULL,
654	saml_encrypt_nameid      integer         DEFAULT '0'               NOT NULL,
655	saml_encrypt_assertions  integer         DEFAULT '0'               NOT NULL,
656	saml_case_sensitive      integer         DEFAULT '0'               NOT NULL,
657	PRIMARY KEY (configid)
658);
659CREATE INDEX config_1 ON config (alert_usrgrpid);
660CREATE INDEX config_2 ON config (discovery_groupid);
661CREATE TABLE triggers (
662	triggerid                bigint                                    NOT NULL,
663	expression               varchar(2048)   DEFAULT ''                NOT NULL,
664	description              varchar(255)    DEFAULT ''                NOT NULL,
665	url                      varchar(255)    DEFAULT ''                NOT NULL,
666	status                   integer         DEFAULT '0'               NOT NULL,
667	value                    integer         DEFAULT '0'               NOT NULL,
668	priority                 integer         DEFAULT '0'               NOT NULL,
669	lastchange               integer         DEFAULT '0'               NOT NULL,
670	comments                 text            DEFAULT ''                NOT NULL,
671	error                    varchar(2048)   DEFAULT ''                NOT NULL,
672	templateid               bigint                                    NULL,
673	type                     integer         DEFAULT '0'               NOT NULL,
674	state                    integer         DEFAULT '0'               NOT NULL,
675	flags                    integer         DEFAULT '0'               NOT NULL,
676	recovery_mode            integer         DEFAULT '0'               NOT NULL,
677	recovery_expression      varchar(2048)   DEFAULT ''                NOT NULL,
678	correlation_mode         integer         DEFAULT '0'               NOT NULL,
679	correlation_tag          varchar(255)    DEFAULT ''                NOT NULL,
680	manual_close             integer         DEFAULT '0'               NOT NULL,
681	opdata                   varchar(255)    DEFAULT ''                NOT NULL,
682	discover                 integer         DEFAULT '0'               NOT NULL,
683	PRIMARY KEY (triggerid)
684);
685CREATE INDEX triggers_1 ON triggers (status);
686CREATE INDEX triggers_2 ON triggers (value,lastchange);
687CREATE INDEX triggers_3 ON triggers (templateid);
688CREATE TABLE trigger_depends (
689	triggerdepid             bigint                                    NOT NULL,
690	triggerid_down           bigint                                    NOT NULL,
691	triggerid_up             bigint                                    NOT NULL,
692	PRIMARY KEY (triggerdepid)
693);
694CREATE UNIQUE INDEX trigger_depends_1 ON trigger_depends (triggerid_down,triggerid_up);
695CREATE INDEX trigger_depends_2 ON trigger_depends (triggerid_up);
696CREATE TABLE functions (
697	functionid               bigint                                    NOT NULL,
698	itemid                   bigint                                    NOT NULL,
699	triggerid                bigint                                    NOT NULL,
700	name                     varchar(12)     DEFAULT ''                NOT NULL,
701	parameter                varchar(255)    DEFAULT '0'               NOT NULL,
702	PRIMARY KEY (functionid)
703);
704CREATE INDEX functions_1 ON functions (triggerid);
705CREATE INDEX functions_2 ON functions (itemid,name,parameter);
706CREATE TABLE graphs (
707	graphid                  bigint                                    NOT NULL,
708	name                     varchar(128)    DEFAULT ''                NOT NULL,
709	width                    integer         DEFAULT '900'             NOT NULL,
710	height                   integer         DEFAULT '200'             NOT NULL,
711	yaxismin                 DOUBLE PRECISION DEFAULT '0'               NOT NULL,
712	yaxismax                 DOUBLE PRECISION DEFAULT '100'             NOT NULL,
713	templateid               bigint                                    NULL,
714	show_work_period         integer         DEFAULT '1'               NOT NULL,
715	show_triggers            integer         DEFAULT '1'               NOT NULL,
716	graphtype                integer         DEFAULT '0'               NOT NULL,
717	show_legend              integer         DEFAULT '1'               NOT NULL,
718	show_3d                  integer         DEFAULT '0'               NOT NULL,
719	percent_left             DOUBLE PRECISION DEFAULT '0'               NOT NULL,
720	percent_right            DOUBLE PRECISION DEFAULT '0'               NOT NULL,
721	ymin_type                integer         DEFAULT '0'               NOT NULL,
722	ymax_type                integer         DEFAULT '0'               NOT NULL,
723	ymin_itemid              bigint                                    NULL,
724	ymax_itemid              bigint                                    NULL,
725	flags                    integer         DEFAULT '0'               NOT NULL,
726	discover                 integer         DEFAULT '0'               NOT NULL,
727	PRIMARY KEY (graphid)
728);
729CREATE INDEX graphs_1 ON graphs (name);
730CREATE INDEX graphs_2 ON graphs (templateid);
731CREATE INDEX graphs_3 ON graphs (ymin_itemid);
732CREATE INDEX graphs_4 ON graphs (ymax_itemid);
733CREATE TABLE graphs_items (
734	gitemid                  bigint                                    NOT NULL,
735	graphid                  bigint                                    NOT NULL,
736	itemid                   bigint                                    NOT NULL,
737	drawtype                 integer         DEFAULT '0'               NOT NULL,
738	sortorder                integer         DEFAULT '0'               NOT NULL,
739	color                    varchar(6)      DEFAULT '009600'          NOT NULL,
740	yaxisside                integer         DEFAULT '0'               NOT NULL,
741	calc_fnc                 integer         DEFAULT '2'               NOT NULL,
742	type                     integer         DEFAULT '0'               NOT NULL,
743	PRIMARY KEY (gitemid)
744);
745CREATE INDEX graphs_items_1 ON graphs_items (itemid);
746CREATE INDEX graphs_items_2 ON graphs_items (graphid);
747CREATE TABLE graph_theme (
748	graphthemeid             bigint                                    NOT NULL,
749	theme                    varchar(64)     DEFAULT ''                NOT NULL,
750	backgroundcolor          varchar(6)      DEFAULT ''                NOT NULL,
751	graphcolor               varchar(6)      DEFAULT ''                NOT NULL,
752	gridcolor                varchar(6)      DEFAULT ''                NOT NULL,
753	maingridcolor            varchar(6)      DEFAULT ''                NOT NULL,
754	gridbordercolor          varchar(6)      DEFAULT ''                NOT NULL,
755	textcolor                varchar(6)      DEFAULT ''                NOT NULL,
756	highlightcolor           varchar(6)      DEFAULT ''                NOT NULL,
757	leftpercentilecolor      varchar(6)      DEFAULT ''                NOT NULL,
758	rightpercentilecolor     varchar(6)      DEFAULT ''                NOT NULL,
759	nonworktimecolor         varchar(6)      DEFAULT ''                NOT NULL,
760	colorpalette             varchar(255)    DEFAULT ''                NOT NULL,
761	PRIMARY KEY (graphthemeid)
762);
763CREATE UNIQUE INDEX graph_theme_1 ON graph_theme (theme);
764CREATE TABLE globalmacro (
765	globalmacroid            bigint                                    NOT NULL,
766	macro                    varchar(255)    DEFAULT ''                NOT NULL,
767	value                    varchar(255)    DEFAULT ''                NOT NULL,
768	description              text            DEFAULT ''                NOT NULL,
769	type                     integer         DEFAULT '0'               NOT NULL,
770	PRIMARY KEY (globalmacroid)
771);
772CREATE UNIQUE INDEX globalmacro_1 ON globalmacro (macro);
773CREATE TABLE hostmacro (
774	hostmacroid              bigint                                    NOT NULL,
775	hostid                   bigint                                    NOT NULL,
776	macro                    varchar(255)    DEFAULT ''                NOT NULL,
777	value                    varchar(255)    DEFAULT ''                NOT NULL,
778	description              text            DEFAULT ''                NOT NULL,
779	type                     integer         DEFAULT '0'               NOT NULL,
780	PRIMARY KEY (hostmacroid)
781);
782CREATE UNIQUE INDEX hostmacro_1 ON hostmacro (hostid,macro);
783CREATE TABLE hosts_groups (
784	hostgroupid              bigint                                    NOT NULL,
785	hostid                   bigint                                    NOT NULL,
786	groupid                  bigint                                    NOT NULL,
787	PRIMARY KEY (hostgroupid)
788);
789CREATE UNIQUE INDEX hosts_groups_1 ON hosts_groups (hostid,groupid);
790CREATE INDEX hosts_groups_2 ON hosts_groups (groupid);
791CREATE TABLE hosts_templates (
792	hosttemplateid           bigint                                    NOT NULL,
793	hostid                   bigint                                    NOT NULL,
794	templateid               bigint                                    NOT NULL,
795	PRIMARY KEY (hosttemplateid)
796);
797CREATE UNIQUE INDEX hosts_templates_1 ON hosts_templates (hostid,templateid);
798CREATE INDEX hosts_templates_2 ON hosts_templates (templateid);
799CREATE TABLE items_applications (
800	itemappid                bigint                                    NOT NULL,
801	applicationid            bigint                                    NOT NULL,
802	itemid                   bigint                                    NOT NULL,
803	PRIMARY KEY (itemappid)
804);
805CREATE UNIQUE INDEX items_applications_1 ON items_applications (applicationid,itemid);
806CREATE INDEX items_applications_2 ON items_applications (itemid);
807CREATE TABLE mappings (
808	mappingid                bigint                                    NOT NULL,
809	valuemapid               bigint                                    NOT NULL,
810	value                    varchar(64)     DEFAULT ''                NOT NULL,
811	newvalue                 varchar(64)     DEFAULT ''                NOT NULL,
812	PRIMARY KEY (mappingid)
813);
814CREATE INDEX mappings_1 ON mappings (valuemapid);
815CREATE TABLE media (
816	mediaid                  bigint                                    NOT NULL,
817	userid                   bigint                                    NOT NULL,
818	mediatypeid              bigint                                    NOT NULL,
819	sendto                   varchar(1024)   DEFAULT ''                NOT NULL,
820	active                   integer         DEFAULT '0'               NOT NULL,
821	severity                 integer         DEFAULT '63'              NOT NULL,
822	period                   varchar(1024)   DEFAULT '1-7,00:00-24:00' NOT NULL,
823	PRIMARY KEY (mediaid)
824);
825CREATE INDEX media_1 ON media (userid);
826CREATE INDEX media_2 ON media (mediatypeid);
827CREATE TABLE rights (
828	rightid                  bigint                                    NOT NULL,
829	groupid                  bigint                                    NOT NULL,
830	permission               integer         DEFAULT '0'               NOT NULL,
831	id                       bigint                                    NOT NULL,
832	PRIMARY KEY (rightid)
833);
834CREATE INDEX rights_1 ON rights (groupid);
835CREATE INDEX rights_2 ON rights (id);
836CREATE TABLE services (
837	serviceid                bigint                                    NOT NULL,
838	name                     varchar(128)    DEFAULT ''                NOT NULL,
839	status                   integer         DEFAULT '0'               NOT NULL,
840	algorithm                integer         DEFAULT '0'               NOT NULL,
841	triggerid                bigint                                    NULL,
842	showsla                  integer         DEFAULT '0'               NOT NULL,
843	goodsla                  DOUBLE PRECISION DEFAULT '99.9'            NOT NULL,
844	sortorder                integer         DEFAULT '0'               NOT NULL,
845	PRIMARY KEY (serviceid)
846);
847CREATE INDEX services_1 ON services (triggerid);
848CREATE TABLE services_links (
849	linkid                   bigint                                    NOT NULL,
850	serviceupid              bigint                                    NOT NULL,
851	servicedownid            bigint                                    NOT NULL,
852	soft                     integer         DEFAULT '0'               NOT NULL,
853	PRIMARY KEY (linkid)
854);
855CREATE INDEX services_links_1 ON services_links (servicedownid);
856CREATE UNIQUE INDEX services_links_2 ON services_links (serviceupid,servicedownid);
857CREATE TABLE services_times (
858	timeid                   bigint                                    NOT NULL,
859	serviceid                bigint                                    NOT NULL,
860	type                     integer         DEFAULT '0'               NOT NULL,
861	ts_from                  integer         DEFAULT '0'               NOT NULL,
862	ts_to                    integer         DEFAULT '0'               NOT NULL,
863	note                     varchar(255)    DEFAULT ''                NOT NULL,
864	PRIMARY KEY (timeid)
865);
866CREATE INDEX services_times_1 ON services_times (serviceid,type,ts_from,ts_to);
867CREATE TABLE icon_map (
868	iconmapid                bigint                                    NOT NULL,
869	name                     varchar(64)     DEFAULT ''                NOT NULL,
870	default_iconid           bigint                                    NOT NULL,
871	PRIMARY KEY (iconmapid)
872);
873CREATE UNIQUE INDEX icon_map_1 ON icon_map (name);
874CREATE INDEX icon_map_2 ON icon_map (default_iconid);
875CREATE TABLE icon_mapping (
876	iconmappingid            bigint                                    NOT NULL,
877	iconmapid                bigint                                    NOT NULL,
878	iconid                   bigint                                    NOT NULL,
879	inventory_link           integer         DEFAULT '0'               NOT NULL,
880	expression               varchar(64)     DEFAULT ''                NOT NULL,
881	sortorder                integer         DEFAULT '0'               NOT NULL,
882	PRIMARY KEY (iconmappingid)
883);
884CREATE INDEX icon_mapping_1 ON icon_mapping (iconmapid);
885CREATE INDEX icon_mapping_2 ON icon_mapping (iconid);
886CREATE TABLE sysmaps (
887	sysmapid                 bigint                                    NOT NULL,
888	name                     varchar(128)    DEFAULT ''                NOT NULL,
889	width                    integer         DEFAULT '600'             NOT NULL,
890	height                   integer         DEFAULT '400'             NOT NULL,
891	backgroundid             bigint                                    NULL,
892	label_type               integer         DEFAULT '2'               NOT NULL,
893	label_location           integer         DEFAULT '0'               NOT NULL,
894	highlight                integer         DEFAULT '1'               NOT NULL,
895	expandproblem            integer         DEFAULT '1'               NOT NULL,
896	markelements             integer         DEFAULT '0'               NOT NULL,
897	show_unack               integer         DEFAULT '0'               NOT NULL,
898	grid_size                integer         DEFAULT '50'              NOT NULL,
899	grid_show                integer         DEFAULT '1'               NOT NULL,
900	grid_align               integer         DEFAULT '1'               NOT NULL,
901	label_format             integer         DEFAULT '0'               NOT NULL,
902	label_type_host          integer         DEFAULT '2'               NOT NULL,
903	label_type_hostgroup     integer         DEFAULT '2'               NOT NULL,
904	label_type_trigger       integer         DEFAULT '2'               NOT NULL,
905	label_type_map           integer         DEFAULT '2'               NOT NULL,
906	label_type_image         integer         DEFAULT '2'               NOT NULL,
907	label_string_host        varchar(255)    DEFAULT ''                NOT NULL,
908	label_string_hostgroup   varchar(255)    DEFAULT ''                NOT NULL,
909	label_string_trigger     varchar(255)    DEFAULT ''                NOT NULL,
910	label_string_map         varchar(255)    DEFAULT ''                NOT NULL,
911	label_string_image       varchar(255)    DEFAULT ''                NOT NULL,
912	iconmapid                bigint                                    NULL,
913	expand_macros            integer         DEFAULT '0'               NOT NULL,
914	severity_min             integer         DEFAULT '0'               NOT NULL,
915	userid                   bigint                                    NOT NULL,
916	private                  integer         DEFAULT '1'               NOT NULL,
917	show_suppressed          integer         DEFAULT '0'               NOT NULL,
918	PRIMARY KEY (sysmapid)
919);
920CREATE UNIQUE INDEX sysmaps_1 ON sysmaps (name);
921CREATE INDEX sysmaps_2 ON sysmaps (backgroundid);
922CREATE INDEX sysmaps_3 ON sysmaps (iconmapid);
923CREATE TABLE sysmaps_elements (
924	selementid               bigint                                    NOT NULL,
925	sysmapid                 bigint                                    NOT NULL,
926	elementid                bigint          DEFAULT '0'               NOT NULL,
927	elementtype              integer         DEFAULT '0'               NOT NULL,
928	iconid_off               bigint                                    NULL,
929	iconid_on                bigint                                    NULL,
930	label                    varchar(2048)   DEFAULT ''                NOT NULL,
931	label_location           integer         DEFAULT '-1'              NOT NULL,
932	x                        integer         DEFAULT '0'               NOT NULL,
933	y                        integer         DEFAULT '0'               NOT NULL,
934	iconid_disabled          bigint                                    NULL,
935	iconid_maintenance       bigint                                    NULL,
936	elementsubtype           integer         DEFAULT '0'               NOT NULL,
937	areatype                 integer         DEFAULT '0'               NOT NULL,
938	width                    integer         DEFAULT '200'             NOT NULL,
939	height                   integer         DEFAULT '200'             NOT NULL,
940	viewtype                 integer         DEFAULT '0'               NOT NULL,
941	use_iconmap              integer         DEFAULT '1'               NOT NULL,
942	application              varchar(255)    DEFAULT ''                NOT NULL,
943	PRIMARY KEY (selementid)
944);
945CREATE INDEX sysmaps_elements_1 ON sysmaps_elements (sysmapid);
946CREATE INDEX sysmaps_elements_2 ON sysmaps_elements (iconid_off);
947CREATE INDEX sysmaps_elements_3 ON sysmaps_elements (iconid_on);
948CREATE INDEX sysmaps_elements_4 ON sysmaps_elements (iconid_disabled);
949CREATE INDEX sysmaps_elements_5 ON sysmaps_elements (iconid_maintenance);
950CREATE TABLE sysmaps_links (
951	linkid                   bigint                                    NOT NULL,
952	sysmapid                 bigint                                    NOT NULL,
953	selementid1              bigint                                    NOT NULL,
954	selementid2              bigint                                    NOT NULL,
955	drawtype                 integer         DEFAULT '0'               NOT NULL,
956	color                    varchar(6)      DEFAULT '000000'          NOT NULL,
957	label                    varchar(2048)   DEFAULT ''                NOT NULL,
958	PRIMARY KEY (linkid)
959);
960CREATE INDEX sysmaps_links_1 ON sysmaps_links (sysmapid);
961CREATE INDEX sysmaps_links_2 ON sysmaps_links (selementid1);
962CREATE INDEX sysmaps_links_3 ON sysmaps_links (selementid2);
963CREATE TABLE sysmaps_link_triggers (
964	linktriggerid            bigint                                    NOT NULL,
965	linkid                   bigint                                    NOT NULL,
966	triggerid                bigint                                    NOT NULL,
967	drawtype                 integer         DEFAULT '0'               NOT NULL,
968	color                    varchar(6)      DEFAULT '000000'          NOT NULL,
969	PRIMARY KEY (linktriggerid)
970);
971CREATE UNIQUE INDEX sysmaps_link_triggers_1 ON sysmaps_link_triggers (linkid,triggerid);
972CREATE INDEX sysmaps_link_triggers_2 ON sysmaps_link_triggers (triggerid);
973CREATE TABLE sysmap_element_url (
974	sysmapelementurlid       bigint                                    NOT NULL,
975	selementid               bigint                                    NOT NULL,
976	name                     varchar(255)                              NOT NULL,
977	url                      varchar(255)    DEFAULT ''                NOT NULL,
978	PRIMARY KEY (sysmapelementurlid)
979);
980CREATE UNIQUE INDEX sysmap_element_url_1 ON sysmap_element_url (selementid,name);
981CREATE TABLE sysmap_url (
982	sysmapurlid              bigint                                    NOT NULL,
983	sysmapid                 bigint                                    NOT NULL,
984	name                     varchar(255)                              NOT NULL,
985	url                      varchar(255)    DEFAULT ''                NOT NULL,
986	elementtype              integer         DEFAULT '0'               NOT NULL,
987	PRIMARY KEY (sysmapurlid)
988);
989CREATE UNIQUE INDEX sysmap_url_1 ON sysmap_url (sysmapid,name);
990CREATE TABLE sysmap_user (
991	sysmapuserid             bigint                                    NOT NULL,
992	sysmapid                 bigint                                    NOT NULL,
993	userid                   bigint                                    NOT NULL,
994	permission               integer         DEFAULT '2'               NOT NULL,
995	PRIMARY KEY (sysmapuserid)
996);
997CREATE UNIQUE INDEX sysmap_user_1 ON sysmap_user (sysmapid,userid);
998CREATE TABLE sysmap_usrgrp (
999	sysmapusrgrpid           bigint                                    NOT NULL,
1000	sysmapid                 bigint                                    NOT NULL,
1001	usrgrpid                 bigint                                    NOT NULL,
1002	permission               integer         DEFAULT '2'               NOT NULL,
1003	PRIMARY KEY (sysmapusrgrpid)
1004);
1005CREATE UNIQUE INDEX sysmap_usrgrp_1 ON sysmap_usrgrp (sysmapid,usrgrpid);
1006CREATE TABLE maintenances_hosts (
1007	maintenance_hostid       bigint                                    NOT NULL,
1008	maintenanceid            bigint                                    NOT NULL,
1009	hostid                   bigint                                    NOT NULL,
1010	PRIMARY KEY (maintenance_hostid)
1011);
1012CREATE UNIQUE INDEX maintenances_hosts_1 ON maintenances_hosts (maintenanceid,hostid);
1013CREATE INDEX maintenances_hosts_2 ON maintenances_hosts (hostid);
1014CREATE TABLE maintenances_groups (
1015	maintenance_groupid      bigint                                    NOT NULL,
1016	maintenanceid            bigint                                    NOT NULL,
1017	groupid                  bigint                                    NOT NULL,
1018	PRIMARY KEY (maintenance_groupid)
1019);
1020CREATE UNIQUE INDEX maintenances_groups_1 ON maintenances_groups (maintenanceid,groupid);
1021CREATE INDEX maintenances_groups_2 ON maintenances_groups (groupid);
1022CREATE TABLE timeperiods (
1023	timeperiodid             bigint                                    NOT NULL,
1024	timeperiod_type          integer         DEFAULT '0'               NOT NULL,
1025	every                    integer         DEFAULT '1'               NOT NULL,
1026	month                    integer         DEFAULT '0'               NOT NULL,
1027	dayofweek                integer         DEFAULT '0'               NOT NULL,
1028	day                      integer         DEFAULT '0'               NOT NULL,
1029	start_time               integer         DEFAULT '0'               NOT NULL,
1030	period                   integer         DEFAULT '0'               NOT NULL,
1031	start_date               integer         DEFAULT '0'               NOT NULL,
1032	PRIMARY KEY (timeperiodid)
1033);
1034CREATE TABLE maintenances_windows (
1035	maintenance_timeperiodid bigint                                    NOT NULL,
1036	maintenanceid            bigint                                    NOT NULL,
1037	timeperiodid             bigint                                    NOT NULL,
1038	PRIMARY KEY (maintenance_timeperiodid)
1039);
1040CREATE UNIQUE INDEX maintenances_windows_1 ON maintenances_windows (maintenanceid,timeperiodid);
1041CREATE INDEX maintenances_windows_2 ON maintenances_windows (timeperiodid);
1042CREATE TABLE regexps (
1043	regexpid                 bigint                                    NOT NULL,
1044	name                     varchar(128)    DEFAULT ''                NOT NULL,
1045	test_string              text            DEFAULT ''                NOT NULL,
1046	PRIMARY KEY (regexpid)
1047);
1048CREATE UNIQUE INDEX regexps_1 ON regexps (name);
1049CREATE TABLE expressions (
1050	expressionid             bigint                                    NOT NULL,
1051	regexpid                 bigint                                    NOT NULL,
1052	expression               varchar(255)    DEFAULT ''                NOT NULL,
1053	expression_type          integer         DEFAULT '0'               NOT NULL,
1054	exp_delimiter            varchar(1)      DEFAULT ''                NOT NULL,
1055	case_sensitive           integer         DEFAULT '0'               NOT NULL,
1056	PRIMARY KEY (expressionid)
1057);
1058CREATE INDEX expressions_1 ON expressions (regexpid);
1059CREATE TABLE ids (
1060	table_name               varchar(64)     DEFAULT ''                NOT NULL,
1061	field_name               varchar(64)     DEFAULT ''                NOT NULL,
1062	nextid                   bigint                                    NOT NULL,
1063	PRIMARY KEY (table_name,field_name)
1064);
1065CREATE TABLE alerts (
1066	alertid                  bigint                                    NOT NULL,
1067	actionid                 bigint                                    NOT NULL,
1068	eventid                  bigint                                    NOT NULL,
1069	userid                   bigint                                    NULL,
1070	clock                    integer         DEFAULT '0'               NOT NULL,
1071	mediatypeid              bigint                                    NULL,
1072	sendto                   varchar(1024)   DEFAULT ''                NOT NULL,
1073	subject                  varchar(255)    DEFAULT ''                NOT NULL,
1074	message                  text            DEFAULT ''                NOT NULL,
1075	status                   integer         DEFAULT '0'               NOT NULL,
1076	retries                  integer         DEFAULT '0'               NOT NULL,
1077	error                    varchar(2048)   DEFAULT ''                NOT NULL,
1078	esc_step                 integer         DEFAULT '0'               NOT NULL,
1079	alerttype                integer         DEFAULT '0'               NOT NULL,
1080	p_eventid                bigint                                    NULL,
1081	acknowledgeid            bigint                                    NULL,
1082	parameters               text            DEFAULT '{}'              NOT NULL,
1083	PRIMARY KEY (alertid)
1084);
1085CREATE INDEX alerts_1 ON alerts (actionid);
1086CREATE INDEX alerts_2 ON alerts (clock);
1087CREATE INDEX alerts_3 ON alerts (eventid);
1088CREATE INDEX alerts_4 ON alerts (status);
1089CREATE INDEX alerts_5 ON alerts (mediatypeid);
1090CREATE INDEX alerts_6 ON alerts (userid);
1091CREATE INDEX alerts_7 ON alerts (p_eventid);
1092CREATE INDEX alerts_8 ON alerts (acknowledgeid);
1093CREATE TABLE history (
1094	itemid                   bigint                                    NOT NULL,
1095	clock                    integer         DEFAULT '0'               NOT NULL,
1096	value                    DOUBLE PRECISION DEFAULT '0.0000'          NOT NULL,
1097	ns                       integer         DEFAULT '0'               NOT NULL
1098);
1099CREATE INDEX history_1 ON history (itemid,clock);
1100CREATE TABLE history_uint (
1101	itemid                   bigint                                    NOT NULL,
1102	clock                    integer         DEFAULT '0'               NOT NULL,
1103	value                    numeric(20)     DEFAULT '0'               NOT NULL,
1104	ns                       integer         DEFAULT '0'               NOT NULL
1105);
1106CREATE INDEX history_uint_1 ON history_uint (itemid,clock);
1107CREATE TABLE history_str (
1108	itemid                   bigint                                    NOT NULL,
1109	clock                    integer         DEFAULT '0'               NOT NULL,
1110	value                    varchar(255)    DEFAULT ''                NOT NULL,
1111	ns                       integer         DEFAULT '0'               NOT NULL
1112);
1113CREATE INDEX history_str_1 ON history_str (itemid,clock);
1114CREATE TABLE history_log (
1115	itemid                   bigint                                    NOT NULL,
1116	clock                    integer         DEFAULT '0'               NOT NULL,
1117	timestamp                integer         DEFAULT '0'               NOT NULL,
1118	source                   varchar(64)     DEFAULT ''                NOT NULL,
1119	severity                 integer         DEFAULT '0'               NOT NULL,
1120	value                    text            DEFAULT ''                NOT NULL,
1121	logeventid               integer         DEFAULT '0'               NOT NULL,
1122	ns                       integer         DEFAULT '0'               NOT NULL
1123);
1124CREATE INDEX history_log_1 ON history_log (itemid,clock);
1125CREATE TABLE history_text (
1126	itemid                   bigint                                    NOT NULL,
1127	clock                    integer         DEFAULT '0'               NOT NULL,
1128	value                    text            DEFAULT ''                NOT NULL,
1129	ns                       integer         DEFAULT '0'               NOT NULL
1130);
1131CREATE INDEX history_text_1 ON history_text (itemid,clock);
1132CREATE TABLE proxy_history (
1133	id                       bigserial                                 NOT NULL,
1134	itemid                   bigint                                    NOT NULL,
1135	clock                    integer         DEFAULT '0'               NOT NULL,
1136	timestamp                integer         DEFAULT '0'               NOT NULL,
1137	source                   varchar(64)     DEFAULT ''                NOT NULL,
1138	severity                 integer         DEFAULT '0'               NOT NULL,
1139	value                    text            DEFAULT ''                NOT NULL,
1140	logeventid               integer         DEFAULT '0'               NOT NULL,
1141	ns                       integer         DEFAULT '0'               NOT NULL,
1142	state                    integer         DEFAULT '0'               NOT NULL,
1143	lastlogsize              numeric(20)     DEFAULT '0'               NOT NULL,
1144	mtime                    integer         DEFAULT '0'               NOT NULL,
1145	flags                    integer         DEFAULT '0'               NOT NULL,
1146	write_clock              integer         DEFAULT '0'               NOT NULL,
1147	PRIMARY KEY (id)
1148);
1149CREATE INDEX proxy_history_1 ON proxy_history (clock);
1150CREATE TABLE proxy_dhistory (
1151	id                       bigserial                                 NOT NULL,
1152	clock                    integer         DEFAULT '0'               NOT NULL,
1153	druleid                  bigint                                    NOT NULL,
1154	ip                       varchar(39)     DEFAULT ''                NOT NULL,
1155	port                     integer         DEFAULT '0'               NOT NULL,
1156	value                    varchar(255)    DEFAULT ''                NOT NULL,
1157	status                   integer         DEFAULT '0'               NOT NULL,
1158	dcheckid                 bigint                                    NULL,
1159	dns                      varchar(255)    DEFAULT ''                NOT NULL,
1160	PRIMARY KEY (id)
1161);
1162CREATE INDEX proxy_dhistory_1 ON proxy_dhistory (clock);
1163CREATE INDEX proxy_dhistory_2 ON proxy_dhistory (druleid);
1164CREATE TABLE events (
1165	eventid                  bigint                                    NOT NULL,
1166	source                   integer         DEFAULT '0'               NOT NULL,
1167	object                   integer         DEFAULT '0'               NOT NULL,
1168	objectid                 bigint          DEFAULT '0'               NOT NULL,
1169	clock                    integer         DEFAULT '0'               NOT NULL,
1170	value                    integer         DEFAULT '0'               NOT NULL,
1171	acknowledged             integer         DEFAULT '0'               NOT NULL,
1172	ns                       integer         DEFAULT '0'               NOT NULL,
1173	name                     varchar(2048)   DEFAULT ''                NOT NULL,
1174	severity                 integer         DEFAULT '0'               NOT NULL,
1175	PRIMARY KEY (eventid)
1176);
1177CREATE INDEX events_1 ON events (source,object,objectid,clock);
1178CREATE INDEX events_2 ON events (source,object,clock);
1179CREATE TABLE trends (
1180	itemid                   bigint                                    NOT NULL,
1181	clock                    integer         DEFAULT '0'               NOT NULL,
1182	num                      integer         DEFAULT '0'               NOT NULL,
1183	value_min                DOUBLE PRECISION DEFAULT '0.0000'          NOT NULL,
1184	value_avg                DOUBLE PRECISION DEFAULT '0.0000'          NOT NULL,
1185	value_max                DOUBLE PRECISION DEFAULT '0.0000'          NOT NULL,
1186	PRIMARY KEY (itemid,clock)
1187);
1188CREATE TABLE trends_uint (
1189	itemid                   bigint                                    NOT NULL,
1190	clock                    integer         DEFAULT '0'               NOT NULL,
1191	num                      integer         DEFAULT '0'               NOT NULL,
1192	value_min                numeric(20)     DEFAULT '0'               NOT NULL,
1193	value_avg                numeric(20)     DEFAULT '0'               NOT NULL,
1194	value_max                numeric(20)     DEFAULT '0'               NOT NULL,
1195	PRIMARY KEY (itemid,clock)
1196);
1197CREATE TABLE acknowledges (
1198	acknowledgeid            bigint                                    NOT NULL,
1199	userid                   bigint                                    NOT NULL,
1200	eventid                  bigint                                    NOT NULL,
1201	clock                    integer         DEFAULT '0'               NOT NULL,
1202	message                  varchar(2048)   DEFAULT ''                NOT NULL,
1203	action                   integer         DEFAULT '0'               NOT NULL,
1204	old_severity             integer         DEFAULT '0'               NOT NULL,
1205	new_severity             integer         DEFAULT '0'               NOT NULL,
1206	PRIMARY KEY (acknowledgeid)
1207);
1208CREATE INDEX acknowledges_1 ON acknowledges (userid);
1209CREATE INDEX acknowledges_2 ON acknowledges (eventid);
1210CREATE INDEX acknowledges_3 ON acknowledges (clock);
1211CREATE TABLE auditlog (
1212	auditid                  bigint                                    NOT NULL,
1213	userid                   bigint                                    NOT NULL,
1214	clock                    integer         DEFAULT '0'               NOT NULL,
1215	action                   integer         DEFAULT '0'               NOT NULL,
1216	resourcetype             integer         DEFAULT '0'               NOT NULL,
1217	note                     varchar(128)    DEFAULT ''                NOT NULL,
1218	ip                       varchar(39)     DEFAULT ''                NOT NULL,
1219	resourceid               bigint                                    NULL,
1220	resourcename             varchar(255)    DEFAULT ''                NOT NULL,
1221	PRIMARY KEY (auditid)
1222);
1223CREATE INDEX auditlog_1 ON auditlog (userid,clock);
1224CREATE INDEX auditlog_2 ON auditlog (clock);
1225CREATE INDEX auditlog_3 ON auditlog (resourcetype,resourceid);
1226CREATE TABLE auditlog_details (
1227	auditdetailid            bigint                                    NOT NULL,
1228	auditid                  bigint                                    NOT NULL,
1229	table_name               varchar(64)     DEFAULT ''                NOT NULL,
1230	field_name               varchar(64)     DEFAULT ''                NOT NULL,
1231	oldvalue                 text            DEFAULT ''                NOT NULL,
1232	newvalue                 text            DEFAULT ''                NOT NULL,
1233	PRIMARY KEY (auditdetailid)
1234);
1235CREATE INDEX auditlog_details_1 ON auditlog_details (auditid);
1236CREATE TABLE service_alarms (
1237	servicealarmid           bigint                                    NOT NULL,
1238	serviceid                bigint                                    NOT NULL,
1239	clock                    integer         DEFAULT '0'               NOT NULL,
1240	value                    integer         DEFAULT '0'               NOT NULL,
1241	PRIMARY KEY (servicealarmid)
1242);
1243CREATE INDEX service_alarms_1 ON service_alarms (serviceid,clock);
1244CREATE INDEX service_alarms_2 ON service_alarms (clock);
1245CREATE TABLE autoreg_host (
1246	autoreg_hostid           bigint                                    NOT NULL,
1247	proxy_hostid             bigint                                    NULL,
1248	host                     varchar(128)    DEFAULT ''                NOT NULL,
1249	listen_ip                varchar(39)     DEFAULT ''                NOT NULL,
1250	listen_port              integer         DEFAULT '0'               NOT NULL,
1251	listen_dns               varchar(255)    DEFAULT ''                NOT NULL,
1252	host_metadata            varchar(255)    DEFAULT ''                NOT NULL,
1253	flags                    integer         DEFAULT '0'               NOT NULL,
1254	tls_accepted             integer         DEFAULT '1'               NOT NULL,
1255	PRIMARY KEY (autoreg_hostid)
1256);
1257CREATE INDEX autoreg_host_1 ON autoreg_host (host);
1258CREATE INDEX autoreg_host_2 ON autoreg_host (proxy_hostid);
1259CREATE TABLE proxy_autoreg_host (
1260	id                       bigserial                                 NOT NULL,
1261	clock                    integer         DEFAULT '0'               NOT NULL,
1262	host                     varchar(128)    DEFAULT ''                NOT NULL,
1263	listen_ip                varchar(39)     DEFAULT ''                NOT NULL,
1264	listen_port              integer         DEFAULT '0'               NOT NULL,
1265	listen_dns               varchar(255)    DEFAULT ''                NOT NULL,
1266	host_metadata            varchar(255)    DEFAULT ''                NOT NULL,
1267	flags                    integer         DEFAULT '0'               NOT NULL,
1268	tls_accepted             integer         DEFAULT '1'               NOT NULL,
1269	PRIMARY KEY (id)
1270);
1271CREATE INDEX proxy_autoreg_host_1 ON proxy_autoreg_host (clock);
1272CREATE TABLE dhosts (
1273	dhostid                  bigint                                    NOT NULL,
1274	druleid                  bigint                                    NOT NULL,
1275	status                   integer         DEFAULT '0'               NOT NULL,
1276	lastup                   integer         DEFAULT '0'               NOT NULL,
1277	lastdown                 integer         DEFAULT '0'               NOT NULL,
1278	PRIMARY KEY (dhostid)
1279);
1280CREATE INDEX dhosts_1 ON dhosts (druleid);
1281CREATE TABLE dservices (
1282	dserviceid               bigint                                    NOT NULL,
1283	dhostid                  bigint                                    NOT NULL,
1284	value                    varchar(255)    DEFAULT ''                NOT NULL,
1285	port                     integer         DEFAULT '0'               NOT NULL,
1286	status                   integer         DEFAULT '0'               NOT NULL,
1287	lastup                   integer         DEFAULT '0'               NOT NULL,
1288	lastdown                 integer         DEFAULT '0'               NOT NULL,
1289	dcheckid                 bigint                                    NOT NULL,
1290	ip                       varchar(39)     DEFAULT ''                NOT NULL,
1291	dns                      varchar(255)    DEFAULT ''                NOT NULL,
1292	PRIMARY KEY (dserviceid)
1293);
1294CREATE UNIQUE INDEX dservices_1 ON dservices (dcheckid,ip,port);
1295CREATE INDEX dservices_2 ON dservices (dhostid);
1296CREATE TABLE escalations (
1297	escalationid             bigint                                    NOT NULL,
1298	actionid                 bigint                                    NOT NULL,
1299	triggerid                bigint                                    NULL,
1300	eventid                  bigint                                    NULL,
1301	r_eventid                bigint                                    NULL,
1302	nextcheck                integer         DEFAULT '0'               NOT NULL,
1303	esc_step                 integer         DEFAULT '0'               NOT NULL,
1304	status                   integer         DEFAULT '0'               NOT NULL,
1305	itemid                   bigint                                    NULL,
1306	acknowledgeid            bigint                                    NULL,
1307	PRIMARY KEY (escalationid)
1308);
1309CREATE UNIQUE INDEX escalations_1 ON escalations (triggerid,itemid,escalationid);
1310CREATE INDEX escalations_2 ON escalations (eventid);
1311CREATE INDEX escalations_3 ON escalations (nextcheck);
1312CREATE TABLE globalvars (
1313	globalvarid              bigint                                    NOT NULL,
1314	snmp_lastsize            numeric(20)     DEFAULT '0'               NOT NULL,
1315	PRIMARY KEY (globalvarid)
1316);
1317CREATE TABLE graph_discovery (
1318	graphid                  bigint                                    NOT NULL,
1319	parent_graphid           bigint                                    NOT NULL,
1320	lastcheck                integer         DEFAULT '0'               NOT NULL,
1321	ts_delete                integer         DEFAULT '0'               NOT NULL,
1322	PRIMARY KEY (graphid)
1323);
1324CREATE INDEX graph_discovery_1 ON graph_discovery (parent_graphid);
1325CREATE TABLE host_inventory (
1326	hostid                   bigint                                    NOT NULL,
1327	inventory_mode           integer         DEFAULT '0'               NOT NULL,
1328	type                     varchar(64)     DEFAULT ''                NOT NULL,
1329	type_full                varchar(64)     DEFAULT ''                NOT NULL,
1330	name                     varchar(128)    DEFAULT ''                NOT NULL,
1331	alias                    varchar(128)    DEFAULT ''                NOT NULL,
1332	os                       varchar(128)    DEFAULT ''                NOT NULL,
1333	os_full                  varchar(255)    DEFAULT ''                NOT NULL,
1334	os_short                 varchar(128)    DEFAULT ''                NOT NULL,
1335	serialno_a               varchar(64)     DEFAULT ''                NOT NULL,
1336	serialno_b               varchar(64)     DEFAULT ''                NOT NULL,
1337	tag                      varchar(64)     DEFAULT ''                NOT NULL,
1338	asset_tag                varchar(64)     DEFAULT ''                NOT NULL,
1339	macaddress_a             varchar(64)     DEFAULT ''                NOT NULL,
1340	macaddress_b             varchar(64)     DEFAULT ''                NOT NULL,
1341	hardware                 varchar(255)    DEFAULT ''                NOT NULL,
1342	hardware_full            text            DEFAULT ''                NOT NULL,
1343	software                 varchar(255)    DEFAULT ''                NOT NULL,
1344	software_full            text            DEFAULT ''                NOT NULL,
1345	software_app_a           varchar(64)     DEFAULT ''                NOT NULL,
1346	software_app_b           varchar(64)     DEFAULT ''                NOT NULL,
1347	software_app_c           varchar(64)     DEFAULT ''                NOT NULL,
1348	software_app_d           varchar(64)     DEFAULT ''                NOT NULL,
1349	software_app_e           varchar(64)     DEFAULT ''                NOT NULL,
1350	contact                  text            DEFAULT ''                NOT NULL,
1351	location                 text            DEFAULT ''                NOT NULL,
1352	location_lat             varchar(16)     DEFAULT ''                NOT NULL,
1353	location_lon             varchar(16)     DEFAULT ''                NOT NULL,
1354	notes                    text            DEFAULT ''                NOT NULL,
1355	chassis                  varchar(64)     DEFAULT ''                NOT NULL,
1356	model                    varchar(64)     DEFAULT ''                NOT NULL,
1357	hw_arch                  varchar(32)     DEFAULT ''                NOT NULL,
1358	vendor                   varchar(64)     DEFAULT ''                NOT NULL,
1359	contract_number          varchar(64)     DEFAULT ''                NOT NULL,
1360	installer_name           varchar(64)     DEFAULT ''                NOT NULL,
1361	deployment_status        varchar(64)     DEFAULT ''                NOT NULL,
1362	url_a                    varchar(255)    DEFAULT ''                NOT NULL,
1363	url_b                    varchar(255)    DEFAULT ''                NOT NULL,
1364	url_c                    varchar(255)    DEFAULT ''                NOT NULL,
1365	host_networks            text            DEFAULT ''                NOT NULL,
1366	host_netmask             varchar(39)     DEFAULT ''                NOT NULL,
1367	host_router              varchar(39)     DEFAULT ''                NOT NULL,
1368	oob_ip                   varchar(39)     DEFAULT ''                NOT NULL,
1369	oob_netmask              varchar(39)     DEFAULT ''                NOT NULL,
1370	oob_router               varchar(39)     DEFAULT ''                NOT NULL,
1371	date_hw_purchase         varchar(64)     DEFAULT ''                NOT NULL,
1372	date_hw_install          varchar(64)     DEFAULT ''                NOT NULL,
1373	date_hw_expiry           varchar(64)     DEFAULT ''                NOT NULL,
1374	date_hw_decomm           varchar(64)     DEFAULT ''                NOT NULL,
1375	site_address_a           varchar(128)    DEFAULT ''                NOT NULL,
1376	site_address_b           varchar(128)    DEFAULT ''                NOT NULL,
1377	site_address_c           varchar(128)    DEFAULT ''                NOT NULL,
1378	site_city                varchar(128)    DEFAULT ''                NOT NULL,
1379	site_state               varchar(64)     DEFAULT ''                NOT NULL,
1380	site_country             varchar(64)     DEFAULT ''                NOT NULL,
1381	site_zip                 varchar(64)     DEFAULT ''                NOT NULL,
1382	site_rack                varchar(128)    DEFAULT ''                NOT NULL,
1383	site_notes               text            DEFAULT ''                NOT NULL,
1384	poc_1_name               varchar(128)    DEFAULT ''                NOT NULL,
1385	poc_1_email              varchar(128)    DEFAULT ''                NOT NULL,
1386	poc_1_phone_a            varchar(64)     DEFAULT ''                NOT NULL,
1387	poc_1_phone_b            varchar(64)     DEFAULT ''                NOT NULL,
1388	poc_1_cell               varchar(64)     DEFAULT ''                NOT NULL,
1389	poc_1_screen             varchar(64)     DEFAULT ''                NOT NULL,
1390	poc_1_notes              text            DEFAULT ''                NOT NULL,
1391	poc_2_name               varchar(128)    DEFAULT ''                NOT NULL,
1392	poc_2_email              varchar(128)    DEFAULT ''                NOT NULL,
1393	poc_2_phone_a            varchar(64)     DEFAULT ''                NOT NULL,
1394	poc_2_phone_b            varchar(64)     DEFAULT ''                NOT NULL,
1395	poc_2_cell               varchar(64)     DEFAULT ''                NOT NULL,
1396	poc_2_screen             varchar(64)     DEFAULT ''                NOT NULL,
1397	poc_2_notes              text            DEFAULT ''                NOT NULL,
1398	PRIMARY KEY (hostid)
1399);
1400CREATE TABLE housekeeper (
1401	housekeeperid            bigint                                    NOT NULL,
1402	tablename                varchar(64)     DEFAULT ''                NOT NULL,
1403	field                    varchar(64)     DEFAULT ''                NOT NULL,
1404	value                    bigint                                    NOT NULL,
1405	PRIMARY KEY (housekeeperid)
1406);
1407CREATE TABLE images (
1408	imageid                  bigint                                    NOT NULL,
1409	imagetype                integer         DEFAULT '0'               NOT NULL,
1410	name                     varchar(64)     DEFAULT '0'               NOT NULL,
1411	image                    bytea           DEFAULT ''                NOT NULL,
1412	PRIMARY KEY (imageid)
1413);
1414CREATE UNIQUE INDEX images_1 ON images (name);
1415CREATE TABLE item_discovery (
1416	itemdiscoveryid          bigint                                    NOT NULL,
1417	itemid                   bigint                                    NOT NULL,
1418	parent_itemid            bigint                                    NOT NULL,
1419	key_                     varchar(2048)   DEFAULT ''                NOT NULL,
1420	lastcheck                integer         DEFAULT '0'               NOT NULL,
1421	ts_delete                integer         DEFAULT '0'               NOT NULL,
1422	PRIMARY KEY (itemdiscoveryid)
1423);
1424CREATE UNIQUE INDEX item_discovery_1 ON item_discovery (itemid,parent_itemid);
1425CREATE INDEX item_discovery_2 ON item_discovery (parent_itemid);
1426CREATE TABLE host_discovery (
1427	hostid                   bigint                                    NOT NULL,
1428	parent_hostid            bigint                                    NULL,
1429	parent_itemid            bigint                                    NULL,
1430	host                     varchar(128)    DEFAULT ''                NOT NULL,
1431	lastcheck                integer         DEFAULT '0'               NOT NULL,
1432	ts_delete                integer         DEFAULT '0'               NOT NULL,
1433	PRIMARY KEY (hostid)
1434);
1435CREATE TABLE interface_discovery (
1436	interfaceid              bigint                                    NOT NULL,
1437	parent_interfaceid       bigint                                    NOT NULL,
1438	PRIMARY KEY (interfaceid)
1439);
1440CREATE TABLE profiles (
1441	profileid                bigint                                    NOT NULL,
1442	userid                   bigint                                    NOT NULL,
1443	idx                      varchar(96)     DEFAULT ''                NOT NULL,
1444	idx2                     bigint          DEFAULT '0'               NOT NULL,
1445	value_id                 bigint          DEFAULT '0'               NOT NULL,
1446	value_int                integer         DEFAULT '0'               NOT NULL,
1447	value_str                varchar(255)    DEFAULT ''                NOT NULL,
1448	source                   varchar(96)     DEFAULT ''                NOT NULL,
1449	type                     integer         DEFAULT '0'               NOT NULL,
1450	PRIMARY KEY (profileid)
1451);
1452CREATE INDEX profiles_1 ON profiles (userid,idx,idx2);
1453CREATE INDEX profiles_2 ON profiles (userid,profileid);
1454CREATE TABLE sessions (
1455	sessionid                varchar(32)     DEFAULT ''                NOT NULL,
1456	userid                   bigint                                    NOT NULL,
1457	lastaccess               integer         DEFAULT '0'               NOT NULL,
1458	status                   integer         DEFAULT '0'               NOT NULL,
1459	PRIMARY KEY (sessionid)
1460);
1461CREATE INDEX sessions_1 ON sessions (userid,status,lastaccess);
1462CREATE TABLE trigger_discovery (
1463	triggerid                bigint                                    NOT NULL,
1464	parent_triggerid         bigint                                    NOT NULL,
1465	lastcheck                integer         DEFAULT '0'               NOT NULL,
1466	ts_delete                integer         DEFAULT '0'               NOT NULL,
1467	PRIMARY KEY (triggerid)
1468);
1469CREATE INDEX trigger_discovery_1 ON trigger_discovery (parent_triggerid);
1470CREATE TABLE application_template (
1471	application_templateid   bigint                                    NOT NULL,
1472	applicationid            bigint                                    NOT NULL,
1473	templateid               bigint                                    NOT NULL,
1474	PRIMARY KEY (application_templateid)
1475);
1476CREATE UNIQUE INDEX application_template_1 ON application_template (applicationid,templateid);
1477CREATE INDEX application_template_2 ON application_template (templateid);
1478CREATE TABLE item_condition (
1479	item_conditionid         bigint                                    NOT NULL,
1480	itemid                   bigint                                    NOT NULL,
1481	operator                 integer         DEFAULT '8'               NOT NULL,
1482	macro                    varchar(64)     DEFAULT ''                NOT NULL,
1483	value                    varchar(255)    DEFAULT ''                NOT NULL,
1484	PRIMARY KEY (item_conditionid)
1485);
1486CREATE INDEX item_condition_1 ON item_condition (itemid);
1487CREATE TABLE item_rtdata (
1488	itemid                   bigint                                    NOT NULL,
1489	lastlogsize              numeric(20)     DEFAULT '0'               NOT NULL,
1490	state                    integer         DEFAULT '0'               NOT NULL,
1491	mtime                    integer         DEFAULT '0'               NOT NULL,
1492	error                    varchar(2048)   DEFAULT ''                NOT NULL,
1493	PRIMARY KEY (itemid)
1494);
1495CREATE TABLE application_prototype (
1496	application_prototypeid  bigint                                    NOT NULL,
1497	itemid                   bigint                                    NOT NULL,
1498	templateid               bigint                                    NULL,
1499	name                     varchar(255)    DEFAULT ''                NOT NULL,
1500	PRIMARY KEY (application_prototypeid)
1501);
1502CREATE INDEX application_prototype_1 ON application_prototype (itemid);
1503CREATE INDEX application_prototype_2 ON application_prototype (templateid);
1504CREATE TABLE item_application_prototype (
1505	item_application_prototypeid bigint                                    NOT NULL,
1506	application_prototypeid  bigint                                    NOT NULL,
1507	itemid                   bigint                                    NOT NULL,
1508	PRIMARY KEY (item_application_prototypeid)
1509);
1510CREATE UNIQUE INDEX item_application_prototype_1 ON item_application_prototype (application_prototypeid,itemid);
1511CREATE INDEX item_application_prototype_2 ON item_application_prototype (itemid);
1512CREATE TABLE application_discovery (
1513	application_discoveryid  bigint                                    NOT NULL,
1514	applicationid            bigint                                    NOT NULL,
1515	application_prototypeid  bigint                                    NOT NULL,
1516	name                     varchar(255)    DEFAULT ''                NOT NULL,
1517	lastcheck                integer         DEFAULT '0'               NOT NULL,
1518	ts_delete                integer         DEFAULT '0'               NOT NULL,
1519	PRIMARY KEY (application_discoveryid)
1520);
1521CREATE INDEX application_discovery_1 ON application_discovery (applicationid);
1522CREATE INDEX application_discovery_2 ON application_discovery (application_prototypeid);
1523CREATE TABLE opinventory (
1524	operationid              bigint                                    NOT NULL,
1525	inventory_mode           integer         DEFAULT '0'               NOT NULL,
1526	PRIMARY KEY (operationid)
1527);
1528CREATE TABLE trigger_tag (
1529	triggertagid             bigint                                    NOT NULL,
1530	triggerid                bigint                                    NOT NULL,
1531	tag                      varchar(255)    DEFAULT ''                NOT NULL,
1532	value                    varchar(255)    DEFAULT ''                NOT NULL,
1533	PRIMARY KEY (triggertagid)
1534);
1535CREATE INDEX trigger_tag_1 ON trigger_tag (triggerid);
1536CREATE TABLE event_tag (
1537	eventtagid               bigint                                    NOT NULL,
1538	eventid                  bigint                                    NOT NULL,
1539	tag                      varchar(255)    DEFAULT ''                NOT NULL,
1540	value                    varchar(255)    DEFAULT ''                NOT NULL,
1541	PRIMARY KEY (eventtagid)
1542);
1543CREATE INDEX event_tag_1 ON event_tag (eventid);
1544CREATE TABLE problem (
1545	eventid                  bigint                                    NOT NULL,
1546	source                   integer         DEFAULT '0'               NOT NULL,
1547	object                   integer         DEFAULT '0'               NOT NULL,
1548	objectid                 bigint          DEFAULT '0'               NOT NULL,
1549	clock                    integer         DEFAULT '0'               NOT NULL,
1550	ns                       integer         DEFAULT '0'               NOT NULL,
1551	r_eventid                bigint                                    NULL,
1552	r_clock                  integer         DEFAULT '0'               NOT NULL,
1553	r_ns                     integer         DEFAULT '0'               NOT NULL,
1554	correlationid            bigint                                    NULL,
1555	userid                   bigint                                    NULL,
1556	name                     varchar(2048)   DEFAULT ''                NOT NULL,
1557	acknowledged             integer         DEFAULT '0'               NOT NULL,
1558	severity                 integer         DEFAULT '0'               NOT NULL,
1559	PRIMARY KEY (eventid)
1560);
1561CREATE INDEX problem_1 ON problem (source,object,objectid);
1562CREATE INDEX problem_2 ON problem (r_clock);
1563CREATE INDEX problem_3 ON problem (r_eventid);
1564CREATE TABLE problem_tag (
1565	problemtagid             bigint                                    NOT NULL,
1566	eventid                  bigint                                    NOT NULL,
1567	tag                      varchar(255)    DEFAULT ''                NOT NULL,
1568	value                    varchar(255)    DEFAULT ''                NOT NULL,
1569	PRIMARY KEY (problemtagid)
1570);
1571CREATE INDEX problem_tag_1 ON problem_tag (eventid,tag,value);
1572CREATE TABLE tag_filter (
1573	tag_filterid             bigint                                    NOT NULL,
1574	usrgrpid                 bigint                                    NOT NULL,
1575	groupid                  bigint                                    NOT NULL,
1576	tag                      varchar(255)    DEFAULT ''                NOT NULL,
1577	value                    varchar(255)    DEFAULT ''                NOT NULL,
1578	PRIMARY KEY (tag_filterid)
1579);
1580CREATE TABLE event_recovery (
1581	eventid                  bigint                                    NOT NULL,
1582	r_eventid                bigint                                    NOT NULL,
1583	c_eventid                bigint                                    NULL,
1584	correlationid            bigint                                    NULL,
1585	userid                   bigint                                    NULL,
1586	PRIMARY KEY (eventid)
1587);
1588CREATE INDEX event_recovery_1 ON event_recovery (r_eventid);
1589CREATE INDEX event_recovery_2 ON event_recovery (c_eventid);
1590CREATE TABLE correlation (
1591	correlationid            bigint                                    NOT NULL,
1592	name                     varchar(255)    DEFAULT ''                NOT NULL,
1593	description              text            DEFAULT ''                NOT NULL,
1594	evaltype                 integer         DEFAULT '0'               NOT NULL,
1595	status                   integer         DEFAULT '0'               NOT NULL,
1596	formula                  varchar(255)    DEFAULT ''                NOT NULL,
1597	PRIMARY KEY (correlationid)
1598);
1599CREATE INDEX correlation_1 ON correlation (status);
1600CREATE UNIQUE INDEX correlation_2 ON correlation (name);
1601CREATE TABLE corr_condition (
1602	corr_conditionid         bigint                                    NOT NULL,
1603	correlationid            bigint                                    NOT NULL,
1604	type                     integer         DEFAULT '0'               NOT NULL,
1605	PRIMARY KEY (corr_conditionid)
1606);
1607CREATE INDEX corr_condition_1 ON corr_condition (correlationid);
1608CREATE TABLE corr_condition_tag (
1609	corr_conditionid         bigint                                    NOT NULL,
1610	tag                      varchar(255)    DEFAULT ''                NOT NULL,
1611	PRIMARY KEY (corr_conditionid)
1612);
1613CREATE TABLE corr_condition_group (
1614	corr_conditionid         bigint                                    NOT NULL,
1615	operator                 integer         DEFAULT '0'               NOT NULL,
1616	groupid                  bigint                                    NOT NULL,
1617	PRIMARY KEY (corr_conditionid)
1618);
1619CREATE INDEX corr_condition_group_1 ON corr_condition_group (groupid);
1620CREATE TABLE corr_condition_tagpair (
1621	corr_conditionid         bigint                                    NOT NULL,
1622	oldtag                   varchar(255)    DEFAULT ''                NOT NULL,
1623	newtag                   varchar(255)    DEFAULT ''                NOT NULL,
1624	PRIMARY KEY (corr_conditionid)
1625);
1626CREATE TABLE corr_condition_tagvalue (
1627	corr_conditionid         bigint                                    NOT NULL,
1628	tag                      varchar(255)    DEFAULT ''                NOT NULL,
1629	operator                 integer         DEFAULT '0'               NOT NULL,
1630	value                    varchar(255)    DEFAULT ''                NOT NULL,
1631	PRIMARY KEY (corr_conditionid)
1632);
1633CREATE TABLE corr_operation (
1634	corr_operationid         bigint                                    NOT NULL,
1635	correlationid            bigint                                    NOT NULL,
1636	type                     integer         DEFAULT '0'               NOT NULL,
1637	PRIMARY KEY (corr_operationid)
1638);
1639CREATE INDEX corr_operation_1 ON corr_operation (correlationid);
1640CREATE TABLE task (
1641	taskid                   bigint                                    NOT NULL,
1642	type                     integer                                   NOT NULL,
1643	status                   integer         DEFAULT '0'               NOT NULL,
1644	clock                    integer         DEFAULT '0'               NOT NULL,
1645	ttl                      integer         DEFAULT '0'               NOT NULL,
1646	proxy_hostid             bigint                                    NULL,
1647	PRIMARY KEY (taskid)
1648);
1649CREATE INDEX task_1 ON task (status,proxy_hostid);
1650CREATE TABLE task_close_problem (
1651	taskid                   bigint                                    NOT NULL,
1652	acknowledgeid            bigint                                    NOT NULL,
1653	PRIMARY KEY (taskid)
1654);
1655CREATE TABLE item_preproc (
1656	item_preprocid           bigint                                    NOT NULL,
1657	itemid                   bigint                                    NOT NULL,
1658	step                     integer         DEFAULT '0'               NOT NULL,
1659	type                     integer         DEFAULT '0'               NOT NULL,
1660	params                   text            DEFAULT ''                NOT NULL,
1661	error_handler            integer         DEFAULT '0'               NOT NULL,
1662	error_handler_params     varchar(255)    DEFAULT ''                NOT NULL,
1663	PRIMARY KEY (item_preprocid)
1664);
1665CREATE INDEX item_preproc_1 ON item_preproc (itemid,step);
1666CREATE TABLE task_remote_command (
1667	taskid                   bigint                                    NOT NULL,
1668	command_type             integer         DEFAULT '0'               NOT NULL,
1669	execute_on               integer         DEFAULT '0'               NOT NULL,
1670	port                     integer         DEFAULT '0'               NOT NULL,
1671	authtype                 integer         DEFAULT '0'               NOT NULL,
1672	username                 varchar(64)     DEFAULT ''                NOT NULL,
1673	password                 varchar(64)     DEFAULT ''                NOT NULL,
1674	publickey                varchar(64)     DEFAULT ''                NOT NULL,
1675	privatekey               varchar(64)     DEFAULT ''                NOT NULL,
1676	command                  text            DEFAULT ''                NOT NULL,
1677	alertid                  bigint                                    NULL,
1678	parent_taskid            bigint                                    NOT NULL,
1679	hostid                   bigint                                    NOT NULL,
1680	PRIMARY KEY (taskid)
1681);
1682CREATE TABLE task_remote_command_result (
1683	taskid                   bigint                                    NOT NULL,
1684	status                   integer         DEFAULT '0'               NOT NULL,
1685	parent_taskid            bigint                                    NOT NULL,
1686	info                     text            DEFAULT ''                NOT NULL,
1687	PRIMARY KEY (taskid)
1688);
1689CREATE TABLE task_data (
1690	taskid                   bigint                                    NOT NULL,
1691	type                     integer         DEFAULT '0'               NOT NULL,
1692	data                     text            DEFAULT ''                NOT NULL,
1693	parent_taskid            bigint                                    NOT NULL,
1694	PRIMARY KEY (taskid)
1695);
1696CREATE TABLE task_result (
1697	taskid                   bigint                                    NOT NULL,
1698	status                   integer         DEFAULT '0'               NOT NULL,
1699	parent_taskid            bigint                                    NOT NULL,
1700	info                     text            DEFAULT ''                NOT NULL,
1701	PRIMARY KEY (taskid)
1702);
1703CREATE INDEX task_result_1 ON task_result (parent_taskid);
1704CREATE TABLE task_acknowledge (
1705	taskid                   bigint                                    NOT NULL,
1706	acknowledgeid            bigint                                    NOT NULL,
1707	PRIMARY KEY (taskid)
1708);
1709CREATE TABLE sysmap_shape (
1710	sysmap_shapeid           bigint                                    NOT NULL,
1711	sysmapid                 bigint                                    NOT NULL,
1712	type                     integer         DEFAULT '0'               NOT NULL,
1713	x                        integer         DEFAULT '0'               NOT NULL,
1714	y                        integer         DEFAULT '0'               NOT NULL,
1715	width                    integer         DEFAULT '200'             NOT NULL,
1716	height                   integer         DEFAULT '200'             NOT NULL,
1717	text                     text            DEFAULT ''                NOT NULL,
1718	font                     integer         DEFAULT '9'               NOT NULL,
1719	font_size                integer         DEFAULT '11'              NOT NULL,
1720	font_color               varchar(6)      DEFAULT '000000'          NOT NULL,
1721	text_halign              integer         DEFAULT '0'               NOT NULL,
1722	text_valign              integer         DEFAULT '0'               NOT NULL,
1723	border_type              integer         DEFAULT '0'               NOT NULL,
1724	border_width             integer         DEFAULT '1'               NOT NULL,
1725	border_color             varchar(6)      DEFAULT '000000'          NOT NULL,
1726	background_color         varchar(6)      DEFAULT ''                NOT NULL,
1727	zindex                   integer         DEFAULT '0'               NOT NULL,
1728	PRIMARY KEY (sysmap_shapeid)
1729);
1730CREATE INDEX sysmap_shape_1 ON sysmap_shape (sysmapid);
1731CREATE TABLE sysmap_element_trigger (
1732	selement_triggerid       bigint                                    NOT NULL,
1733	selementid               bigint                                    NOT NULL,
1734	triggerid                bigint                                    NOT NULL,
1735	PRIMARY KEY (selement_triggerid)
1736);
1737CREATE UNIQUE INDEX sysmap_element_trigger_1 ON sysmap_element_trigger (selementid,triggerid);
1738CREATE TABLE httptest_field (
1739	httptest_fieldid         bigint                                    NOT NULL,
1740	httptestid               bigint                                    NOT NULL,
1741	type                     integer         DEFAULT '0'               NOT NULL,
1742	name                     varchar(255)    DEFAULT ''                NOT NULL,
1743	value                    text            DEFAULT ''                NOT NULL,
1744	PRIMARY KEY (httptest_fieldid)
1745);
1746CREATE INDEX httptest_field_1 ON httptest_field (httptestid);
1747CREATE TABLE httpstep_field (
1748	httpstep_fieldid         bigint                                    NOT NULL,
1749	httpstepid               bigint                                    NOT NULL,
1750	type                     integer         DEFAULT '0'               NOT NULL,
1751	name                     varchar(255)    DEFAULT ''                NOT NULL,
1752	value                    text            DEFAULT ''                NOT NULL,
1753	PRIMARY KEY (httpstep_fieldid)
1754);
1755CREATE INDEX httpstep_field_1 ON httpstep_field (httpstepid);
1756CREATE TABLE dashboard (
1757	dashboardid              bigint                                    NOT NULL,
1758	name                     varchar(255)                              NOT NULL,
1759	userid                   bigint                                    NOT NULL,
1760	private                  integer         DEFAULT '1'               NOT NULL,
1761	PRIMARY KEY (dashboardid)
1762);
1763CREATE TABLE dashboard_user (
1764	dashboard_userid         bigint                                    NOT NULL,
1765	dashboardid              bigint                                    NOT NULL,
1766	userid                   bigint                                    NOT NULL,
1767	permission               integer         DEFAULT '2'               NOT NULL,
1768	PRIMARY KEY (dashboard_userid)
1769);
1770CREATE UNIQUE INDEX dashboard_user_1 ON dashboard_user (dashboardid,userid);
1771CREATE TABLE dashboard_usrgrp (
1772	dashboard_usrgrpid       bigint                                    NOT NULL,
1773	dashboardid              bigint                                    NOT NULL,
1774	usrgrpid                 bigint                                    NOT NULL,
1775	permission               integer         DEFAULT '2'               NOT NULL,
1776	PRIMARY KEY (dashboard_usrgrpid)
1777);
1778CREATE UNIQUE INDEX dashboard_usrgrp_1 ON dashboard_usrgrp (dashboardid,usrgrpid);
1779CREATE TABLE widget (
1780	widgetid                 bigint                                    NOT NULL,
1781	dashboardid              bigint                                    NOT NULL,
1782	type                     varchar(255)    DEFAULT ''                NOT NULL,
1783	name                     varchar(255)    DEFAULT ''                NOT NULL,
1784	x                        integer         DEFAULT '0'               NOT NULL,
1785	y                        integer         DEFAULT '0'               NOT NULL,
1786	width                    integer         DEFAULT '1'               NOT NULL,
1787	height                   integer         DEFAULT '2'               NOT NULL,
1788	view_mode                integer         DEFAULT '0'               NOT NULL,
1789	PRIMARY KEY (widgetid)
1790);
1791CREATE INDEX widget_1 ON widget (dashboardid);
1792CREATE TABLE widget_field (
1793	widget_fieldid           bigint                                    NOT NULL,
1794	widgetid                 bigint                                    NOT NULL,
1795	type                     integer         DEFAULT '0'               NOT NULL,
1796	name                     varchar(255)    DEFAULT ''                NOT NULL,
1797	value_int                integer         DEFAULT '0'               NOT NULL,
1798	value_str                varchar(255)    DEFAULT ''                NOT NULL,
1799	value_groupid            bigint                                    NULL,
1800	value_hostid             bigint                                    NULL,
1801	value_itemid             bigint                                    NULL,
1802	value_graphid            bigint                                    NULL,
1803	value_sysmapid           bigint                                    NULL,
1804	PRIMARY KEY (widget_fieldid)
1805);
1806CREATE INDEX widget_field_1 ON widget_field (widgetid);
1807CREATE INDEX widget_field_2 ON widget_field (value_groupid);
1808CREATE INDEX widget_field_3 ON widget_field (value_hostid);
1809CREATE INDEX widget_field_4 ON widget_field (value_itemid);
1810CREATE INDEX widget_field_5 ON widget_field (value_graphid);
1811CREATE INDEX widget_field_6 ON widget_field (value_sysmapid);
1812CREATE TABLE task_check_now (
1813	taskid                   bigint                                    NOT NULL,
1814	itemid                   bigint                                    NOT NULL,
1815	PRIMARY KEY (taskid)
1816);
1817CREATE TABLE event_suppress (
1818	event_suppressid         bigint                                    NOT NULL,
1819	eventid                  bigint                                    NOT NULL,
1820	maintenanceid            bigint                                    NULL,
1821	suppress_until           integer         DEFAULT '0'               NOT NULL,
1822	PRIMARY KEY (event_suppressid)
1823);
1824CREATE UNIQUE INDEX event_suppress_1 ON event_suppress (eventid,maintenanceid);
1825CREATE INDEX event_suppress_2 ON event_suppress (suppress_until);
1826CREATE INDEX event_suppress_3 ON event_suppress (maintenanceid);
1827CREATE TABLE maintenance_tag (
1828	maintenancetagid         bigint                                    NOT NULL,
1829	maintenanceid            bigint                                    NOT NULL,
1830	tag                      varchar(255)    DEFAULT ''                NOT NULL,
1831	operator                 integer         DEFAULT '2'               NOT NULL,
1832	value                    varchar(255)    DEFAULT ''                NOT NULL,
1833	PRIMARY KEY (maintenancetagid)
1834);
1835CREATE INDEX maintenance_tag_1 ON maintenance_tag (maintenanceid);
1836CREATE TABLE lld_macro_path (
1837	lld_macro_pathid         bigint                                    NOT NULL,
1838	itemid                   bigint                                    NOT NULL,
1839	lld_macro                varchar(255)    DEFAULT ''                NOT NULL,
1840	path                     varchar(255)    DEFAULT ''                NOT NULL,
1841	PRIMARY KEY (lld_macro_pathid)
1842);
1843CREATE UNIQUE INDEX lld_macro_path_1 ON lld_macro_path (itemid,lld_macro);
1844CREATE TABLE host_tag (
1845	hosttagid                bigint                                    NOT NULL,
1846	hostid                   bigint                                    NOT NULL,
1847	tag                      varchar(255)    DEFAULT ''                NOT NULL,
1848	value                    varchar(255)    DEFAULT ''                NOT NULL,
1849	PRIMARY KEY (hosttagid)
1850);
1851CREATE INDEX host_tag_1 ON host_tag (hostid);
1852CREATE TABLE config_autoreg_tls (
1853	autoreg_tlsid            bigint                                    NOT NULL,
1854	tls_psk_identity         varchar(128)    DEFAULT ''                NOT NULL,
1855	tls_psk                  varchar(512)    DEFAULT ''                NOT NULL,
1856	PRIMARY KEY (autoreg_tlsid)
1857);
1858CREATE UNIQUE INDEX config_autoreg_tls_1 ON config_autoreg_tls (tls_psk_identity);
1859CREATE TABLE module (
1860	moduleid                 bigint                                    NOT NULL,
1861	id                       varchar(255)    DEFAULT ''                NOT NULL,
1862	relative_path            varchar(255)    DEFAULT ''                NOT NULL,
1863	status                   integer         DEFAULT '0'               NOT NULL,
1864	config                   text            DEFAULT ''                NOT NULL,
1865	PRIMARY KEY (moduleid)
1866);
1867CREATE TABLE interface_snmp (
1868	interfaceid              bigint                                    NOT NULL,
1869	version                  integer         DEFAULT '2'               NOT NULL,
1870	bulk                     integer         DEFAULT '1'               NOT NULL,
1871	community                varchar(64)     DEFAULT ''                NOT NULL,
1872	securityname             varchar(64)     DEFAULT ''                NOT NULL,
1873	securitylevel            integer         DEFAULT '0'               NOT NULL,
1874	authpassphrase           varchar(64)     DEFAULT ''                NOT NULL,
1875	privpassphrase           varchar(64)     DEFAULT ''                NOT NULL,
1876	authprotocol             integer         DEFAULT '0'               NOT NULL,
1877	privprotocol             integer         DEFAULT '0'               NOT NULL,
1878	contextname              varchar(255)    DEFAULT ''                NOT NULL,
1879	PRIMARY KEY (interfaceid)
1880);
1881CREATE TABLE lld_override (
1882	lld_overrideid           bigint                                    NOT NULL,
1883	itemid                   bigint                                    NOT NULL,
1884	name                     varchar(255)    DEFAULT ''                NOT NULL,
1885	step                     integer         DEFAULT '0'               NOT NULL,
1886	evaltype                 integer         DEFAULT '0'               NOT NULL,
1887	formula                  varchar(255)    DEFAULT ''                NOT NULL,
1888	stop                     integer         DEFAULT '0'               NOT NULL,
1889	PRIMARY KEY (lld_overrideid)
1890);
1891CREATE UNIQUE INDEX lld_override_1 ON lld_override (itemid,name);
1892CREATE TABLE lld_override_condition (
1893	lld_override_conditionid bigint                                    NOT NULL,
1894	lld_overrideid           bigint                                    NOT NULL,
1895	operator                 integer         DEFAULT '8'               NOT NULL,
1896	macro                    varchar(64)     DEFAULT ''                NOT NULL,
1897	value                    varchar(255)    DEFAULT ''                NOT NULL,
1898	PRIMARY KEY (lld_override_conditionid)
1899);
1900CREATE INDEX lld_override_condition_1 ON lld_override_condition (lld_overrideid);
1901CREATE TABLE lld_override_operation (
1902	lld_override_operationid bigint                                    NOT NULL,
1903	lld_overrideid           bigint                                    NOT NULL,
1904	operationobject          integer         DEFAULT '0'               NOT NULL,
1905	operator                 integer         DEFAULT '0'               NOT NULL,
1906	value                    varchar(255)    DEFAULT ''                NOT NULL,
1907	PRIMARY KEY (lld_override_operationid)
1908);
1909CREATE INDEX lld_override_operation_1 ON lld_override_operation (lld_overrideid);
1910CREATE TABLE lld_override_opstatus (
1911	lld_override_operationid bigint                                    NOT NULL,
1912	status                   integer         DEFAULT '0'               NOT NULL,
1913	PRIMARY KEY (lld_override_operationid)
1914);
1915CREATE TABLE lld_override_opdiscover (
1916	lld_override_operationid bigint                                    NOT NULL,
1917	discover                 integer         DEFAULT '0'               NOT NULL,
1918	PRIMARY KEY (lld_override_operationid)
1919);
1920CREATE TABLE lld_override_opperiod (
1921	lld_override_operationid bigint                                    NOT NULL,
1922	delay                    varchar(1024)   DEFAULT '0'               NOT NULL,
1923	PRIMARY KEY (lld_override_operationid)
1924);
1925CREATE TABLE lld_override_ophistory (
1926	lld_override_operationid bigint                                    NOT NULL,
1927	history                  varchar(255)    DEFAULT '90d'             NOT NULL,
1928	PRIMARY KEY (lld_override_operationid)
1929);
1930CREATE TABLE lld_override_optrends (
1931	lld_override_operationid bigint                                    NOT NULL,
1932	trends                   varchar(255)    DEFAULT '365d'            NOT NULL,
1933	PRIMARY KEY (lld_override_operationid)
1934);
1935CREATE TABLE lld_override_opseverity (
1936	lld_override_operationid bigint                                    NOT NULL,
1937	severity                 integer         DEFAULT '0'               NOT NULL,
1938	PRIMARY KEY (lld_override_operationid)
1939);
1940CREATE TABLE lld_override_optag (
1941	lld_override_optagid     bigint                                    NOT NULL,
1942	lld_override_operationid bigint                                    NOT NULL,
1943	tag                      varchar(255)    DEFAULT ''                NOT NULL,
1944	value                    varchar(255)    DEFAULT ''                NOT NULL,
1945	PRIMARY KEY (lld_override_optagid)
1946);
1947CREATE INDEX lld_override_optag_1 ON lld_override_optag (lld_override_operationid);
1948CREATE TABLE lld_override_optemplate (
1949	lld_override_optemplateid bigint                                    NOT NULL,
1950	lld_override_operationid bigint                                    NOT NULL,
1951	templateid               bigint                                    NOT NULL,
1952	PRIMARY KEY (lld_override_optemplateid)
1953);
1954CREATE UNIQUE INDEX lld_override_optemplate_1 ON lld_override_optemplate (lld_override_operationid,templateid);
1955CREATE INDEX lld_override_optemplate_2 ON lld_override_optemplate (templateid);
1956CREATE TABLE lld_override_opinventory (
1957	lld_override_operationid bigint                                    NOT NULL,
1958	inventory_mode           integer         DEFAULT '0'               NOT NULL,
1959	PRIMARY KEY (lld_override_operationid)
1960);
1961CREATE TABLE dbversion (
1962	mandatory                integer         DEFAULT '0'               NOT NULL,
1963	optional                 integer         DEFAULT '0'               NOT NULL
1964);
1965INSERT INTO dbversion VALUES ('5000000','5000005');
1966ALTER TABLE ONLY hosts ADD CONSTRAINT c_hosts_1 FOREIGN KEY (proxy_hostid) REFERENCES hosts (hostid);
1967ALTER TABLE ONLY hosts ADD CONSTRAINT c_hosts_2 FOREIGN KEY (maintenanceid) REFERENCES maintenances (maintenanceid);
1968ALTER TABLE ONLY hosts ADD CONSTRAINT c_hosts_3 FOREIGN KEY (templateid) REFERENCES hosts (hostid) ON DELETE CASCADE;
1969ALTER TABLE ONLY group_prototype ADD CONSTRAINT c_group_prototype_1 FOREIGN KEY (hostid) REFERENCES hosts (hostid) ON DELETE CASCADE;
1970ALTER TABLE ONLY group_prototype ADD CONSTRAINT c_group_prototype_2 FOREIGN KEY (groupid) REFERENCES hstgrp (groupid);
1971ALTER TABLE ONLY group_prototype ADD CONSTRAINT c_group_prototype_3 FOREIGN KEY (templateid) REFERENCES group_prototype (group_prototypeid) ON DELETE CASCADE;
1972ALTER TABLE ONLY group_discovery ADD CONSTRAINT c_group_discovery_1 FOREIGN KEY (groupid) REFERENCES hstgrp (groupid) ON DELETE CASCADE;
1973ALTER TABLE ONLY group_discovery ADD CONSTRAINT c_group_discovery_2 FOREIGN KEY (parent_group_prototypeid) REFERENCES group_prototype (group_prototypeid);
1974ALTER TABLE ONLY screens ADD CONSTRAINT c_screens_1 FOREIGN KEY (templateid) REFERENCES hosts (hostid) ON DELETE CASCADE;
1975ALTER TABLE ONLY screens ADD CONSTRAINT c_screens_3 FOREIGN KEY (userid) REFERENCES users (userid);
1976ALTER TABLE ONLY screens_items ADD CONSTRAINT c_screens_items_1 FOREIGN KEY (screenid) REFERENCES screens (screenid) ON DELETE CASCADE;
1977ALTER TABLE ONLY screen_user ADD CONSTRAINT c_screen_user_1 FOREIGN KEY (screenid) REFERENCES screens (screenid) ON DELETE CASCADE;
1978ALTER TABLE ONLY screen_user ADD CONSTRAINT c_screen_user_2 FOREIGN KEY (userid) REFERENCES users (userid) ON DELETE CASCADE;
1979ALTER TABLE ONLY screen_usrgrp ADD CONSTRAINT c_screen_usrgrp_1 FOREIGN KEY (screenid) REFERENCES screens (screenid) ON DELETE CASCADE;
1980ALTER TABLE ONLY screen_usrgrp ADD CONSTRAINT c_screen_usrgrp_2 FOREIGN KEY (usrgrpid) REFERENCES usrgrp (usrgrpid) ON DELETE CASCADE;
1981ALTER TABLE ONLY slideshows ADD CONSTRAINT c_slideshows_3 FOREIGN KEY (userid) REFERENCES users (userid);
1982ALTER TABLE ONLY slideshow_user ADD CONSTRAINT c_slideshow_user_1 FOREIGN KEY (slideshowid) REFERENCES slideshows (slideshowid) ON DELETE CASCADE;
1983ALTER TABLE ONLY slideshow_user ADD CONSTRAINT c_slideshow_user_2 FOREIGN KEY (userid) REFERENCES users (userid) ON DELETE CASCADE;
1984ALTER TABLE ONLY slideshow_usrgrp ADD CONSTRAINT c_slideshow_usrgrp_1 FOREIGN KEY (slideshowid) REFERENCES slideshows (slideshowid) ON DELETE CASCADE;
1985ALTER TABLE ONLY slideshow_usrgrp ADD CONSTRAINT c_slideshow_usrgrp_2 FOREIGN KEY (usrgrpid) REFERENCES usrgrp (usrgrpid) ON DELETE CASCADE;
1986ALTER TABLE ONLY slides ADD CONSTRAINT c_slides_1 FOREIGN KEY (slideshowid) REFERENCES slideshows (slideshowid) ON DELETE CASCADE;
1987ALTER TABLE ONLY slides ADD CONSTRAINT c_slides_2 FOREIGN KEY (screenid) REFERENCES screens (screenid) ON DELETE CASCADE;
1988ALTER TABLE ONLY drules ADD CONSTRAINT c_drules_1 FOREIGN KEY (proxy_hostid) REFERENCES hosts (hostid);
1989ALTER TABLE ONLY dchecks ADD CONSTRAINT c_dchecks_1 FOREIGN KEY (druleid) REFERENCES drules (druleid) ON DELETE CASCADE;
1990ALTER TABLE ONLY applications ADD CONSTRAINT c_applications_1 FOREIGN KEY (hostid) REFERENCES hosts (hostid) ON DELETE CASCADE;
1991ALTER TABLE ONLY httptest ADD CONSTRAINT c_httptest_1 FOREIGN KEY (applicationid) REFERENCES applications (applicationid);
1992ALTER TABLE ONLY httptest ADD CONSTRAINT c_httptest_2 FOREIGN KEY (hostid) REFERENCES hosts (hostid) ON DELETE CASCADE;
1993ALTER TABLE ONLY httptest ADD CONSTRAINT c_httptest_3 FOREIGN KEY (templateid) REFERENCES httptest (httptestid) ON DELETE CASCADE;
1994ALTER TABLE ONLY httpstep ADD CONSTRAINT c_httpstep_1 FOREIGN KEY (httptestid) REFERENCES httptest (httptestid) ON DELETE CASCADE;
1995ALTER TABLE ONLY interface ADD CONSTRAINT c_interface_1 FOREIGN KEY (hostid) REFERENCES hosts (hostid) ON DELETE CASCADE;
1996ALTER TABLE ONLY items ADD CONSTRAINT c_items_1 FOREIGN KEY (hostid) REFERENCES hosts (hostid) ON DELETE CASCADE;
1997ALTER TABLE ONLY items ADD CONSTRAINT c_items_2 FOREIGN KEY (templateid) REFERENCES items (itemid) ON DELETE CASCADE;
1998ALTER TABLE ONLY items ADD CONSTRAINT c_items_3 FOREIGN KEY (valuemapid) REFERENCES valuemaps (valuemapid);
1999ALTER TABLE ONLY items ADD CONSTRAINT c_items_4 FOREIGN KEY (interfaceid) REFERENCES interface (interfaceid);
2000ALTER TABLE ONLY items ADD CONSTRAINT c_items_5 FOREIGN KEY (master_itemid) REFERENCES items (itemid) ON DELETE CASCADE;
2001ALTER TABLE ONLY httpstepitem ADD CONSTRAINT c_httpstepitem_1 FOREIGN KEY (httpstepid) REFERENCES httpstep (httpstepid) ON DELETE CASCADE;
2002ALTER TABLE ONLY httpstepitem ADD CONSTRAINT c_httpstepitem_2 FOREIGN KEY (itemid) REFERENCES items (itemid) ON DELETE CASCADE;
2003ALTER TABLE ONLY httptestitem ADD CONSTRAINT c_httptestitem_1 FOREIGN KEY (httptestid) REFERENCES httptest (httptestid) ON DELETE CASCADE;
2004ALTER TABLE ONLY httptestitem ADD CONSTRAINT c_httptestitem_2 FOREIGN KEY (itemid) REFERENCES items (itemid) ON DELETE CASCADE;
2005ALTER TABLE ONLY media_type_param ADD CONSTRAINT c_media_type_param_1 FOREIGN KEY (mediatypeid) REFERENCES media_type (mediatypeid) ON DELETE CASCADE;
2006ALTER TABLE ONLY media_type_message ADD CONSTRAINT c_media_type_message_1 FOREIGN KEY (mediatypeid) REFERENCES media_type (mediatypeid) ON DELETE CASCADE;
2007ALTER TABLE ONLY users_groups ADD CONSTRAINT c_users_groups_1 FOREIGN KEY (usrgrpid) REFERENCES usrgrp (usrgrpid) ON DELETE CASCADE;
2008ALTER TABLE ONLY users_groups ADD CONSTRAINT c_users_groups_2 FOREIGN KEY (userid) REFERENCES users (userid) ON DELETE CASCADE;
2009ALTER TABLE ONLY scripts ADD CONSTRAINT c_scripts_1 FOREIGN KEY (usrgrpid) REFERENCES usrgrp (usrgrpid);
2010ALTER TABLE ONLY scripts ADD CONSTRAINT c_scripts_2 FOREIGN KEY (groupid) REFERENCES hstgrp (groupid);
2011ALTER TABLE ONLY operations ADD CONSTRAINT c_operations_1 FOREIGN KEY (actionid) REFERENCES actions (actionid) ON DELETE CASCADE;
2012ALTER TABLE ONLY opmessage ADD CONSTRAINT c_opmessage_1 FOREIGN KEY (operationid) REFERENCES operations (operationid) ON DELETE CASCADE;
2013ALTER TABLE ONLY opmessage ADD CONSTRAINT c_opmessage_2 FOREIGN KEY (mediatypeid) REFERENCES media_type (mediatypeid);
2014ALTER TABLE ONLY opmessage_grp ADD CONSTRAINT c_opmessage_grp_1 FOREIGN KEY (operationid) REFERENCES operations (operationid) ON DELETE CASCADE;
2015ALTER TABLE ONLY opmessage_grp ADD CONSTRAINT c_opmessage_grp_2 FOREIGN KEY (usrgrpid) REFERENCES usrgrp (usrgrpid);
2016ALTER TABLE ONLY opmessage_usr ADD CONSTRAINT c_opmessage_usr_1 FOREIGN KEY (operationid) REFERENCES operations (operationid) ON DELETE CASCADE;
2017ALTER TABLE ONLY opmessage_usr ADD CONSTRAINT c_opmessage_usr_2 FOREIGN KEY (userid) REFERENCES users (userid);
2018ALTER TABLE ONLY opcommand ADD CONSTRAINT c_opcommand_1 FOREIGN KEY (operationid) REFERENCES operations (operationid) ON DELETE CASCADE;
2019ALTER TABLE ONLY opcommand ADD CONSTRAINT c_opcommand_2 FOREIGN KEY (scriptid) REFERENCES scripts (scriptid);
2020ALTER TABLE ONLY opcommand_hst ADD CONSTRAINT c_opcommand_hst_1 FOREIGN KEY (operationid) REFERENCES operations (operationid) ON DELETE CASCADE;
2021ALTER TABLE ONLY opcommand_hst ADD CONSTRAINT c_opcommand_hst_2 FOREIGN KEY (hostid) REFERENCES hosts (hostid);
2022ALTER TABLE ONLY opcommand_grp ADD CONSTRAINT c_opcommand_grp_1 FOREIGN KEY (operationid) REFERENCES operations (operationid) ON DELETE CASCADE;
2023ALTER TABLE ONLY opcommand_grp ADD CONSTRAINT c_opcommand_grp_2 FOREIGN KEY (groupid) REFERENCES hstgrp (groupid);
2024ALTER TABLE ONLY opgroup ADD CONSTRAINT c_opgroup_1 FOREIGN KEY (operationid) REFERENCES operations (operationid) ON DELETE CASCADE;
2025ALTER TABLE ONLY opgroup ADD CONSTRAINT c_opgroup_2 FOREIGN KEY (groupid) REFERENCES hstgrp (groupid);
2026ALTER TABLE ONLY optemplate ADD CONSTRAINT c_optemplate_1 FOREIGN KEY (operationid) REFERENCES operations (operationid) ON DELETE CASCADE;
2027ALTER TABLE ONLY optemplate ADD CONSTRAINT c_optemplate_2 FOREIGN KEY (templateid) REFERENCES hosts (hostid);
2028ALTER TABLE ONLY opconditions ADD CONSTRAINT c_opconditions_1 FOREIGN KEY (operationid) REFERENCES operations (operationid) ON DELETE CASCADE;
2029ALTER TABLE ONLY conditions ADD CONSTRAINT c_conditions_1 FOREIGN KEY (actionid) REFERENCES actions (actionid) ON DELETE CASCADE;
2030ALTER TABLE ONLY config ADD CONSTRAINT c_config_1 FOREIGN KEY (alert_usrgrpid) REFERENCES usrgrp (usrgrpid);
2031ALTER TABLE ONLY config ADD CONSTRAINT c_config_2 FOREIGN KEY (discovery_groupid) REFERENCES hstgrp (groupid);
2032ALTER TABLE ONLY triggers ADD CONSTRAINT c_triggers_1 FOREIGN KEY (templateid) REFERENCES triggers (triggerid) ON DELETE CASCADE;
2033ALTER TABLE ONLY trigger_depends ADD CONSTRAINT c_trigger_depends_1 FOREIGN KEY (triggerid_down) REFERENCES triggers (triggerid) ON DELETE CASCADE;
2034ALTER TABLE ONLY trigger_depends ADD CONSTRAINT c_trigger_depends_2 FOREIGN KEY (triggerid_up) REFERENCES triggers (triggerid) ON DELETE CASCADE;
2035ALTER TABLE ONLY functions ADD CONSTRAINT c_functions_1 FOREIGN KEY (itemid) REFERENCES items (itemid) ON DELETE CASCADE;
2036ALTER TABLE ONLY functions ADD CONSTRAINT c_functions_2 FOREIGN KEY (triggerid) REFERENCES triggers (triggerid) ON DELETE CASCADE;
2037ALTER TABLE ONLY graphs ADD CONSTRAINT c_graphs_1 FOREIGN KEY (templateid) REFERENCES graphs (graphid) ON DELETE CASCADE;
2038ALTER TABLE ONLY graphs ADD CONSTRAINT c_graphs_2 FOREIGN KEY (ymin_itemid) REFERENCES items (itemid);
2039ALTER TABLE ONLY graphs ADD CONSTRAINT c_graphs_3 FOREIGN KEY (ymax_itemid) REFERENCES items (itemid);
2040ALTER TABLE ONLY graphs_items ADD CONSTRAINT c_graphs_items_1 FOREIGN KEY (graphid) REFERENCES graphs (graphid) ON DELETE CASCADE;
2041ALTER TABLE ONLY graphs_items ADD CONSTRAINT c_graphs_items_2 FOREIGN KEY (itemid) REFERENCES items (itemid) ON DELETE CASCADE;
2042ALTER TABLE ONLY hostmacro ADD CONSTRAINT c_hostmacro_1 FOREIGN KEY (hostid) REFERENCES hosts (hostid) ON DELETE CASCADE;
2043ALTER TABLE ONLY hosts_groups ADD CONSTRAINT c_hosts_groups_1 FOREIGN KEY (hostid) REFERENCES hosts (hostid) ON DELETE CASCADE;
2044ALTER TABLE ONLY hosts_groups ADD CONSTRAINT c_hosts_groups_2 FOREIGN KEY (groupid) REFERENCES hstgrp (groupid) ON DELETE CASCADE;
2045ALTER TABLE ONLY hosts_templates ADD CONSTRAINT c_hosts_templates_1 FOREIGN KEY (hostid) REFERENCES hosts (hostid) ON DELETE CASCADE;
2046ALTER TABLE ONLY hosts_templates ADD CONSTRAINT c_hosts_templates_2 FOREIGN KEY (templateid) REFERENCES hosts (hostid) ON DELETE CASCADE;
2047ALTER TABLE ONLY items_applications ADD CONSTRAINT c_items_applications_1 FOREIGN KEY (applicationid) REFERENCES applications (applicationid) ON DELETE CASCADE;
2048ALTER TABLE ONLY items_applications ADD CONSTRAINT c_items_applications_2 FOREIGN KEY (itemid) REFERENCES items (itemid) ON DELETE CASCADE;
2049ALTER TABLE ONLY mappings ADD CONSTRAINT c_mappings_1 FOREIGN KEY (valuemapid) REFERENCES valuemaps (valuemapid) ON DELETE CASCADE;
2050ALTER TABLE ONLY media ADD CONSTRAINT c_media_1 FOREIGN KEY (userid) REFERENCES users (userid) ON DELETE CASCADE;
2051ALTER TABLE ONLY media ADD CONSTRAINT c_media_2 FOREIGN KEY (mediatypeid) REFERENCES media_type (mediatypeid) ON DELETE CASCADE;
2052ALTER TABLE ONLY rights ADD CONSTRAINT c_rights_1 FOREIGN KEY (groupid) REFERENCES usrgrp (usrgrpid) ON DELETE CASCADE;
2053ALTER TABLE ONLY rights ADD CONSTRAINT c_rights_2 FOREIGN KEY (id) REFERENCES hstgrp (groupid) ON DELETE CASCADE;
2054ALTER TABLE ONLY services ADD CONSTRAINT c_services_1 FOREIGN KEY (triggerid) REFERENCES triggers (triggerid) ON DELETE CASCADE;
2055ALTER TABLE ONLY services_links ADD CONSTRAINT c_services_links_1 FOREIGN KEY (serviceupid) REFERENCES services (serviceid) ON DELETE CASCADE;
2056ALTER TABLE ONLY services_links ADD CONSTRAINT c_services_links_2 FOREIGN KEY (servicedownid) REFERENCES services (serviceid) ON DELETE CASCADE;
2057ALTER TABLE ONLY services_times ADD CONSTRAINT c_services_times_1 FOREIGN KEY (serviceid) REFERENCES services (serviceid) ON DELETE CASCADE;
2058ALTER TABLE ONLY icon_map ADD CONSTRAINT c_icon_map_1 FOREIGN KEY (default_iconid) REFERENCES images (imageid);
2059ALTER TABLE ONLY icon_mapping ADD CONSTRAINT c_icon_mapping_1 FOREIGN KEY (iconmapid) REFERENCES icon_map (iconmapid) ON DELETE CASCADE;
2060ALTER TABLE ONLY icon_mapping ADD CONSTRAINT c_icon_mapping_2 FOREIGN KEY (iconid) REFERENCES images (imageid);
2061ALTER TABLE ONLY sysmaps ADD CONSTRAINT c_sysmaps_1 FOREIGN KEY (backgroundid) REFERENCES images (imageid);
2062ALTER TABLE ONLY sysmaps ADD CONSTRAINT c_sysmaps_2 FOREIGN KEY (iconmapid) REFERENCES icon_map (iconmapid);
2063ALTER TABLE ONLY sysmaps ADD CONSTRAINT c_sysmaps_3 FOREIGN KEY (userid) REFERENCES users (userid);
2064ALTER TABLE ONLY sysmaps_elements ADD CONSTRAINT c_sysmaps_elements_1 FOREIGN KEY (sysmapid) REFERENCES sysmaps (sysmapid) ON DELETE CASCADE;
2065ALTER TABLE ONLY sysmaps_elements ADD CONSTRAINT c_sysmaps_elements_2 FOREIGN KEY (iconid_off) REFERENCES images (imageid);
2066ALTER TABLE ONLY sysmaps_elements ADD CONSTRAINT c_sysmaps_elements_3 FOREIGN KEY (iconid_on) REFERENCES images (imageid);
2067ALTER TABLE ONLY sysmaps_elements ADD CONSTRAINT c_sysmaps_elements_4 FOREIGN KEY (iconid_disabled) REFERENCES images (imageid);
2068ALTER TABLE ONLY sysmaps_elements ADD CONSTRAINT c_sysmaps_elements_5 FOREIGN KEY (iconid_maintenance) REFERENCES images (imageid);
2069ALTER TABLE ONLY sysmaps_links ADD CONSTRAINT c_sysmaps_links_1 FOREIGN KEY (sysmapid) REFERENCES sysmaps (sysmapid) ON DELETE CASCADE;
2070ALTER TABLE ONLY sysmaps_links ADD CONSTRAINT c_sysmaps_links_2 FOREIGN KEY (selementid1) REFERENCES sysmaps_elements (selementid) ON DELETE CASCADE;
2071ALTER TABLE ONLY sysmaps_links ADD CONSTRAINT c_sysmaps_links_3 FOREIGN KEY (selementid2) REFERENCES sysmaps_elements (selementid) ON DELETE CASCADE;
2072ALTER TABLE ONLY sysmaps_link_triggers ADD CONSTRAINT c_sysmaps_link_triggers_1 FOREIGN KEY (linkid) REFERENCES sysmaps_links (linkid) ON DELETE CASCADE;
2073ALTER TABLE ONLY sysmaps_link_triggers ADD CONSTRAINT c_sysmaps_link_triggers_2 FOREIGN KEY (triggerid) REFERENCES triggers (triggerid) ON DELETE CASCADE;
2074ALTER TABLE ONLY sysmap_element_url ADD CONSTRAINT c_sysmap_element_url_1 FOREIGN KEY (selementid) REFERENCES sysmaps_elements (selementid) ON DELETE CASCADE;
2075ALTER TABLE ONLY sysmap_url ADD CONSTRAINT c_sysmap_url_1 FOREIGN KEY (sysmapid) REFERENCES sysmaps (sysmapid) ON DELETE CASCADE;
2076ALTER TABLE ONLY sysmap_user ADD CONSTRAINT c_sysmap_user_1 FOREIGN KEY (sysmapid) REFERENCES sysmaps (sysmapid) ON DELETE CASCADE;
2077ALTER TABLE ONLY sysmap_user ADD CONSTRAINT c_sysmap_user_2 FOREIGN KEY (userid) REFERENCES users (userid) ON DELETE CASCADE;
2078ALTER TABLE ONLY sysmap_usrgrp ADD CONSTRAINT c_sysmap_usrgrp_1 FOREIGN KEY (sysmapid) REFERENCES sysmaps (sysmapid) ON DELETE CASCADE;
2079ALTER TABLE ONLY sysmap_usrgrp ADD CONSTRAINT c_sysmap_usrgrp_2 FOREIGN KEY (usrgrpid) REFERENCES usrgrp (usrgrpid) ON DELETE CASCADE;
2080ALTER TABLE ONLY maintenances_hosts ADD CONSTRAINT c_maintenances_hosts_1 FOREIGN KEY (maintenanceid) REFERENCES maintenances (maintenanceid) ON DELETE CASCADE;
2081ALTER TABLE ONLY maintenances_hosts ADD CONSTRAINT c_maintenances_hosts_2 FOREIGN KEY (hostid) REFERENCES hosts (hostid) ON DELETE CASCADE;
2082ALTER TABLE ONLY maintenances_groups ADD CONSTRAINT c_maintenances_groups_1 FOREIGN KEY (maintenanceid) REFERENCES maintenances (maintenanceid) ON DELETE CASCADE;
2083ALTER TABLE ONLY maintenances_groups ADD CONSTRAINT c_maintenances_groups_2 FOREIGN KEY (groupid) REFERENCES hstgrp (groupid) ON DELETE CASCADE;
2084ALTER TABLE ONLY maintenances_windows ADD CONSTRAINT c_maintenances_windows_1 FOREIGN KEY (maintenanceid) REFERENCES maintenances (maintenanceid) ON DELETE CASCADE;
2085ALTER TABLE ONLY maintenances_windows ADD CONSTRAINT c_maintenances_windows_2 FOREIGN KEY (timeperiodid) REFERENCES timeperiods (timeperiodid) ON DELETE CASCADE;
2086ALTER TABLE ONLY expressions ADD CONSTRAINT c_expressions_1 FOREIGN KEY (regexpid) REFERENCES regexps (regexpid) ON DELETE CASCADE;
2087ALTER TABLE ONLY alerts ADD CONSTRAINT c_alerts_1 FOREIGN KEY (actionid) REFERENCES actions (actionid) ON DELETE CASCADE;
2088ALTER TABLE ONLY alerts ADD CONSTRAINT c_alerts_2 FOREIGN KEY (eventid) REFERENCES events (eventid) ON DELETE CASCADE;
2089ALTER TABLE ONLY alerts ADD CONSTRAINT c_alerts_3 FOREIGN KEY (userid) REFERENCES users (userid) ON DELETE CASCADE;
2090ALTER TABLE ONLY alerts ADD CONSTRAINT c_alerts_4 FOREIGN KEY (mediatypeid) REFERENCES media_type (mediatypeid) ON DELETE CASCADE;
2091ALTER TABLE ONLY alerts ADD CONSTRAINT c_alerts_5 FOREIGN KEY (p_eventid) REFERENCES events (eventid) ON DELETE CASCADE;
2092ALTER TABLE ONLY alerts ADD CONSTRAINT c_alerts_6 FOREIGN KEY (acknowledgeid) REFERENCES acknowledges (acknowledgeid) ON DELETE CASCADE;
2093ALTER TABLE ONLY acknowledges ADD CONSTRAINT c_acknowledges_1 FOREIGN KEY (userid) REFERENCES users (userid) ON DELETE CASCADE;
2094ALTER TABLE ONLY acknowledges ADD CONSTRAINT c_acknowledges_2 FOREIGN KEY (eventid) REFERENCES events (eventid) ON DELETE CASCADE;
2095ALTER TABLE ONLY auditlog ADD CONSTRAINT c_auditlog_1 FOREIGN KEY (userid) REFERENCES users (userid) ON DELETE CASCADE;
2096ALTER TABLE ONLY auditlog_details ADD CONSTRAINT c_auditlog_details_1 FOREIGN KEY (auditid) REFERENCES auditlog (auditid) ON DELETE CASCADE;
2097ALTER TABLE ONLY service_alarms ADD CONSTRAINT c_service_alarms_1 FOREIGN KEY (serviceid) REFERENCES services (serviceid) ON DELETE CASCADE;
2098ALTER TABLE ONLY autoreg_host ADD CONSTRAINT c_autoreg_host_1 FOREIGN KEY (proxy_hostid) REFERENCES hosts (hostid) ON DELETE CASCADE;
2099ALTER TABLE ONLY dhosts ADD CONSTRAINT c_dhosts_1 FOREIGN KEY (druleid) REFERENCES drules (druleid) ON DELETE CASCADE;
2100ALTER TABLE ONLY dservices ADD CONSTRAINT c_dservices_1 FOREIGN KEY (dhostid) REFERENCES dhosts (dhostid) ON DELETE CASCADE;
2101ALTER TABLE ONLY dservices ADD CONSTRAINT c_dservices_2 FOREIGN KEY (dcheckid) REFERENCES dchecks (dcheckid) ON DELETE CASCADE;
2102ALTER TABLE ONLY graph_discovery ADD CONSTRAINT c_graph_discovery_1 FOREIGN KEY (graphid) REFERENCES graphs (graphid) ON DELETE CASCADE;
2103ALTER TABLE ONLY graph_discovery ADD CONSTRAINT c_graph_discovery_2 FOREIGN KEY (parent_graphid) REFERENCES graphs (graphid);
2104ALTER TABLE ONLY host_inventory ADD CONSTRAINT c_host_inventory_1 FOREIGN KEY (hostid) REFERENCES hosts (hostid) ON DELETE CASCADE;
2105ALTER TABLE ONLY item_discovery ADD CONSTRAINT c_item_discovery_1 FOREIGN KEY (itemid) REFERENCES items (itemid) ON DELETE CASCADE;
2106ALTER TABLE ONLY item_discovery ADD CONSTRAINT c_item_discovery_2 FOREIGN KEY (parent_itemid) REFERENCES items (itemid) ON DELETE CASCADE;
2107ALTER TABLE ONLY host_discovery ADD CONSTRAINT c_host_discovery_1 FOREIGN KEY (hostid) REFERENCES hosts (hostid) ON DELETE CASCADE;
2108ALTER TABLE ONLY host_discovery ADD CONSTRAINT c_host_discovery_2 FOREIGN KEY (parent_hostid) REFERENCES hosts (hostid);
2109ALTER TABLE ONLY host_discovery ADD CONSTRAINT c_host_discovery_3 FOREIGN KEY (parent_itemid) REFERENCES items (itemid);
2110ALTER TABLE ONLY interface_discovery ADD CONSTRAINT c_interface_discovery_1 FOREIGN KEY (interfaceid) REFERENCES interface (interfaceid) ON DELETE CASCADE;
2111ALTER TABLE ONLY interface_discovery ADD CONSTRAINT c_interface_discovery_2 FOREIGN KEY (parent_interfaceid) REFERENCES interface (interfaceid) ON DELETE CASCADE;
2112ALTER TABLE ONLY profiles ADD CONSTRAINT c_profiles_1 FOREIGN KEY (userid) REFERENCES users (userid) ON DELETE CASCADE;
2113ALTER TABLE ONLY sessions ADD CONSTRAINT c_sessions_1 FOREIGN KEY (userid) REFERENCES users (userid) ON DELETE CASCADE;
2114ALTER TABLE ONLY trigger_discovery ADD CONSTRAINT c_trigger_discovery_1 FOREIGN KEY (triggerid) REFERENCES triggers (triggerid) ON DELETE CASCADE;
2115ALTER TABLE ONLY trigger_discovery ADD CONSTRAINT c_trigger_discovery_2 FOREIGN KEY (parent_triggerid) REFERENCES triggers (triggerid);
2116ALTER TABLE ONLY application_template ADD CONSTRAINT c_application_template_1 FOREIGN KEY (applicationid) REFERENCES applications (applicationid) ON DELETE CASCADE;
2117ALTER TABLE ONLY application_template ADD CONSTRAINT c_application_template_2 FOREIGN KEY (templateid) REFERENCES applications (applicationid) ON DELETE CASCADE;
2118ALTER TABLE ONLY item_condition ADD CONSTRAINT c_item_condition_1 FOREIGN KEY (itemid) REFERENCES items (itemid) ON DELETE CASCADE;
2119ALTER TABLE ONLY item_rtdata ADD CONSTRAINT c_item_rtdata_1 FOREIGN KEY (itemid) REFERENCES items (itemid) ON DELETE CASCADE;
2120ALTER TABLE ONLY application_prototype ADD CONSTRAINT c_application_prototype_1 FOREIGN KEY (itemid) REFERENCES items (itemid) ON DELETE CASCADE;
2121ALTER TABLE ONLY application_prototype ADD CONSTRAINT c_application_prototype_2 FOREIGN KEY (templateid) REFERENCES application_prototype (application_prototypeid) ON DELETE CASCADE;
2122ALTER TABLE ONLY item_application_prototype ADD CONSTRAINT c_item_application_prototype_1 FOREIGN KEY (application_prototypeid) REFERENCES application_prototype (application_prototypeid) ON DELETE CASCADE;
2123ALTER TABLE ONLY item_application_prototype ADD CONSTRAINT c_item_application_prototype_2 FOREIGN KEY (itemid) REFERENCES items (itemid) ON DELETE CASCADE;
2124ALTER TABLE ONLY application_discovery ADD CONSTRAINT c_application_discovery_1 FOREIGN KEY (applicationid) REFERENCES applications (applicationid) ON DELETE CASCADE;
2125ALTER TABLE ONLY application_discovery ADD CONSTRAINT c_application_discovery_2 FOREIGN KEY (application_prototypeid) REFERENCES application_prototype (application_prototypeid) ON DELETE CASCADE;
2126ALTER TABLE ONLY opinventory ADD CONSTRAINT c_opinventory_1 FOREIGN KEY (operationid) REFERENCES operations (operationid) ON DELETE CASCADE;
2127ALTER TABLE ONLY trigger_tag ADD CONSTRAINT c_trigger_tag_1 FOREIGN KEY (triggerid) REFERENCES triggers (triggerid) ON DELETE CASCADE;
2128ALTER TABLE ONLY event_tag ADD CONSTRAINT c_event_tag_1 FOREIGN KEY (eventid) REFERENCES events (eventid) ON DELETE CASCADE;
2129ALTER TABLE ONLY problem ADD CONSTRAINT c_problem_1 FOREIGN KEY (eventid) REFERENCES events (eventid) ON DELETE CASCADE;
2130ALTER TABLE ONLY problem ADD CONSTRAINT c_problem_2 FOREIGN KEY (r_eventid) REFERENCES events (eventid) ON DELETE CASCADE;
2131ALTER TABLE ONLY problem_tag ADD CONSTRAINT c_problem_tag_1 FOREIGN KEY (eventid) REFERENCES problem (eventid) ON DELETE CASCADE;
2132ALTER TABLE ONLY tag_filter ADD CONSTRAINT c_tag_filter_1 FOREIGN KEY (usrgrpid) REFERENCES usrgrp (usrgrpid) ON DELETE CASCADE;
2133ALTER TABLE ONLY tag_filter ADD CONSTRAINT c_tag_filter_2 FOREIGN KEY (groupid) REFERENCES hstgrp (groupid) ON DELETE CASCADE;
2134ALTER TABLE ONLY event_recovery ADD CONSTRAINT c_event_recovery_1 FOREIGN KEY (eventid) REFERENCES events (eventid) ON DELETE CASCADE;
2135ALTER TABLE ONLY event_recovery ADD CONSTRAINT c_event_recovery_2 FOREIGN KEY (r_eventid) REFERENCES events (eventid) ON DELETE CASCADE;
2136ALTER TABLE ONLY event_recovery ADD CONSTRAINT c_event_recovery_3 FOREIGN KEY (c_eventid) REFERENCES events (eventid) ON DELETE CASCADE;
2137ALTER TABLE ONLY corr_condition ADD CONSTRAINT c_corr_condition_1 FOREIGN KEY (correlationid) REFERENCES correlation (correlationid) ON DELETE CASCADE;
2138ALTER TABLE ONLY corr_condition_tag ADD CONSTRAINT c_corr_condition_tag_1 FOREIGN KEY (corr_conditionid) REFERENCES corr_condition (corr_conditionid) ON DELETE CASCADE;
2139ALTER TABLE ONLY corr_condition_group ADD CONSTRAINT c_corr_condition_group_1 FOREIGN KEY (corr_conditionid) REFERENCES corr_condition (corr_conditionid) ON DELETE CASCADE;
2140ALTER TABLE ONLY corr_condition_group ADD CONSTRAINT c_corr_condition_group_2 FOREIGN KEY (groupid) REFERENCES hstgrp (groupid);
2141ALTER TABLE ONLY corr_condition_tagpair ADD CONSTRAINT c_corr_condition_tagpair_1 FOREIGN KEY (corr_conditionid) REFERENCES corr_condition (corr_conditionid) ON DELETE CASCADE;
2142ALTER TABLE ONLY corr_condition_tagvalue ADD CONSTRAINT c_corr_condition_tagvalue_1 FOREIGN KEY (corr_conditionid) REFERENCES corr_condition (corr_conditionid) ON DELETE CASCADE;
2143ALTER TABLE ONLY corr_operation ADD CONSTRAINT c_corr_operation_1 FOREIGN KEY (correlationid) REFERENCES correlation (correlationid) ON DELETE CASCADE;
2144ALTER TABLE ONLY task ADD CONSTRAINT c_task_1 FOREIGN KEY (proxy_hostid) REFERENCES hosts (hostid) ON DELETE CASCADE;
2145ALTER TABLE ONLY task_close_problem ADD CONSTRAINT c_task_close_problem_1 FOREIGN KEY (taskid) REFERENCES task (taskid) ON DELETE CASCADE;
2146ALTER TABLE ONLY item_preproc ADD CONSTRAINT c_item_preproc_1 FOREIGN KEY (itemid) REFERENCES items (itemid) ON DELETE CASCADE;
2147ALTER TABLE ONLY task_remote_command ADD CONSTRAINT c_task_remote_command_1 FOREIGN KEY (taskid) REFERENCES task (taskid) ON DELETE CASCADE;
2148ALTER TABLE ONLY task_remote_command_result ADD CONSTRAINT c_task_remote_command_result_1 FOREIGN KEY (taskid) REFERENCES task (taskid) ON DELETE CASCADE;
2149ALTER TABLE ONLY task_data ADD CONSTRAINT c_task_data_1 FOREIGN KEY (taskid) REFERENCES task (taskid) ON DELETE CASCADE;
2150ALTER TABLE ONLY task_result ADD CONSTRAINT c_task_result_1 FOREIGN KEY (taskid) REFERENCES task (taskid) ON DELETE CASCADE;
2151ALTER TABLE ONLY task_acknowledge ADD CONSTRAINT c_task_acknowledge_1 FOREIGN KEY (taskid) REFERENCES task (taskid) ON DELETE CASCADE;
2152ALTER TABLE ONLY sysmap_shape ADD CONSTRAINT c_sysmap_shape_1 FOREIGN KEY (sysmapid) REFERENCES sysmaps (sysmapid) ON DELETE CASCADE;
2153ALTER TABLE ONLY sysmap_element_trigger ADD CONSTRAINT c_sysmap_element_trigger_1 FOREIGN KEY (selementid) REFERENCES sysmaps_elements (selementid) ON DELETE CASCADE;
2154ALTER TABLE ONLY sysmap_element_trigger ADD CONSTRAINT c_sysmap_element_trigger_2 FOREIGN KEY (triggerid) REFERENCES triggers (triggerid) ON DELETE CASCADE;
2155ALTER TABLE ONLY httptest_field ADD CONSTRAINT c_httptest_field_1 FOREIGN KEY (httptestid) REFERENCES httptest (httptestid) ON DELETE CASCADE;
2156ALTER TABLE ONLY httpstep_field ADD CONSTRAINT c_httpstep_field_1 FOREIGN KEY (httpstepid) REFERENCES httpstep (httpstepid) ON DELETE CASCADE;
2157ALTER TABLE ONLY dashboard ADD CONSTRAINT c_dashboard_1 FOREIGN KEY (userid) REFERENCES users (userid);
2158ALTER TABLE ONLY dashboard_user ADD CONSTRAINT c_dashboard_user_1 FOREIGN KEY (dashboardid) REFERENCES dashboard (dashboardid) ON DELETE CASCADE;
2159ALTER TABLE ONLY dashboard_user ADD CONSTRAINT c_dashboard_user_2 FOREIGN KEY (userid) REFERENCES users (userid) ON DELETE CASCADE;
2160ALTER TABLE ONLY dashboard_usrgrp ADD CONSTRAINT c_dashboard_usrgrp_1 FOREIGN KEY (dashboardid) REFERENCES dashboard (dashboardid) ON DELETE CASCADE;
2161ALTER TABLE ONLY dashboard_usrgrp ADD CONSTRAINT c_dashboard_usrgrp_2 FOREIGN KEY (usrgrpid) REFERENCES usrgrp (usrgrpid) ON DELETE CASCADE;
2162ALTER TABLE ONLY widget ADD CONSTRAINT c_widget_1 FOREIGN KEY (dashboardid) REFERENCES dashboard (dashboardid) ON DELETE CASCADE;
2163ALTER TABLE ONLY widget_field ADD CONSTRAINT c_widget_field_1 FOREIGN KEY (widgetid) REFERENCES widget (widgetid) ON DELETE CASCADE;
2164ALTER TABLE ONLY widget_field ADD CONSTRAINT c_widget_field_2 FOREIGN KEY (value_groupid) REFERENCES hstgrp (groupid) ON DELETE CASCADE;
2165ALTER TABLE ONLY widget_field ADD CONSTRAINT c_widget_field_3 FOREIGN KEY (value_hostid) REFERENCES hosts (hostid) ON DELETE CASCADE;
2166ALTER TABLE ONLY widget_field ADD CONSTRAINT c_widget_field_4 FOREIGN KEY (value_itemid) REFERENCES items (itemid) ON DELETE CASCADE;
2167ALTER TABLE ONLY widget_field ADD CONSTRAINT c_widget_field_5 FOREIGN KEY (value_graphid) REFERENCES graphs (graphid) ON DELETE CASCADE;
2168ALTER TABLE ONLY widget_field ADD CONSTRAINT c_widget_field_6 FOREIGN KEY (value_sysmapid) REFERENCES sysmaps (sysmapid) ON DELETE CASCADE;
2169ALTER TABLE ONLY task_check_now ADD CONSTRAINT c_task_check_now_1 FOREIGN KEY (taskid) REFERENCES task (taskid) ON DELETE CASCADE;
2170ALTER TABLE ONLY event_suppress ADD CONSTRAINT c_event_suppress_1 FOREIGN KEY (eventid) REFERENCES events (eventid) ON DELETE CASCADE;
2171ALTER TABLE ONLY event_suppress ADD CONSTRAINT c_event_suppress_2 FOREIGN KEY (maintenanceid) REFERENCES maintenances (maintenanceid) ON DELETE CASCADE;
2172ALTER TABLE ONLY maintenance_tag ADD CONSTRAINT c_maintenance_tag_1 FOREIGN KEY (maintenanceid) REFERENCES maintenances (maintenanceid) ON DELETE CASCADE;
2173ALTER TABLE ONLY lld_macro_path ADD CONSTRAINT c_lld_macro_path_1 FOREIGN KEY (itemid) REFERENCES items (itemid) ON DELETE CASCADE;
2174ALTER TABLE ONLY host_tag ADD CONSTRAINT c_host_tag_1 FOREIGN KEY (hostid) REFERENCES hosts (hostid) ON DELETE CASCADE;
2175ALTER TABLE ONLY interface_snmp ADD CONSTRAINT c_interface_snmp_1 FOREIGN KEY (interfaceid) REFERENCES interface (interfaceid) ON DELETE CASCADE;
2176ALTER TABLE ONLY lld_override ADD CONSTRAINT c_lld_override_1 FOREIGN KEY (itemid) REFERENCES items (itemid) ON DELETE CASCADE;
2177ALTER TABLE ONLY lld_override_condition ADD CONSTRAINT c_lld_override_condition_1 FOREIGN KEY (lld_overrideid) REFERENCES lld_override (lld_overrideid) ON DELETE CASCADE;
2178ALTER TABLE ONLY lld_override_operation ADD CONSTRAINT c_lld_override_operation_1 FOREIGN KEY (lld_overrideid) REFERENCES lld_override (lld_overrideid) ON DELETE CASCADE;
2179ALTER TABLE ONLY lld_override_opstatus ADD CONSTRAINT c_lld_override_opstatus_1 FOREIGN KEY (lld_override_operationid) REFERENCES lld_override_operation (lld_override_operationid) ON DELETE CASCADE;
2180ALTER TABLE ONLY lld_override_opdiscover ADD CONSTRAINT c_lld_override_opdiscover_1 FOREIGN KEY (lld_override_operationid) REFERENCES lld_override_operation (lld_override_operationid) ON DELETE CASCADE;
2181ALTER TABLE ONLY lld_override_opperiod ADD CONSTRAINT c_lld_override_opperiod_1 FOREIGN KEY (lld_override_operationid) REFERENCES lld_override_operation (lld_override_operationid) ON DELETE CASCADE;
2182ALTER TABLE ONLY lld_override_ophistory ADD CONSTRAINT c_lld_override_ophistory_1 FOREIGN KEY (lld_override_operationid) REFERENCES lld_override_operation (lld_override_operationid) ON DELETE CASCADE;
2183ALTER TABLE ONLY lld_override_optrends ADD CONSTRAINT c_lld_override_optrends_1 FOREIGN KEY (lld_override_operationid) REFERENCES lld_override_operation (lld_override_operationid) ON DELETE CASCADE;
2184ALTER TABLE ONLY lld_override_opseverity ADD CONSTRAINT c_lld_override_opseverity_1 FOREIGN KEY (lld_override_operationid) REFERENCES lld_override_operation (lld_override_operationid) ON DELETE CASCADE;
2185ALTER TABLE ONLY lld_override_optag ADD CONSTRAINT c_lld_override_optag_1 FOREIGN KEY (lld_override_operationid) REFERENCES lld_override_operation (lld_override_operationid) ON DELETE CASCADE;
2186ALTER TABLE ONLY lld_override_optemplate ADD CONSTRAINT c_lld_override_optemplate_1 FOREIGN KEY (lld_override_operationid) REFERENCES lld_override_operation (lld_override_operationid) ON DELETE CASCADE;
2187ALTER TABLE ONLY lld_override_optemplate ADD CONSTRAINT c_lld_override_optemplate_2 FOREIGN KEY (templateid) REFERENCES hosts (hostid);
2188ALTER TABLE ONLY lld_override_opinventory ADD CONSTRAINT c_lld_override_opinventory_1 FOREIGN KEY (lld_override_operationid) REFERENCES lld_override_operation (lld_override_operationid) ON DELETE CASCADE;
2189