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                   char(32)        DEFAULT ''                NOT NULL,
7	url                      varchar(255)    DEFAULT ''                NOT NULL,
8	autologin                integer         DEFAULT '0'               NOT NULL,
9	autologout               integer         DEFAULT '900'             NOT NULL,
10	lang                     varchar(5)      DEFAULT 'en_GB'           NOT NULL,
11	refresh                  integer         DEFAULT '30'              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	PRIMARY KEY (maintenanceid)
29);
30CREATE INDEX maintenances_1 ON maintenances (active_since,active_till);
31CREATE UNIQUE INDEX maintenances_2 ON maintenances (name);
32CREATE TABLE hosts (
33	hostid                   bigint                                    NOT NULL,
34	proxy_hostid             bigint                                    NULL,
35	host                     varchar(128)    DEFAULT ''                NOT NULL,
36	status                   integer         DEFAULT '0'               NOT NULL,
37	disable_until            integer         DEFAULT '0'               NOT NULL,
38	error                    varchar(2048)   DEFAULT ''                NOT NULL,
39	available                integer         DEFAULT '0'               NOT NULL,
40	errors_from              integer         DEFAULT '0'               NOT NULL,
41	lastaccess               integer         DEFAULT '0'               NOT NULL,
42	ipmi_authtype            integer         DEFAULT '0'               NOT NULL,
43	ipmi_privilege           integer         DEFAULT '2'               NOT NULL,
44	ipmi_username            varchar(16)     DEFAULT ''                NOT NULL,
45	ipmi_password            varchar(20)     DEFAULT ''                NOT NULL,
46	ipmi_disable_until       integer         DEFAULT '0'               NOT NULL,
47	ipmi_available           integer         DEFAULT '0'               NOT NULL,
48	snmp_disable_until       integer         DEFAULT '0'               NOT NULL,
49	snmp_available           integer         DEFAULT '0'               NOT NULL,
50	maintenanceid            bigint                                    NULL,
51	maintenance_status       integer         DEFAULT '0'               NOT NULL,
52	maintenance_type         integer         DEFAULT '0'               NOT NULL,
53	maintenance_from         integer         DEFAULT '0'               NOT NULL,
54	ipmi_errors_from         integer         DEFAULT '0'               NOT NULL,
55	snmp_errors_from         integer         DEFAULT '0'               NOT NULL,
56	ipmi_error               varchar(2048)   DEFAULT ''                NOT NULL,
57	snmp_error               varchar(2048)   DEFAULT ''                NOT NULL,
58	jmx_disable_until        integer         DEFAULT '0'               NOT NULL,
59	jmx_available            integer         DEFAULT '0'               NOT NULL,
60	jmx_errors_from          integer         DEFAULT '0'               NOT NULL,
61	jmx_error                varchar(2048)   DEFAULT ''                NOT NULL,
62	name                     varchar(128)    DEFAULT ''                NOT NULL,
63	flags                    integer         DEFAULT '0'               NOT NULL,
64	templateid               bigint                                    NULL,
65	description              text            DEFAULT ''                NOT NULL,
66	tls_connect              integer         DEFAULT '1'               NOT NULL,
67	tls_accept               integer         DEFAULT '1'               NOT NULL,
68	tls_issuer               varchar(1024)   DEFAULT ''                NOT NULL,
69	tls_subject              varchar(1024)   DEFAULT ''                NOT NULL,
70	tls_psk_identity         varchar(128)    DEFAULT ''                NOT NULL,
71	tls_psk                  varchar(512)    DEFAULT ''                NOT NULL,
72	PRIMARY KEY (hostid)
73);
74CREATE INDEX hosts_1 ON hosts (host);
75CREATE INDEX hosts_2 ON hosts (status);
76CREATE INDEX hosts_3 ON hosts (proxy_hostid);
77CREATE INDEX hosts_4 ON hosts (name);
78CREATE INDEX hosts_5 ON hosts (maintenanceid);
79CREATE TABLE groups (
80	groupid                  bigint                                    NOT NULL,
81	name                     varchar(64)     DEFAULT ''                NOT NULL,
82	internal                 integer         DEFAULT '0'               NOT NULL,
83	flags                    integer         DEFAULT '0'               NOT NULL,
84	PRIMARY KEY (groupid)
85);
86CREATE INDEX groups_1 ON groups (name);
87CREATE TABLE group_prototype (
88	group_prototypeid        bigint                                    NOT NULL,
89	hostid                   bigint                                    NOT NULL,
90	name                     varchar(64)     DEFAULT ''                NOT NULL,
91	groupid                  bigint                                    NULL,
92	templateid               bigint                                    NULL,
93	PRIMARY KEY (group_prototypeid)
94);
95CREATE INDEX group_prototype_1 ON group_prototype (hostid);
96CREATE TABLE group_discovery (
97	groupid                  bigint                                    NOT NULL,
98	parent_group_prototypeid bigint                                    NOT NULL,
99	name                     varchar(64)     DEFAULT ''                NOT NULL,
100	lastcheck                integer         DEFAULT '0'               NOT NULL,
101	ts_delete                integer         DEFAULT '0'               NOT NULL,
102	PRIMARY KEY (groupid)
103);
104CREATE TABLE screens (
105	screenid                 bigint                                    NOT NULL,
106	name                     varchar(255)                              NOT NULL,
107	hsize                    integer         DEFAULT '1'               NOT NULL,
108	vsize                    integer         DEFAULT '1'               NOT NULL,
109	templateid               bigint                                    NULL,
110	userid                   bigint                                    NULL,
111	private                  integer         DEFAULT '1'               NOT NULL,
112	PRIMARY KEY (screenid)
113);
114CREATE INDEX screens_1 ON screens (templateid);
115CREATE TABLE screens_items (
116	screenitemid             bigint                                    NOT NULL,
117	screenid                 bigint                                    NOT NULL,
118	resourcetype             integer         DEFAULT '0'               NOT NULL,
119	resourceid               bigint          DEFAULT '0'               NOT NULL,
120	width                    integer         DEFAULT '320'             NOT NULL,
121	height                   integer         DEFAULT '200'             NOT NULL,
122	x                        integer         DEFAULT '0'               NOT NULL,
123	y                        integer         DEFAULT '0'               NOT NULL,
124	colspan                  integer         DEFAULT '1'               NOT NULL,
125	rowspan                  integer         DEFAULT '1'               NOT NULL,
126	elements                 integer         DEFAULT '25'              NOT NULL,
127	valign                   integer         DEFAULT '0'               NOT NULL,
128	halign                   integer         DEFAULT '0'               NOT NULL,
129	style                    integer         DEFAULT '0'               NOT NULL,
130	url                      varchar(255)    DEFAULT ''                NOT NULL,
131	dynamic                  integer         DEFAULT '0'               NOT NULL,
132	sort_triggers            integer         DEFAULT '0'               NOT NULL,
133	application              varchar(255)    DEFAULT ''                NOT NULL,
134	max_columns              integer         DEFAULT '3'               NOT NULL,
135	PRIMARY KEY (screenitemid)
136);
137CREATE INDEX screens_items_1 ON screens_items (screenid);
138CREATE TABLE screen_user (
139	screenuserid             bigint                                    NOT NULL,
140	screenid                 bigint                                    NOT NULL,
141	userid                   bigint                                    NOT NULL,
142	permission               integer         DEFAULT '2'               NOT NULL,
143	PRIMARY KEY (screenuserid)
144);
145CREATE UNIQUE INDEX screen_user_1 ON screen_user (screenid,userid);
146CREATE TABLE screen_usrgrp (
147	screenusrgrpid           bigint                                    NOT NULL,
148	screenid                 bigint                                    NOT NULL,
149	usrgrpid                 bigint                                    NOT NULL,
150	permission               integer         DEFAULT '2'               NOT NULL,
151	PRIMARY KEY (screenusrgrpid)
152);
153CREATE UNIQUE INDEX screen_usrgrp_1 ON screen_usrgrp (screenid,usrgrpid);
154CREATE TABLE slideshows (
155	slideshowid              bigint                                    NOT NULL,
156	name                     varchar(255)    DEFAULT ''                NOT NULL,
157	delay                    integer         DEFAULT '0'               NOT NULL,
158	userid                   bigint                                    NOT NULL,
159	private                  integer         DEFAULT '1'               NOT NULL,
160	PRIMARY KEY (slideshowid)
161);
162CREATE UNIQUE INDEX slideshows_1 ON slideshows (name);
163CREATE TABLE slideshow_user (
164	slideshowuserid          bigint                                    NOT NULL,
165	slideshowid              bigint                                    NOT NULL,
166	userid                   bigint                                    NOT NULL,
167	permission               integer         DEFAULT '2'               NOT NULL,
168	PRIMARY KEY (slideshowuserid)
169);
170CREATE UNIQUE INDEX slideshow_user_1 ON slideshow_user (slideshowid,userid);
171CREATE TABLE slideshow_usrgrp (
172	slideshowusrgrpid        bigint                                    NOT NULL,
173	slideshowid              bigint                                    NOT NULL,
174	usrgrpid                 bigint                                    NOT NULL,
175	permission               integer         DEFAULT '2'               NOT NULL,
176	PRIMARY KEY (slideshowusrgrpid)
177);
178CREATE UNIQUE INDEX slideshow_usrgrp_1 ON slideshow_usrgrp (slideshowid,usrgrpid);
179CREATE TABLE slides (
180	slideid                  bigint                                    NOT NULL,
181	slideshowid              bigint                                    NOT NULL,
182	screenid                 bigint                                    NOT NULL,
183	step                     integer         DEFAULT '0'               NOT NULL,
184	delay                    integer         DEFAULT '0'               NOT NULL,
185	PRIMARY KEY (slideid)
186);
187CREATE INDEX slides_1 ON slides (slideshowid);
188CREATE INDEX slides_2 ON slides (screenid);
189CREATE TABLE drules (
190	druleid                  bigint                                    NOT NULL,
191	proxy_hostid             bigint                                    NULL,
192	name                     varchar(255)    DEFAULT ''                NOT NULL,
193	iprange                  varchar(2048)   DEFAULT ''                NOT NULL,
194	delay                    integer         DEFAULT '3600'            NOT NULL,
195	nextcheck                integer         DEFAULT '0'               NOT NULL,
196	status                   integer         DEFAULT '0'               NOT NULL,
197	PRIMARY KEY (druleid)
198);
199CREATE INDEX drules_1 ON drules (proxy_hostid);
200CREATE UNIQUE INDEX drules_2 ON drules (name);
201CREATE TABLE dchecks (
202	dcheckid                 bigint                                    NOT NULL,
203	druleid                  bigint                                    NOT NULL,
204	type                     integer         DEFAULT '0'               NOT NULL,
205	key_                     varchar(255)    DEFAULT ''                NOT NULL,
206	snmp_community           varchar(255)    DEFAULT ''                NOT NULL,
207	ports                    varchar(255)    DEFAULT '0'               NOT NULL,
208	snmpv3_securityname      varchar(64)     DEFAULT ''                NOT NULL,
209	snmpv3_securitylevel     integer         DEFAULT '0'               NOT NULL,
210	snmpv3_authpassphrase    varchar(64)     DEFAULT ''                NOT NULL,
211	snmpv3_privpassphrase    varchar(64)     DEFAULT ''                NOT NULL,
212	uniq                     integer         DEFAULT '0'               NOT NULL,
213	snmpv3_authprotocol      integer         DEFAULT '0'               NOT NULL,
214	snmpv3_privprotocol      integer         DEFAULT '0'               NOT NULL,
215	snmpv3_contextname       varchar(255)    DEFAULT ''                NOT NULL,
216	PRIMARY KEY (dcheckid)
217);
218CREATE INDEX dchecks_1 ON dchecks (druleid);
219CREATE TABLE applications (
220	applicationid            bigint                                    NOT NULL,
221	hostid                   bigint                                    NOT NULL,
222	name                     varchar(255)    DEFAULT ''                NOT NULL,
223	flags                    integer         DEFAULT '0'               NOT NULL,
224	PRIMARY KEY (applicationid)
225);
226CREATE UNIQUE INDEX applications_2 ON applications (hostid,name);
227CREATE TABLE httptest (
228	httptestid               bigint                                    NOT NULL,
229	name                     varchar(64)     DEFAULT ''                NOT NULL,
230	applicationid            bigint                                    NULL,
231	nextcheck                integer         DEFAULT '0'               NOT NULL,
232	delay                    integer         DEFAULT '60'              NOT NULL,
233	status                   integer         DEFAULT '0'               NOT NULL,
234	variables                text            DEFAULT ''                NOT NULL,
235	agent                    varchar(255)    DEFAULT 'Zabbix'          NOT NULL,
236	authentication           integer         DEFAULT '0'               NOT NULL,
237	http_user                varchar(64)     DEFAULT ''                NOT NULL,
238	http_password            varchar(64)     DEFAULT ''                NOT NULL,
239	hostid                   bigint                                    NOT NULL,
240	templateid               bigint                                    NULL,
241	http_proxy               varchar(255)    DEFAULT ''                NOT NULL,
242	retries                  integer         DEFAULT '1'               NOT NULL,
243	ssl_cert_file            varchar(255)    DEFAULT ''                NOT NULL,
244	ssl_key_file             varchar(255)    DEFAULT ''                NOT NULL,
245	ssl_key_password         varchar(64)     DEFAULT ''                NOT NULL,
246	verify_peer              integer         DEFAULT '0'               NOT NULL,
247	verify_host              integer         DEFAULT '0'               NOT NULL,
248	headers                  text            DEFAULT ''                NOT NULL,
249	PRIMARY KEY (httptestid)
250);
251CREATE INDEX httptest_1 ON httptest (applicationid);
252CREATE UNIQUE INDEX httptest_2 ON httptest (hostid,name);
253CREATE INDEX httptest_3 ON httptest (status);
254CREATE INDEX httptest_4 ON httptest (templateid);
255CREATE TABLE httpstep (
256	httpstepid               bigint                                    NOT NULL,
257	httptestid               bigint                                    NOT NULL,
258	name                     varchar(64)     DEFAULT ''                NOT NULL,
259	no                       integer         DEFAULT '0'               NOT NULL,
260	url                      varchar(2048)   DEFAULT ''                NOT NULL,
261	timeout                  integer         DEFAULT '15'              NOT NULL,
262	posts                    text            DEFAULT ''                NOT NULL,
263	required                 varchar(255)    DEFAULT ''                NOT NULL,
264	status_codes             varchar(255)    DEFAULT ''                NOT NULL,
265	variables                text            DEFAULT ''                NOT NULL,
266	follow_redirects         integer         DEFAULT '1'               NOT NULL,
267	retrieve_mode            integer         DEFAULT '0'               NOT NULL,
268	headers                  text            DEFAULT ''                NOT NULL,
269	PRIMARY KEY (httpstepid)
270);
271CREATE INDEX httpstep_1 ON httpstep (httptestid);
272CREATE TABLE interface (
273	interfaceid              bigint                                    NOT NULL,
274	hostid                   bigint                                    NOT NULL,
275	main                     integer         DEFAULT '0'               NOT NULL,
276	type                     integer         DEFAULT '0'               NOT NULL,
277	useip                    integer         DEFAULT '1'               NOT NULL,
278	ip                       varchar(64)     DEFAULT '127.0.0.1'       NOT NULL,
279	dns                      varchar(64)     DEFAULT ''                NOT NULL,
280	port                     varchar(64)     DEFAULT '10050'           NOT NULL,
281	bulk                     integer         DEFAULT '1'               NOT NULL,
282	PRIMARY KEY (interfaceid)
283);
284CREATE INDEX interface_1 ON interface (hostid,type);
285CREATE INDEX interface_2 ON interface (ip,dns);
286CREATE TABLE valuemaps (
287	valuemapid               bigint                                    NOT NULL,
288	name                     varchar(64)     DEFAULT ''                NOT NULL,
289	PRIMARY KEY (valuemapid)
290);
291CREATE UNIQUE INDEX valuemaps_1 ON valuemaps (name);
292CREATE TABLE items (
293	itemid                   bigint                                    NOT NULL,
294	type                     integer         DEFAULT '0'               NOT NULL,
295	snmp_community           varchar(64)     DEFAULT ''                NOT NULL,
296	snmp_oid                 varchar(255)    DEFAULT ''                NOT NULL,
297	hostid                   bigint                                    NOT NULL,
298	name                     varchar(255)    DEFAULT ''                NOT NULL,
299	key_                     varchar(255)    DEFAULT ''                NOT NULL,
300	delay                    integer         DEFAULT '0'               NOT NULL,
301	history                  integer         DEFAULT '90'              NOT NULL,
302	trends                   integer         DEFAULT '365'             NOT NULL,
303	status                   integer         DEFAULT '0'               NOT NULL,
304	value_type               integer         DEFAULT '0'               NOT NULL,
305	trapper_hosts            varchar(255)    DEFAULT ''                NOT NULL,
306	units                    varchar(255)    DEFAULT ''                NOT NULL,
307	multiplier               integer         DEFAULT '0'               NOT NULL,
308	delta                    integer         DEFAULT '0'               NOT NULL,
309	snmpv3_securityname      varchar(64)     DEFAULT ''                NOT NULL,
310	snmpv3_securitylevel     integer         DEFAULT '0'               NOT NULL,
311	snmpv3_authpassphrase    varchar(64)     DEFAULT ''                NOT NULL,
312	snmpv3_privpassphrase    varchar(64)     DEFAULT ''                NOT NULL,
313	formula                  varchar(255)    DEFAULT ''                NOT NULL,
314	error                    varchar(2048)   DEFAULT ''                NOT NULL,
315	lastlogsize              numeric(20)     DEFAULT '0'               NOT NULL,
316	logtimefmt               varchar(64)     DEFAULT ''                NOT NULL,
317	templateid               bigint                                    NULL,
318	valuemapid               bigint                                    NULL,
319	delay_flex               varchar(255)    DEFAULT ''                NOT NULL,
320	params                   text            DEFAULT ''                NOT NULL,
321	ipmi_sensor              varchar(128)    DEFAULT ''                NOT NULL,
322	data_type                integer         DEFAULT '0'               NOT NULL,
323	authtype                 integer         DEFAULT '0'               NOT NULL,
324	username                 varchar(64)     DEFAULT ''                NOT NULL,
325	password                 varchar(64)     DEFAULT ''                NOT NULL,
326	publickey                varchar(64)     DEFAULT ''                NOT NULL,
327	privatekey               varchar(64)     DEFAULT ''                NOT NULL,
328	mtime                    integer         DEFAULT '0'               NOT NULL,
329	flags                    integer         DEFAULT '0'               NOT NULL,
330	interfaceid              bigint                                    NULL,
331	port                     varchar(64)     DEFAULT ''                NOT NULL,
332	description              text            DEFAULT ''                NOT NULL,
333	inventory_link           integer         DEFAULT '0'               NOT NULL,
334	lifetime                 varchar(64)     DEFAULT '30'              NOT NULL,
335	snmpv3_authprotocol      integer         DEFAULT '0'               NOT NULL,
336	snmpv3_privprotocol      integer         DEFAULT '0'               NOT NULL,
337	state                    integer         DEFAULT '0'               NOT NULL,
338	snmpv3_contextname       varchar(255)    DEFAULT ''                NOT NULL,
339	evaltype                 integer         DEFAULT '0'               NOT NULL,
340	PRIMARY KEY (itemid)
341);
342CREATE UNIQUE INDEX items_1 ON items (hostid,key_);
343CREATE INDEX items_3 ON items (status);
344CREATE INDEX items_4 ON items (templateid);
345CREATE INDEX items_5 ON items (valuemapid);
346CREATE INDEX items_6 ON items (interfaceid);
347CREATE TABLE httpstepitem (
348	httpstepitemid           bigint                                    NOT NULL,
349	httpstepid               bigint                                    NOT NULL,
350	itemid                   bigint                                    NOT NULL,
351	type                     integer         DEFAULT '0'               NOT NULL,
352	PRIMARY KEY (httpstepitemid)
353);
354CREATE UNIQUE INDEX httpstepitem_1 ON httpstepitem (httpstepid,itemid);
355CREATE INDEX httpstepitem_2 ON httpstepitem (itemid);
356CREATE TABLE httptestitem (
357	httptestitemid           bigint                                    NOT NULL,
358	httptestid               bigint                                    NOT NULL,
359	itemid                   bigint                                    NOT NULL,
360	type                     integer         DEFAULT '0'               NOT NULL,
361	PRIMARY KEY (httptestitemid)
362);
363CREATE UNIQUE INDEX httptestitem_1 ON httptestitem (httptestid,itemid);
364CREATE INDEX httptestitem_2 ON httptestitem (itemid);
365CREATE TABLE media_type (
366	mediatypeid              bigint                                    NOT NULL,
367	type                     integer         DEFAULT '0'               NOT NULL,
368	description              varchar(100)    DEFAULT ''                NOT NULL,
369	smtp_server              varchar(255)    DEFAULT ''                NOT NULL,
370	smtp_helo                varchar(255)    DEFAULT ''                NOT NULL,
371	smtp_email               varchar(255)    DEFAULT ''                NOT NULL,
372	exec_path                varchar(255)    DEFAULT ''                NOT NULL,
373	gsm_modem                varchar(255)    DEFAULT ''                NOT NULL,
374	username                 varchar(255)    DEFAULT ''                NOT NULL,
375	passwd                   varchar(255)    DEFAULT ''                NOT NULL,
376	status                   integer         DEFAULT '0'               NOT NULL,
377	smtp_port                integer         DEFAULT '25'              NOT NULL,
378	smtp_security            integer         DEFAULT '0'               NOT NULL,
379	smtp_verify_peer         integer         DEFAULT '0'               NOT NULL,
380	smtp_verify_host         integer         DEFAULT '0'               NOT NULL,
381	smtp_authentication      integer         DEFAULT '0'               NOT NULL,
382	exec_params              varchar(255)    DEFAULT ''                NOT NULL,
383	PRIMARY KEY (mediatypeid)
384);
385CREATE UNIQUE INDEX media_type_1 ON media_type (description);
386CREATE TABLE usrgrp (
387	usrgrpid                 bigint                                    NOT NULL,
388	name                     varchar(64)     DEFAULT ''                NOT NULL,
389	gui_access               integer         DEFAULT '0'               NOT NULL,
390	users_status             integer         DEFAULT '0'               NOT NULL,
391	debug_mode               integer         DEFAULT '0'               NOT NULL,
392	PRIMARY KEY (usrgrpid)
393);
394CREATE UNIQUE INDEX usrgrp_1 ON usrgrp (name);
395CREATE TABLE users_groups (
396	id                       bigint                                    NOT NULL,
397	usrgrpid                 bigint                                    NOT NULL,
398	userid                   bigint                                    NOT NULL,
399	PRIMARY KEY (id)
400);
401CREATE UNIQUE INDEX users_groups_1 ON users_groups (usrgrpid,userid);
402CREATE INDEX users_groups_2 ON users_groups (userid);
403CREATE TABLE scripts (
404	scriptid                 bigint                                    NOT NULL,
405	name                     varchar(255)    DEFAULT ''                NOT NULL,
406	command                  varchar(255)    DEFAULT ''                NOT NULL,
407	host_access              integer         DEFAULT '2'               NOT NULL,
408	usrgrpid                 bigint                                    NULL,
409	groupid                  bigint                                    NULL,
410	description              text            DEFAULT ''                NOT NULL,
411	confirmation             varchar(255)    DEFAULT ''                NOT NULL,
412	type                     integer         DEFAULT '0'               NOT NULL,
413	execute_on               integer         DEFAULT '1'               NOT NULL,
414	PRIMARY KEY (scriptid)
415);
416CREATE INDEX scripts_1 ON scripts (usrgrpid);
417CREATE INDEX scripts_2 ON scripts (groupid);
418CREATE UNIQUE INDEX scripts_3 ON scripts (name);
419CREATE TABLE actions (
420	actionid                 bigint                                    NOT NULL,
421	name                     varchar(255)    DEFAULT ''                NOT NULL,
422	eventsource              integer         DEFAULT '0'               NOT NULL,
423	evaltype                 integer         DEFAULT '0'               NOT NULL,
424	status                   integer         DEFAULT '0'               NOT NULL,
425	esc_period               integer         DEFAULT '0'               NOT NULL,
426	def_shortdata            varchar(255)    DEFAULT ''                NOT NULL,
427	def_longdata             text            DEFAULT ''                NOT NULL,
428	recovery_msg             integer         DEFAULT '0'               NOT NULL,
429	r_shortdata              varchar(255)    DEFAULT ''                NOT NULL,
430	r_longdata               text            DEFAULT ''                NOT NULL,
431	formula                  varchar(255)    DEFAULT ''                NOT NULL,
432	PRIMARY KEY (actionid)
433);
434CREATE INDEX actions_1 ON actions (eventsource,status);
435CREATE UNIQUE INDEX actions_2 ON actions (name);
436CREATE TABLE operations (
437	operationid              bigint                                    NOT NULL,
438	actionid                 bigint                                    NOT NULL,
439	operationtype            integer         DEFAULT '0'               NOT NULL,
440	esc_period               integer         DEFAULT '0'               NOT NULL,
441	esc_step_from            integer         DEFAULT '1'               NOT NULL,
442	esc_step_to              integer         DEFAULT '1'               NOT NULL,
443	evaltype                 integer         DEFAULT '0'               NOT NULL,
444	PRIMARY KEY (operationid)
445);
446CREATE INDEX operations_1 ON operations (actionid);
447CREATE TABLE opmessage (
448	operationid              bigint                                    NOT NULL,
449	default_msg              integer         DEFAULT '0'               NOT NULL,
450	subject                  varchar(255)    DEFAULT ''                NOT NULL,
451	message                  text            DEFAULT ''                NOT NULL,
452	mediatypeid              bigint                                    NULL,
453	PRIMARY KEY (operationid)
454);
455CREATE INDEX opmessage_1 ON opmessage (mediatypeid);
456CREATE TABLE opmessage_grp (
457	opmessage_grpid          bigint                                    NOT NULL,
458	operationid              bigint                                    NOT NULL,
459	usrgrpid                 bigint                                    NOT NULL,
460	PRIMARY KEY (opmessage_grpid)
461);
462CREATE UNIQUE INDEX opmessage_grp_1 ON opmessage_grp (operationid,usrgrpid);
463CREATE INDEX opmessage_grp_2 ON opmessage_grp (usrgrpid);
464CREATE TABLE opmessage_usr (
465	opmessage_usrid          bigint                                    NOT NULL,
466	operationid              bigint                                    NOT NULL,
467	userid                   bigint                                    NOT NULL,
468	PRIMARY KEY (opmessage_usrid)
469);
470CREATE UNIQUE INDEX opmessage_usr_1 ON opmessage_usr (operationid,userid);
471CREATE INDEX opmessage_usr_2 ON opmessage_usr (userid);
472CREATE TABLE opcommand (
473	operationid              bigint                                    NOT NULL,
474	type                     integer         DEFAULT '0'               NOT NULL,
475	scriptid                 bigint                                    NULL,
476	execute_on               integer         DEFAULT '0'               NOT NULL,
477	port                     varchar(64)     DEFAULT ''                NOT NULL,
478	authtype                 integer         DEFAULT '0'               NOT NULL,
479	username                 varchar(64)     DEFAULT ''                NOT NULL,
480	password                 varchar(64)     DEFAULT ''                NOT NULL,
481	publickey                varchar(64)     DEFAULT ''                NOT NULL,
482	privatekey               varchar(64)     DEFAULT ''                NOT NULL,
483	command                  text            DEFAULT ''                NOT NULL,
484	PRIMARY KEY (operationid)
485);
486CREATE INDEX opcommand_1 ON opcommand (scriptid);
487CREATE TABLE opcommand_hst (
488	opcommand_hstid          bigint                                    NOT NULL,
489	operationid              bigint                                    NOT NULL,
490	hostid                   bigint                                    NULL,
491	PRIMARY KEY (opcommand_hstid)
492);
493CREATE INDEX opcommand_hst_1 ON opcommand_hst (operationid);
494CREATE INDEX opcommand_hst_2 ON opcommand_hst (hostid);
495CREATE TABLE opcommand_grp (
496	opcommand_grpid          bigint                                    NOT NULL,
497	operationid              bigint                                    NOT NULL,
498	groupid                  bigint                                    NOT NULL,
499	PRIMARY KEY (opcommand_grpid)
500);
501CREATE INDEX opcommand_grp_1 ON opcommand_grp (operationid);
502CREATE INDEX opcommand_grp_2 ON opcommand_grp (groupid);
503CREATE TABLE opgroup (
504	opgroupid                bigint                                    NOT NULL,
505	operationid              bigint                                    NOT NULL,
506	groupid                  bigint                                    NOT NULL,
507	PRIMARY KEY (opgroupid)
508);
509CREATE UNIQUE INDEX opgroup_1 ON opgroup (operationid,groupid);
510CREATE INDEX opgroup_2 ON opgroup (groupid);
511CREATE TABLE optemplate (
512	optemplateid             bigint                                    NOT NULL,
513	operationid              bigint                                    NOT NULL,
514	templateid               bigint                                    NOT NULL,
515	PRIMARY KEY (optemplateid)
516);
517CREATE UNIQUE INDEX optemplate_1 ON optemplate (operationid,templateid);
518CREATE INDEX optemplate_2 ON optemplate (templateid);
519CREATE TABLE opconditions (
520	opconditionid            bigint                                    NOT NULL,
521	operationid              bigint                                    NOT NULL,
522	conditiontype            integer         DEFAULT '0'               NOT NULL,
523	operator                 integer         DEFAULT '0'               NOT NULL,
524	value                    varchar(255)    DEFAULT ''                NOT NULL,
525	PRIMARY KEY (opconditionid)
526);
527CREATE INDEX opconditions_1 ON opconditions (operationid);
528CREATE TABLE conditions (
529	conditionid              bigint                                    NOT NULL,
530	actionid                 bigint                                    NOT NULL,
531	conditiontype            integer         DEFAULT '0'               NOT NULL,
532	operator                 integer         DEFAULT '0'               NOT NULL,
533	value                    varchar(255)    DEFAULT ''                NOT NULL,
534	PRIMARY KEY (conditionid)
535);
536CREATE INDEX conditions_1 ON conditions (actionid);
537CREATE TABLE config (
538	configid                 bigint                                    NOT NULL,
539	refresh_unsupported      integer         DEFAULT '0'               NOT NULL,
540	work_period              varchar(100)    DEFAULT '1-5,00:00-24:00' NOT NULL,
541	alert_usrgrpid           bigint                                    NULL,
542	event_ack_enable         integer         DEFAULT '1'               NOT NULL,
543	event_expire             integer         DEFAULT '7'               NOT NULL,
544	event_show_max           integer         DEFAULT '100'             NOT NULL,
545	default_theme            varchar(128)    DEFAULT 'blue-theme'      NOT NULL,
546	authentication_type      integer         DEFAULT '0'               NOT NULL,
547	ldap_host                varchar(255)    DEFAULT ''                NOT NULL,
548	ldap_port                integer         DEFAULT 389               NOT NULL,
549	ldap_base_dn             varchar(255)    DEFAULT ''                NOT NULL,
550	ldap_bind_dn             varchar(255)    DEFAULT ''                NOT NULL,
551	ldap_bind_password       varchar(128)    DEFAULT ''                NOT NULL,
552	ldap_search_attribute    varchar(128)    DEFAULT ''                NOT NULL,
553	dropdown_first_entry     integer         DEFAULT '1'               NOT NULL,
554	dropdown_first_remember  integer         DEFAULT '1'               NOT NULL,
555	discovery_groupid        bigint                                    NOT NULL,
556	max_in_table             integer         DEFAULT '50'              NOT NULL,
557	search_limit             integer         DEFAULT '1000'            NOT NULL,
558	severity_color_0         varchar(6)      DEFAULT '97AAB3'          NOT NULL,
559	severity_color_1         varchar(6)      DEFAULT '7499FF'          NOT NULL,
560	severity_color_2         varchar(6)      DEFAULT 'FFC859'          NOT NULL,
561	severity_color_3         varchar(6)      DEFAULT 'FFA059'          NOT NULL,
562	severity_color_4         varchar(6)      DEFAULT 'E97659'          NOT NULL,
563	severity_color_5         varchar(6)      DEFAULT 'E45959'          NOT NULL,
564	severity_name_0          varchar(32)     DEFAULT 'Not classified'  NOT NULL,
565	severity_name_1          varchar(32)     DEFAULT 'Information'     NOT NULL,
566	severity_name_2          varchar(32)     DEFAULT 'Warning'         NOT NULL,
567	severity_name_3          varchar(32)     DEFAULT 'Average'         NOT NULL,
568	severity_name_4          varchar(32)     DEFAULT 'High'            NOT NULL,
569	severity_name_5          varchar(32)     DEFAULT 'Disaster'        NOT NULL,
570	ok_period                integer         DEFAULT '1800'            NOT NULL,
571	blink_period             integer         DEFAULT '1800'            NOT NULL,
572	problem_unack_color      varchar(6)      DEFAULT 'DC0000'          NOT NULL,
573	problem_ack_color        varchar(6)      DEFAULT 'DC0000'          NOT NULL,
574	ok_unack_color           varchar(6)      DEFAULT '00AA00'          NOT NULL,
575	ok_ack_color             varchar(6)      DEFAULT '00AA00'          NOT NULL,
576	problem_unack_style      integer         DEFAULT '1'               NOT NULL,
577	problem_ack_style        integer         DEFAULT '1'               NOT NULL,
578	ok_unack_style           integer         DEFAULT '1'               NOT NULL,
579	ok_ack_style             integer         DEFAULT '1'               NOT NULL,
580	snmptrap_logging         integer         DEFAULT '1'               NOT NULL,
581	server_check_interval    integer         DEFAULT '10'              NOT NULL,
582	hk_events_mode           integer         DEFAULT '1'               NOT NULL,
583	hk_events_trigger        integer         DEFAULT '365'             NOT NULL,
584	hk_events_internal       integer         DEFAULT '365'             NOT NULL,
585	hk_events_discovery      integer         DEFAULT '365'             NOT NULL,
586	hk_events_autoreg        integer         DEFAULT '365'             NOT NULL,
587	hk_services_mode         integer         DEFAULT '1'               NOT NULL,
588	hk_services              integer         DEFAULT '365'             NOT NULL,
589	hk_audit_mode            integer         DEFAULT '1'               NOT NULL,
590	hk_audit                 integer         DEFAULT '365'             NOT NULL,
591	hk_sessions_mode         integer         DEFAULT '1'               NOT NULL,
592	hk_sessions              integer         DEFAULT '365'             NOT NULL,
593	hk_history_mode          integer         DEFAULT '1'               NOT NULL,
594	hk_history_global        integer         DEFAULT '0'               NOT NULL,
595	hk_history               integer         DEFAULT '90'              NOT NULL,
596	hk_trends_mode           integer         DEFAULT '1'               NOT NULL,
597	hk_trends_global         integer         DEFAULT '0'               NOT NULL,
598	hk_trends                integer         DEFAULT '365'             NOT NULL,
599	default_inventory_mode   integer         DEFAULT '-1'              NOT NULL,
600	PRIMARY KEY (configid)
601);
602CREATE INDEX config_1 ON config (alert_usrgrpid);
603CREATE INDEX config_2 ON config (discovery_groupid);
604CREATE TABLE triggers (
605	triggerid                bigint                                    NOT NULL,
606	expression               varchar(2048)   DEFAULT ''                NOT NULL,
607	description              varchar(255)    DEFAULT ''                NOT NULL,
608	url                      varchar(255)    DEFAULT ''                NOT NULL,
609	status                   integer         DEFAULT '0'               NOT NULL,
610	value                    integer         DEFAULT '0'               NOT NULL,
611	priority                 integer         DEFAULT '0'               NOT NULL,
612	lastchange               integer         DEFAULT '0'               NOT NULL,
613	comments                 text            DEFAULT ''                NOT NULL,
614	error                    varchar(128)    DEFAULT ''                NOT NULL,
615	templateid               bigint                                    NULL,
616	type                     integer         DEFAULT '0'               NOT NULL,
617	state                    integer         DEFAULT '0'               NOT NULL,
618	flags                    integer         DEFAULT '0'               NOT NULL,
619	PRIMARY KEY (triggerid)
620);
621CREATE INDEX triggers_1 ON triggers (status);
622CREATE INDEX triggers_2 ON triggers (value,lastchange);
623CREATE INDEX triggers_3 ON triggers (templateid);
624CREATE TABLE trigger_depends (
625	triggerdepid             bigint                                    NOT NULL,
626	triggerid_down           bigint                                    NOT NULL,
627	triggerid_up             bigint                                    NOT NULL,
628	PRIMARY KEY (triggerdepid)
629);
630CREATE UNIQUE INDEX trigger_depends_1 ON trigger_depends (triggerid_down,triggerid_up);
631CREATE INDEX trigger_depends_2 ON trigger_depends (triggerid_up);
632CREATE TABLE functions (
633	functionid               bigint                                    NOT NULL,
634	itemid                   bigint                                    NOT NULL,
635	triggerid                bigint                                    NOT NULL,
636	function                 varchar(12)     DEFAULT ''                NOT NULL,
637	parameter                varchar(255)    DEFAULT '0'               NOT NULL,
638	PRIMARY KEY (functionid)
639);
640CREATE INDEX functions_1 ON functions (triggerid);
641CREATE INDEX functions_2 ON functions (itemid,function,parameter);
642CREATE TABLE graphs (
643	graphid                  bigint                                    NOT NULL,
644	name                     varchar(128)    DEFAULT ''                NOT NULL,
645	width                    integer         DEFAULT '900'             NOT NULL,
646	height                   integer         DEFAULT '200'             NOT NULL,
647	yaxismin                 numeric(16,4)   DEFAULT '0'               NOT NULL,
648	yaxismax                 numeric(16,4)   DEFAULT '100'             NOT NULL,
649	templateid               bigint                                    NULL,
650	show_work_period         integer         DEFAULT '1'               NOT NULL,
651	show_triggers            integer         DEFAULT '1'               NOT NULL,
652	graphtype                integer         DEFAULT '0'               NOT NULL,
653	show_legend              integer         DEFAULT '1'               NOT NULL,
654	show_3d                  integer         DEFAULT '0'               NOT NULL,
655	percent_left             numeric(16,4)   DEFAULT '0'               NOT NULL,
656	percent_right            numeric(16,4)   DEFAULT '0'               NOT NULL,
657	ymin_type                integer         DEFAULT '0'               NOT NULL,
658	ymax_type                integer         DEFAULT '0'               NOT NULL,
659	ymin_itemid              bigint                                    NULL,
660	ymax_itemid              bigint                                    NULL,
661	flags                    integer         DEFAULT '0'               NOT NULL,
662	PRIMARY KEY (graphid)
663);
664CREATE INDEX graphs_1 ON graphs (name);
665CREATE INDEX graphs_2 ON graphs (templateid);
666CREATE INDEX graphs_3 ON graphs (ymin_itemid);
667CREATE INDEX graphs_4 ON graphs (ymax_itemid);
668CREATE TABLE graphs_items (
669	gitemid                  bigint                                    NOT NULL,
670	graphid                  bigint                                    NOT NULL,
671	itemid                   bigint                                    NOT NULL,
672	drawtype                 integer         DEFAULT '0'               NOT NULL,
673	sortorder                integer         DEFAULT '0'               NOT NULL,
674	color                    varchar(6)      DEFAULT '009600'          NOT NULL,
675	yaxisside                integer         DEFAULT '0'               NOT NULL,
676	calc_fnc                 integer         DEFAULT '2'               NOT NULL,
677	type                     integer         DEFAULT '0'               NOT NULL,
678	PRIMARY KEY (gitemid)
679);
680CREATE INDEX graphs_items_1 ON graphs_items (itemid);
681CREATE INDEX graphs_items_2 ON graphs_items (graphid);
682CREATE TABLE graph_theme (
683	graphthemeid             bigint                                    NOT NULL,
684	theme                    varchar(64)     DEFAULT ''                NOT NULL,
685	backgroundcolor          varchar(6)      DEFAULT ''                NOT NULL,
686	graphcolor               varchar(6)      DEFAULT ''                NOT NULL,
687	gridcolor                varchar(6)      DEFAULT ''                NOT NULL,
688	maingridcolor            varchar(6)      DEFAULT ''                NOT NULL,
689	gridbordercolor          varchar(6)      DEFAULT ''                NOT NULL,
690	textcolor                varchar(6)      DEFAULT ''                NOT NULL,
691	highlightcolor           varchar(6)      DEFAULT ''                NOT NULL,
692	leftpercentilecolor      varchar(6)      DEFAULT ''                NOT NULL,
693	rightpercentilecolor     varchar(6)      DEFAULT ''                NOT NULL,
694	nonworktimecolor         varchar(6)      DEFAULT ''                NOT NULL,
695	PRIMARY KEY (graphthemeid)
696);
697CREATE UNIQUE INDEX graph_theme_1 ON graph_theme (theme);
698CREATE TABLE globalmacro (
699	globalmacroid            bigint                                    NOT NULL,
700	macro                    varchar(255)    DEFAULT ''                NOT NULL,
701	value                    varchar(255)    DEFAULT ''                NOT NULL,
702	PRIMARY KEY (globalmacroid)
703);
704CREATE UNIQUE INDEX globalmacro_1 ON globalmacro (macro);
705CREATE TABLE hostmacro (
706	hostmacroid              bigint                                    NOT NULL,
707	hostid                   bigint                                    NOT NULL,
708	macro                    varchar(255)    DEFAULT ''                NOT NULL,
709	value                    varchar(255)    DEFAULT ''                NOT NULL,
710	PRIMARY KEY (hostmacroid)
711);
712CREATE UNIQUE INDEX hostmacro_1 ON hostmacro (hostid,macro);
713CREATE TABLE hosts_groups (
714	hostgroupid              bigint                                    NOT NULL,
715	hostid                   bigint                                    NOT NULL,
716	groupid                  bigint                                    NOT NULL,
717	PRIMARY KEY (hostgroupid)
718);
719CREATE UNIQUE INDEX hosts_groups_1 ON hosts_groups (hostid,groupid);
720CREATE INDEX hosts_groups_2 ON hosts_groups (groupid);
721CREATE TABLE hosts_templates (
722	hosttemplateid           bigint                                    NOT NULL,
723	hostid                   bigint                                    NOT NULL,
724	templateid               bigint                                    NOT NULL,
725	PRIMARY KEY (hosttemplateid)
726);
727CREATE UNIQUE INDEX hosts_templates_1 ON hosts_templates (hostid,templateid);
728CREATE INDEX hosts_templates_2 ON hosts_templates (templateid);
729CREATE TABLE items_applications (
730	itemappid                bigint                                    NOT NULL,
731	applicationid            bigint                                    NOT NULL,
732	itemid                   bigint                                    NOT NULL,
733	PRIMARY KEY (itemappid)
734);
735CREATE UNIQUE INDEX items_applications_1 ON items_applications (applicationid,itemid);
736CREATE INDEX items_applications_2 ON items_applications (itemid);
737CREATE TABLE mappings (
738	mappingid                bigint                                    NOT NULL,
739	valuemapid               bigint                                    NOT NULL,
740	value                    varchar(64)     DEFAULT ''                NOT NULL,
741	newvalue                 varchar(64)     DEFAULT ''                NOT NULL,
742	PRIMARY KEY (mappingid)
743);
744CREATE INDEX mappings_1 ON mappings (valuemapid);
745CREATE TABLE media (
746	mediaid                  bigint                                    NOT NULL,
747	userid                   bigint                                    NOT NULL,
748	mediatypeid              bigint                                    NOT NULL,
749	sendto                   varchar(100)    DEFAULT ''                NOT NULL,
750	active                   integer         DEFAULT '0'               NOT NULL,
751	severity                 integer         DEFAULT '63'              NOT NULL,
752	period                   varchar(100)    DEFAULT '1-7,00:00-24:00' NOT NULL,
753	PRIMARY KEY (mediaid)
754);
755CREATE INDEX media_1 ON media (userid);
756CREATE INDEX media_2 ON media (mediatypeid);
757CREATE TABLE rights (
758	rightid                  bigint                                    NOT NULL,
759	groupid                  bigint                                    NOT NULL,
760	permission               integer         DEFAULT '0'               NOT NULL,
761	id                       bigint                                    NOT NULL,
762	PRIMARY KEY (rightid)
763);
764CREATE INDEX rights_1 ON rights (groupid);
765CREATE INDEX rights_2 ON rights (id);
766CREATE TABLE services (
767	serviceid                bigint                                    NOT NULL,
768	name                     varchar(128)    DEFAULT ''                NOT NULL,
769	status                   integer         DEFAULT '0'               NOT NULL,
770	algorithm                integer         DEFAULT '0'               NOT NULL,
771	triggerid                bigint                                    NULL,
772	showsla                  integer         DEFAULT '0'               NOT NULL,
773	goodsla                  numeric(16,4)   DEFAULT '99.9'            NOT NULL,
774	sortorder                integer         DEFAULT '0'               NOT NULL,
775	PRIMARY KEY (serviceid)
776);
777CREATE INDEX services_1 ON services (triggerid);
778CREATE TABLE services_links (
779	linkid                   bigint                                    NOT NULL,
780	serviceupid              bigint                                    NOT NULL,
781	servicedownid            bigint                                    NOT NULL,
782	soft                     integer         DEFAULT '0'               NOT NULL,
783	PRIMARY KEY (linkid)
784);
785CREATE INDEX services_links_1 ON services_links (servicedownid);
786CREATE UNIQUE INDEX services_links_2 ON services_links (serviceupid,servicedownid);
787CREATE TABLE services_times (
788	timeid                   bigint                                    NOT NULL,
789	serviceid                bigint                                    NOT NULL,
790	type                     integer         DEFAULT '0'               NOT NULL,
791	ts_from                  integer         DEFAULT '0'               NOT NULL,
792	ts_to                    integer         DEFAULT '0'               NOT NULL,
793	note                     varchar(255)    DEFAULT ''                NOT NULL,
794	PRIMARY KEY (timeid)
795);
796CREATE INDEX services_times_1 ON services_times (serviceid,type,ts_from,ts_to);
797CREATE TABLE icon_map (
798	iconmapid                bigint                                    NOT NULL,
799	name                     varchar(64)     DEFAULT ''                NOT NULL,
800	default_iconid           bigint                                    NOT NULL,
801	PRIMARY KEY (iconmapid)
802);
803CREATE UNIQUE INDEX icon_map_1 ON icon_map (name);
804CREATE INDEX icon_map_2 ON icon_map (default_iconid);
805CREATE TABLE icon_mapping (
806	iconmappingid            bigint                                    NOT NULL,
807	iconmapid                bigint                                    NOT NULL,
808	iconid                   bigint                                    NOT NULL,
809	inventory_link           integer         DEFAULT '0'               NOT NULL,
810	expression               varchar(64)     DEFAULT ''                NOT NULL,
811	sortorder                integer         DEFAULT '0'               NOT NULL,
812	PRIMARY KEY (iconmappingid)
813);
814CREATE INDEX icon_mapping_1 ON icon_mapping (iconmapid);
815CREATE INDEX icon_mapping_2 ON icon_mapping (iconid);
816CREATE TABLE sysmaps (
817	sysmapid                 bigint                                    NOT NULL,
818	name                     varchar(128)    DEFAULT ''                NOT NULL,
819	width                    integer         DEFAULT '600'             NOT NULL,
820	height                   integer         DEFAULT '400'             NOT NULL,
821	backgroundid             bigint                                    NULL,
822	label_type               integer         DEFAULT '2'               NOT NULL,
823	label_location           integer         DEFAULT '0'               NOT NULL,
824	highlight                integer         DEFAULT '1'               NOT NULL,
825	expandproblem            integer         DEFAULT '1'               NOT NULL,
826	markelements             integer         DEFAULT '0'               NOT NULL,
827	show_unack               integer         DEFAULT '0'               NOT NULL,
828	grid_size                integer         DEFAULT '50'              NOT NULL,
829	grid_show                integer         DEFAULT '1'               NOT NULL,
830	grid_align               integer         DEFAULT '1'               NOT NULL,
831	label_format             integer         DEFAULT '0'               NOT NULL,
832	label_type_host          integer         DEFAULT '2'               NOT NULL,
833	label_type_hostgroup     integer         DEFAULT '2'               NOT NULL,
834	label_type_trigger       integer         DEFAULT '2'               NOT NULL,
835	label_type_map           integer         DEFAULT '2'               NOT NULL,
836	label_type_image         integer         DEFAULT '2'               NOT NULL,
837	label_string_host        varchar(255)    DEFAULT ''                NOT NULL,
838	label_string_hostgroup   varchar(255)    DEFAULT ''                NOT NULL,
839	label_string_trigger     varchar(255)    DEFAULT ''                NOT NULL,
840	label_string_map         varchar(255)    DEFAULT ''                NOT NULL,
841	label_string_image       varchar(255)    DEFAULT ''                NOT NULL,
842	iconmapid                bigint                                    NULL,
843	expand_macros            integer         DEFAULT '0'               NOT NULL,
844	severity_min             integer         DEFAULT '0'               NOT NULL,
845	userid                   bigint                                    NOT NULL,
846	private                  integer         DEFAULT '1'               NOT NULL,
847	PRIMARY KEY (sysmapid)
848);
849CREATE UNIQUE INDEX sysmaps_1 ON sysmaps (name);
850CREATE INDEX sysmaps_2 ON sysmaps (backgroundid);
851CREATE INDEX sysmaps_3 ON sysmaps (iconmapid);
852CREATE TABLE sysmaps_elements (
853	selementid               bigint                                    NOT NULL,
854	sysmapid                 bigint                                    NOT NULL,
855	elementid                bigint          DEFAULT '0'               NOT NULL,
856	elementtype              integer         DEFAULT '0'               NOT NULL,
857	iconid_off               bigint                                    NULL,
858	iconid_on                bigint                                    NULL,
859	label                    varchar(2048)   DEFAULT ''                NOT NULL,
860	label_location           integer         DEFAULT '-1'              NOT NULL,
861	x                        integer         DEFAULT '0'               NOT NULL,
862	y                        integer         DEFAULT '0'               NOT NULL,
863	iconid_disabled          bigint                                    NULL,
864	iconid_maintenance       bigint                                    NULL,
865	elementsubtype           integer         DEFAULT '0'               NOT NULL,
866	areatype                 integer         DEFAULT '0'               NOT NULL,
867	width                    integer         DEFAULT '200'             NOT NULL,
868	height                   integer         DEFAULT '200'             NOT NULL,
869	viewtype                 integer         DEFAULT '0'               NOT NULL,
870	use_iconmap              integer         DEFAULT '1'               NOT NULL,
871	application              varchar(255)    DEFAULT ''                NOT NULL,
872	PRIMARY KEY (selementid)
873);
874CREATE INDEX sysmaps_elements_1 ON sysmaps_elements (sysmapid);
875CREATE INDEX sysmaps_elements_2 ON sysmaps_elements (iconid_off);
876CREATE INDEX sysmaps_elements_3 ON sysmaps_elements (iconid_on);
877CREATE INDEX sysmaps_elements_4 ON sysmaps_elements (iconid_disabled);
878CREATE INDEX sysmaps_elements_5 ON sysmaps_elements (iconid_maintenance);
879CREATE TABLE sysmaps_links (
880	linkid                   bigint                                    NOT NULL,
881	sysmapid                 bigint                                    NOT NULL,
882	selementid1              bigint                                    NOT NULL,
883	selementid2              bigint                                    NOT NULL,
884	drawtype                 integer         DEFAULT '0'               NOT NULL,
885	color                    varchar(6)      DEFAULT '000000'          NOT NULL,
886	label                    varchar(2048)   DEFAULT ''                NOT NULL,
887	PRIMARY KEY (linkid)
888);
889CREATE INDEX sysmaps_links_1 ON sysmaps_links (sysmapid);
890CREATE INDEX sysmaps_links_2 ON sysmaps_links (selementid1);
891CREATE INDEX sysmaps_links_3 ON sysmaps_links (selementid2);
892CREATE TABLE sysmaps_link_triggers (
893	linktriggerid            bigint                                    NOT NULL,
894	linkid                   bigint                                    NOT NULL,
895	triggerid                bigint                                    NOT NULL,
896	drawtype                 integer         DEFAULT '0'               NOT NULL,
897	color                    varchar(6)      DEFAULT '000000'          NOT NULL,
898	PRIMARY KEY (linktriggerid)
899);
900CREATE UNIQUE INDEX sysmaps_link_triggers_1 ON sysmaps_link_triggers (linkid,triggerid);
901CREATE INDEX sysmaps_link_triggers_2 ON sysmaps_link_triggers (triggerid);
902CREATE TABLE sysmap_element_url (
903	sysmapelementurlid       bigint                                    NOT NULL,
904	selementid               bigint                                    NOT NULL,
905	name                     varchar(255)                              NOT NULL,
906	url                      varchar(255)    DEFAULT ''                NOT NULL,
907	PRIMARY KEY (sysmapelementurlid)
908);
909CREATE UNIQUE INDEX sysmap_element_url_1 ON sysmap_element_url (selementid,name);
910CREATE TABLE sysmap_url (
911	sysmapurlid              bigint                                    NOT NULL,
912	sysmapid                 bigint                                    NOT NULL,
913	name                     varchar(255)                              NOT NULL,
914	url                      varchar(255)    DEFAULT ''                NOT NULL,
915	elementtype              integer         DEFAULT '0'               NOT NULL,
916	PRIMARY KEY (sysmapurlid)
917);
918CREATE UNIQUE INDEX sysmap_url_1 ON sysmap_url (sysmapid,name);
919CREATE TABLE sysmap_user (
920	sysmapuserid             bigint                                    NOT NULL,
921	sysmapid                 bigint                                    NOT NULL,
922	userid                   bigint                                    NOT NULL,
923	permission               integer         DEFAULT '2'               NOT NULL,
924	PRIMARY KEY (sysmapuserid)
925);
926CREATE UNIQUE INDEX sysmap_user_1 ON sysmap_user (sysmapid,userid);
927CREATE TABLE sysmap_usrgrp (
928	sysmapusrgrpid           bigint                                    NOT NULL,
929	sysmapid                 bigint                                    NOT NULL,
930	usrgrpid                 bigint                                    NOT NULL,
931	permission               integer         DEFAULT '2'               NOT NULL,
932	PRIMARY KEY (sysmapusrgrpid)
933);
934CREATE UNIQUE INDEX sysmap_usrgrp_1 ON sysmap_usrgrp (sysmapid,usrgrpid);
935CREATE TABLE maintenances_hosts (
936	maintenance_hostid       bigint                                    NOT NULL,
937	maintenanceid            bigint                                    NOT NULL,
938	hostid                   bigint                                    NOT NULL,
939	PRIMARY KEY (maintenance_hostid)
940);
941CREATE UNIQUE INDEX maintenances_hosts_1 ON maintenances_hosts (maintenanceid,hostid);
942CREATE INDEX maintenances_hosts_2 ON maintenances_hosts (hostid);
943CREATE TABLE maintenances_groups (
944	maintenance_groupid      bigint                                    NOT NULL,
945	maintenanceid            bigint                                    NOT NULL,
946	groupid                  bigint                                    NOT NULL,
947	PRIMARY KEY (maintenance_groupid)
948);
949CREATE UNIQUE INDEX maintenances_groups_1 ON maintenances_groups (maintenanceid,groupid);
950CREATE INDEX maintenances_groups_2 ON maintenances_groups (groupid);
951CREATE TABLE timeperiods (
952	timeperiodid             bigint                                    NOT NULL,
953	timeperiod_type          integer         DEFAULT '0'               NOT NULL,
954	every                    integer         DEFAULT '1'               NOT NULL,
955	month                    integer         DEFAULT '0'               NOT NULL,
956	dayofweek                integer         DEFAULT '0'               NOT NULL,
957	day                      integer         DEFAULT '0'               NOT NULL,
958	start_time               integer         DEFAULT '0'               NOT NULL,
959	period                   integer         DEFAULT '0'               NOT NULL,
960	start_date               integer         DEFAULT '0'               NOT NULL,
961	PRIMARY KEY (timeperiodid)
962);
963CREATE TABLE maintenances_windows (
964	maintenance_timeperiodid bigint                                    NOT NULL,
965	maintenanceid            bigint                                    NOT NULL,
966	timeperiodid             bigint                                    NOT NULL,
967	PRIMARY KEY (maintenance_timeperiodid)
968);
969CREATE UNIQUE INDEX maintenances_windows_1 ON maintenances_windows (maintenanceid,timeperiodid);
970CREATE INDEX maintenances_windows_2 ON maintenances_windows (timeperiodid);
971CREATE TABLE regexps (
972	regexpid                 bigint                                    NOT NULL,
973	name                     varchar(128)    DEFAULT ''                NOT NULL,
974	test_string              text            DEFAULT ''                NOT NULL,
975	PRIMARY KEY (regexpid)
976);
977CREATE UNIQUE INDEX regexps_1 ON regexps (name);
978CREATE TABLE expressions (
979	expressionid             bigint                                    NOT NULL,
980	regexpid                 bigint                                    NOT NULL,
981	expression               varchar(255)    DEFAULT ''                NOT NULL,
982	expression_type          integer         DEFAULT '0'               NOT NULL,
983	exp_delimiter            varchar(1)      DEFAULT ''                NOT NULL,
984	case_sensitive           integer         DEFAULT '0'               NOT NULL,
985	PRIMARY KEY (expressionid)
986);
987CREATE INDEX expressions_1 ON expressions (regexpid);
988CREATE TABLE ids (
989	table_name               varchar(64)     DEFAULT ''                NOT NULL,
990	field_name               varchar(64)     DEFAULT ''                NOT NULL,
991	nextid                   bigint                                    NOT NULL,
992	PRIMARY KEY (table_name,field_name)
993);
994CREATE TABLE alerts (
995	alertid                  bigint                                    NOT NULL,
996	actionid                 bigint                                    NOT NULL,
997	eventid                  bigint                                    NOT NULL,
998	userid                   bigint                                    NULL,
999	clock                    integer         DEFAULT '0'               NOT NULL,
1000	mediatypeid              bigint                                    NULL,
1001	sendto                   varchar(100)    DEFAULT ''                NOT NULL,
1002	subject                  varchar(255)    DEFAULT ''                NOT NULL,
1003	message                  text            DEFAULT ''                NOT NULL,
1004	status                   integer         DEFAULT '0'               NOT NULL,
1005	retries                  integer         DEFAULT '0'               NOT NULL,
1006	error                    varchar(128)    DEFAULT ''                NOT NULL,
1007	esc_step                 integer         DEFAULT '0'               NOT NULL,
1008	alerttype                integer         DEFAULT '0'               NOT NULL,
1009	PRIMARY KEY (alertid)
1010);
1011CREATE INDEX alerts_1 ON alerts (actionid);
1012CREATE INDEX alerts_2 ON alerts (clock);
1013CREATE INDEX alerts_3 ON alerts (eventid);
1014CREATE INDEX alerts_4 ON alerts (status,retries);
1015CREATE INDEX alerts_5 ON alerts (mediatypeid);
1016CREATE INDEX alerts_6 ON alerts (userid);
1017CREATE TABLE history (
1018	itemid                   bigint                                    NOT NULL,
1019	clock                    integer         DEFAULT '0'               NOT NULL,
1020	value                    numeric(16,4)   DEFAULT '0.0000'          NOT NULL,
1021	ns                       integer         DEFAULT '0'               NOT NULL
1022);
1023CREATE INDEX history_1 ON history (itemid,clock);
1024CREATE TABLE history_uint (
1025	itemid                   bigint                                    NOT NULL,
1026	clock                    integer         DEFAULT '0'               NOT NULL,
1027	value                    numeric(20)     DEFAULT '0'               NOT NULL,
1028	ns                       integer         DEFAULT '0'               NOT NULL
1029);
1030CREATE INDEX history_uint_1 ON history_uint (itemid,clock);
1031CREATE TABLE history_str (
1032	itemid                   bigint                                    NOT NULL,
1033	clock                    integer         DEFAULT '0'               NOT NULL,
1034	value                    varchar(255)    DEFAULT ''                NOT NULL,
1035	ns                       integer         DEFAULT '0'               NOT NULL
1036);
1037CREATE INDEX history_str_1 ON history_str (itemid,clock);
1038CREATE TABLE history_log (
1039	id                       bigint                                    NOT NULL,
1040	itemid                   bigint                                    NOT NULL,
1041	clock                    integer         DEFAULT '0'               NOT NULL,
1042	timestamp                integer         DEFAULT '0'               NOT NULL,
1043	source                   varchar(64)     DEFAULT ''                NOT NULL,
1044	severity                 integer         DEFAULT '0'               NOT NULL,
1045	value                    text            DEFAULT ''                NOT NULL,
1046	logeventid               integer         DEFAULT '0'               NOT NULL,
1047	ns                       integer         DEFAULT '0'               NOT NULL,
1048	PRIMARY KEY (id)
1049);
1050CREATE INDEX history_log_1 ON history_log (itemid,clock);
1051CREATE UNIQUE INDEX history_log_2 ON history_log (itemid,id);
1052CREATE TABLE history_text (
1053	id                       bigint                                    NOT NULL,
1054	itemid                   bigint                                    NOT NULL,
1055	clock                    integer         DEFAULT '0'               NOT NULL,
1056	value                    text            DEFAULT ''                NOT NULL,
1057	ns                       integer         DEFAULT '0'               NOT NULL,
1058	PRIMARY KEY (id)
1059);
1060CREATE INDEX history_text_1 ON history_text (itemid,clock);
1061CREATE UNIQUE INDEX history_text_2 ON history_text (itemid,id);
1062CREATE TABLE proxy_history (
1063	id                       bigserial                                 NOT NULL,
1064	itemid                   bigint                                    NOT NULL,
1065	clock                    integer         DEFAULT '0'               NOT NULL,
1066	timestamp                integer         DEFAULT '0'               NOT NULL,
1067	source                   varchar(64)     DEFAULT ''                NOT NULL,
1068	severity                 integer         DEFAULT '0'               NOT NULL,
1069	value                    text            DEFAULT ''                NOT NULL,
1070	logeventid               integer         DEFAULT '0'               NOT NULL,
1071	ns                       integer         DEFAULT '0'               NOT NULL,
1072	state                    integer         DEFAULT '0'               NOT NULL,
1073	lastlogsize              numeric(20)     DEFAULT '0'               NOT NULL,
1074	mtime                    integer         DEFAULT '0'               NOT NULL,
1075	flags                    integer         DEFAULT '0'               NOT NULL,
1076	PRIMARY KEY (id)
1077);
1078CREATE INDEX proxy_history_1 ON proxy_history (clock);
1079CREATE TABLE proxy_dhistory (
1080	id                       bigserial                                 NOT NULL,
1081	clock                    integer         DEFAULT '0'               NOT NULL,
1082	druleid                  bigint                                    NOT NULL,
1083	type                     integer         DEFAULT '0'               NOT NULL,
1084	ip                       varchar(39)     DEFAULT ''                NOT NULL,
1085	port                     integer         DEFAULT '0'               NOT NULL,
1086	key_                     varchar(255)    DEFAULT ''                NOT NULL,
1087	value                    varchar(255)    DEFAULT ''                NOT NULL,
1088	status                   integer         DEFAULT '0'               NOT NULL,
1089	dcheckid                 bigint                                    NULL,
1090	dns                      varchar(64)     DEFAULT ''                NOT NULL,
1091	PRIMARY KEY (id)
1092);
1093CREATE INDEX proxy_dhistory_1 ON proxy_dhistory (clock);
1094CREATE TABLE events (
1095	eventid                  bigint                                    NOT NULL,
1096	source                   integer         DEFAULT '0'               NOT NULL,
1097	object                   integer         DEFAULT '0'               NOT NULL,
1098	objectid                 bigint          DEFAULT '0'               NOT NULL,
1099	clock                    integer         DEFAULT '0'               NOT NULL,
1100	value                    integer         DEFAULT '0'               NOT NULL,
1101	acknowledged             integer         DEFAULT '0'               NOT NULL,
1102	ns                       integer         DEFAULT '0'               NOT NULL,
1103	PRIMARY KEY (eventid)
1104);
1105CREATE INDEX events_1 ON events (source,object,objectid,clock);
1106CREATE INDEX events_2 ON events (source,object,clock);
1107CREATE TABLE trends (
1108	itemid                   bigint                                    NOT NULL,
1109	clock                    integer         DEFAULT '0'               NOT NULL,
1110	num                      integer         DEFAULT '0'               NOT NULL,
1111	value_min                numeric(16,4)   DEFAULT '0.0000'          NOT NULL,
1112	value_avg                numeric(16,4)   DEFAULT '0.0000'          NOT NULL,
1113	value_max                numeric(16,4)   DEFAULT '0.0000'          NOT NULL,
1114	PRIMARY KEY (itemid,clock)
1115);
1116CREATE TABLE trends_uint (
1117	itemid                   bigint                                    NOT NULL,
1118	clock                    integer         DEFAULT '0'               NOT NULL,
1119	num                      integer         DEFAULT '0'               NOT NULL,
1120	value_min                numeric(20)     DEFAULT '0'               NOT NULL,
1121	value_avg                numeric(20)     DEFAULT '0'               NOT NULL,
1122	value_max                numeric(20)     DEFAULT '0'               NOT NULL,
1123	PRIMARY KEY (itemid,clock)
1124);
1125CREATE TABLE acknowledges (
1126	acknowledgeid            bigint                                    NOT NULL,
1127	userid                   bigint                                    NOT NULL,
1128	eventid                  bigint                                    NOT NULL,
1129	clock                    integer         DEFAULT '0'               NOT NULL,
1130	message                  varchar(255)    DEFAULT ''                NOT NULL,
1131	PRIMARY KEY (acknowledgeid)
1132);
1133CREATE INDEX acknowledges_1 ON acknowledges (userid);
1134CREATE INDEX acknowledges_2 ON acknowledges (eventid);
1135CREATE INDEX acknowledges_3 ON acknowledges (clock);
1136CREATE TABLE auditlog (
1137	auditid                  bigint                                    NOT NULL,
1138	userid                   bigint                                    NOT NULL,
1139	clock                    integer         DEFAULT '0'               NOT NULL,
1140	action                   integer         DEFAULT '0'               NOT NULL,
1141	resourcetype             integer         DEFAULT '0'               NOT NULL,
1142	details                  varchar(128)    DEFAULT '0'               NOT NULL,
1143	ip                       varchar(39)     DEFAULT ''                NOT NULL,
1144	resourceid               bigint          DEFAULT '0'               NOT NULL,
1145	resourcename             varchar(255)    DEFAULT ''                NOT NULL,
1146	PRIMARY KEY (auditid)
1147);
1148CREATE INDEX auditlog_1 ON auditlog (userid,clock);
1149CREATE INDEX auditlog_2 ON auditlog (clock);
1150CREATE TABLE auditlog_details (
1151	auditdetailid            bigint                                    NOT NULL,
1152	auditid                  bigint                                    NOT NULL,
1153	table_name               varchar(64)     DEFAULT ''                NOT NULL,
1154	field_name               varchar(64)     DEFAULT ''                NOT NULL,
1155	oldvalue                 text            DEFAULT ''                NOT NULL,
1156	newvalue                 text            DEFAULT ''                NOT NULL,
1157	PRIMARY KEY (auditdetailid)
1158);
1159CREATE INDEX auditlog_details_1 ON auditlog_details (auditid);
1160CREATE TABLE service_alarms (
1161	servicealarmid           bigint                                    NOT NULL,
1162	serviceid                bigint                                    NOT NULL,
1163	clock                    integer         DEFAULT '0'               NOT NULL,
1164	value                    integer         DEFAULT '0'               NOT NULL,
1165	PRIMARY KEY (servicealarmid)
1166);
1167CREATE INDEX service_alarms_1 ON service_alarms (serviceid,clock);
1168CREATE INDEX service_alarms_2 ON service_alarms (clock);
1169CREATE TABLE autoreg_host (
1170	autoreg_hostid           bigint                                    NOT NULL,
1171	proxy_hostid             bigint                                    NULL,
1172	host                     varchar(64)     DEFAULT ''                NOT NULL,
1173	listen_ip                varchar(39)     DEFAULT ''                NOT NULL,
1174	listen_port              integer         DEFAULT '0'               NOT NULL,
1175	listen_dns               varchar(64)     DEFAULT ''                NOT NULL,
1176	host_metadata            varchar(255)    DEFAULT ''                NOT NULL,
1177	PRIMARY KEY (autoreg_hostid)
1178);
1179CREATE INDEX autoreg_host_1 ON autoreg_host (proxy_hostid,host);
1180CREATE TABLE proxy_autoreg_host (
1181	id                       bigserial                                 NOT NULL,
1182	clock                    integer         DEFAULT '0'               NOT NULL,
1183	host                     varchar(64)     DEFAULT ''                NOT NULL,
1184	listen_ip                varchar(39)     DEFAULT ''                NOT NULL,
1185	listen_port              integer         DEFAULT '0'               NOT NULL,
1186	listen_dns               varchar(64)     DEFAULT ''                NOT NULL,
1187	host_metadata            varchar(255)    DEFAULT ''                NOT NULL,
1188	PRIMARY KEY (id)
1189);
1190CREATE INDEX proxy_autoreg_host_1 ON proxy_autoreg_host (clock);
1191CREATE TABLE dhosts (
1192	dhostid                  bigint                                    NOT NULL,
1193	druleid                  bigint                                    NOT NULL,
1194	status                   integer         DEFAULT '0'               NOT NULL,
1195	lastup                   integer         DEFAULT '0'               NOT NULL,
1196	lastdown                 integer         DEFAULT '0'               NOT NULL,
1197	PRIMARY KEY (dhostid)
1198);
1199CREATE INDEX dhosts_1 ON dhosts (druleid);
1200CREATE TABLE dservices (
1201	dserviceid               bigint                                    NOT NULL,
1202	dhostid                  bigint                                    NOT NULL,
1203	type                     integer         DEFAULT '0'               NOT NULL,
1204	key_                     varchar(255)    DEFAULT ''                NOT NULL,
1205	value                    varchar(255)    DEFAULT ''                NOT NULL,
1206	port                     integer         DEFAULT '0'               NOT NULL,
1207	status                   integer         DEFAULT '0'               NOT NULL,
1208	lastup                   integer         DEFAULT '0'               NOT NULL,
1209	lastdown                 integer         DEFAULT '0'               NOT NULL,
1210	dcheckid                 bigint                                    NOT NULL,
1211	ip                       varchar(39)     DEFAULT ''                NOT NULL,
1212	dns                      varchar(64)     DEFAULT ''                NOT NULL,
1213	PRIMARY KEY (dserviceid)
1214);
1215CREATE UNIQUE INDEX dservices_1 ON dservices (dcheckid,type,key_,ip,port);
1216CREATE INDEX dservices_2 ON dservices (dhostid);
1217CREATE TABLE escalations (
1218	escalationid             bigint                                    NOT NULL,
1219	actionid                 bigint                                    NOT NULL,
1220	triggerid                bigint                                    NULL,
1221	eventid                  bigint                                    NULL,
1222	r_eventid                bigint                                    NULL,
1223	nextcheck                integer         DEFAULT '0'               NOT NULL,
1224	esc_step                 integer         DEFAULT '0'               NOT NULL,
1225	status                   integer         DEFAULT '0'               NOT NULL,
1226	itemid                   bigint                                    NULL,
1227	PRIMARY KEY (escalationid)
1228);
1229CREATE UNIQUE INDEX escalations_1 ON escalations (actionid,triggerid,itemid,escalationid);
1230CREATE TABLE globalvars (
1231	globalvarid              bigint                                    NOT NULL,
1232	snmp_lastsize            integer         DEFAULT '0'               NOT NULL,
1233	PRIMARY KEY (globalvarid)
1234);
1235CREATE TABLE graph_discovery (
1236	graphid                  bigint                                    NOT NULL,
1237	parent_graphid           bigint                                    NOT NULL,
1238	PRIMARY KEY (graphid)
1239);
1240CREATE INDEX graph_discovery_1 ON graph_discovery (parent_graphid);
1241CREATE TABLE host_inventory (
1242	hostid                   bigint                                    NOT NULL,
1243	inventory_mode           integer         DEFAULT '0'               NOT NULL,
1244	type                     varchar(64)     DEFAULT ''                NOT NULL,
1245	type_full                varchar(64)     DEFAULT ''                NOT NULL,
1246	name                     varchar(64)     DEFAULT ''                NOT NULL,
1247	alias                    varchar(64)     DEFAULT ''                NOT NULL,
1248	os                       varchar(64)     DEFAULT ''                NOT NULL,
1249	os_full                  varchar(255)    DEFAULT ''                NOT NULL,
1250	os_short                 varchar(64)     DEFAULT ''                NOT NULL,
1251	serialno_a               varchar(64)     DEFAULT ''                NOT NULL,
1252	serialno_b               varchar(64)     DEFAULT ''                NOT NULL,
1253	tag                      varchar(64)     DEFAULT ''                NOT NULL,
1254	asset_tag                varchar(64)     DEFAULT ''                NOT NULL,
1255	macaddress_a             varchar(64)     DEFAULT ''                NOT NULL,
1256	macaddress_b             varchar(64)     DEFAULT ''                NOT NULL,
1257	hardware                 varchar(255)    DEFAULT ''                NOT NULL,
1258	hardware_full            text            DEFAULT ''                NOT NULL,
1259	software                 varchar(255)    DEFAULT ''                NOT NULL,
1260	software_full            text            DEFAULT ''                NOT NULL,
1261	software_app_a           varchar(64)     DEFAULT ''                NOT NULL,
1262	software_app_b           varchar(64)     DEFAULT ''                NOT NULL,
1263	software_app_c           varchar(64)     DEFAULT ''                NOT NULL,
1264	software_app_d           varchar(64)     DEFAULT ''                NOT NULL,
1265	software_app_e           varchar(64)     DEFAULT ''                NOT NULL,
1266	contact                  text            DEFAULT ''                NOT NULL,
1267	location                 text            DEFAULT ''                NOT NULL,
1268	location_lat             varchar(16)     DEFAULT ''                NOT NULL,
1269	location_lon             varchar(16)     DEFAULT ''                NOT NULL,
1270	notes                    text            DEFAULT ''                NOT NULL,
1271	chassis                  varchar(64)     DEFAULT ''                NOT NULL,
1272	model                    varchar(64)     DEFAULT ''                NOT NULL,
1273	hw_arch                  varchar(32)     DEFAULT ''                NOT NULL,
1274	vendor                   varchar(64)     DEFAULT ''                NOT NULL,
1275	contract_number          varchar(64)     DEFAULT ''                NOT NULL,
1276	installer_name           varchar(64)     DEFAULT ''                NOT NULL,
1277	deployment_status        varchar(64)     DEFAULT ''                NOT NULL,
1278	url_a                    varchar(255)    DEFAULT ''                NOT NULL,
1279	url_b                    varchar(255)    DEFAULT ''                NOT NULL,
1280	url_c                    varchar(255)    DEFAULT ''                NOT NULL,
1281	host_networks            text            DEFAULT ''                NOT NULL,
1282	host_netmask             varchar(39)     DEFAULT ''                NOT NULL,
1283	host_router              varchar(39)     DEFAULT ''                NOT NULL,
1284	oob_ip                   varchar(39)     DEFAULT ''                NOT NULL,
1285	oob_netmask              varchar(39)     DEFAULT ''                NOT NULL,
1286	oob_router               varchar(39)     DEFAULT ''                NOT NULL,
1287	date_hw_purchase         varchar(64)     DEFAULT ''                NOT NULL,
1288	date_hw_install          varchar(64)     DEFAULT ''                NOT NULL,
1289	date_hw_expiry           varchar(64)     DEFAULT ''                NOT NULL,
1290	date_hw_decomm           varchar(64)     DEFAULT ''                NOT NULL,
1291	site_address_a           varchar(128)    DEFAULT ''                NOT NULL,
1292	site_address_b           varchar(128)    DEFAULT ''                NOT NULL,
1293	site_address_c           varchar(128)    DEFAULT ''                NOT NULL,
1294	site_city                varchar(128)    DEFAULT ''                NOT NULL,
1295	site_state               varchar(64)     DEFAULT ''                NOT NULL,
1296	site_country             varchar(64)     DEFAULT ''                NOT NULL,
1297	site_zip                 varchar(64)     DEFAULT ''                NOT NULL,
1298	site_rack                varchar(128)    DEFAULT ''                NOT NULL,
1299	site_notes               text            DEFAULT ''                NOT NULL,
1300	poc_1_name               varchar(128)    DEFAULT ''                NOT NULL,
1301	poc_1_email              varchar(128)    DEFAULT ''                NOT NULL,
1302	poc_1_phone_a            varchar(64)     DEFAULT ''                NOT NULL,
1303	poc_1_phone_b            varchar(64)     DEFAULT ''                NOT NULL,
1304	poc_1_cell               varchar(64)     DEFAULT ''                NOT NULL,
1305	poc_1_screen             varchar(64)     DEFAULT ''                NOT NULL,
1306	poc_1_notes              text            DEFAULT ''                NOT NULL,
1307	poc_2_name               varchar(128)    DEFAULT ''                NOT NULL,
1308	poc_2_email              varchar(128)    DEFAULT ''                NOT NULL,
1309	poc_2_phone_a            varchar(64)     DEFAULT ''                NOT NULL,
1310	poc_2_phone_b            varchar(64)     DEFAULT ''                NOT NULL,
1311	poc_2_cell               varchar(64)     DEFAULT ''                NOT NULL,
1312	poc_2_screen             varchar(64)     DEFAULT ''                NOT NULL,
1313	poc_2_notes              text            DEFAULT ''                NOT NULL,
1314	PRIMARY KEY (hostid)
1315);
1316CREATE TABLE housekeeper (
1317	housekeeperid            bigint                                    NOT NULL,
1318	tablename                varchar(64)     DEFAULT ''                NOT NULL,
1319	field                    varchar(64)     DEFAULT ''                NOT NULL,
1320	value                    bigint                                    NOT NULL,
1321	PRIMARY KEY (housekeeperid)
1322);
1323CREATE TABLE images (
1324	imageid                  bigint                                    NOT NULL,
1325	imagetype                integer         DEFAULT '0'               NOT NULL,
1326	name                     varchar(64)     DEFAULT '0'               NOT NULL,
1327	image                    bytea           DEFAULT ''                NOT NULL,
1328	PRIMARY KEY (imageid)
1329);
1330CREATE UNIQUE INDEX images_1 ON images (name);
1331CREATE TABLE item_discovery (
1332	itemdiscoveryid          bigint                                    NOT NULL,
1333	itemid                   bigint                                    NOT NULL,
1334	parent_itemid            bigint                                    NOT NULL,
1335	key_                     varchar(255)    DEFAULT ''                NOT NULL,
1336	lastcheck                integer         DEFAULT '0'               NOT NULL,
1337	ts_delete                integer         DEFAULT '0'               NOT NULL,
1338	PRIMARY KEY (itemdiscoveryid)
1339);
1340CREATE UNIQUE INDEX item_discovery_1 ON item_discovery (itemid,parent_itemid);
1341CREATE INDEX item_discovery_2 ON item_discovery (parent_itemid);
1342CREATE TABLE host_discovery (
1343	hostid                   bigint                                    NOT NULL,
1344	parent_hostid            bigint                                    NULL,
1345	parent_itemid            bigint                                    NULL,
1346	host                     varchar(64)     DEFAULT ''                NOT NULL,
1347	lastcheck                integer         DEFAULT '0'               NOT NULL,
1348	ts_delete                integer         DEFAULT '0'               NOT NULL,
1349	PRIMARY KEY (hostid)
1350);
1351CREATE TABLE interface_discovery (
1352	interfaceid              bigint                                    NOT NULL,
1353	parent_interfaceid       bigint                                    NOT NULL,
1354	PRIMARY KEY (interfaceid)
1355);
1356CREATE TABLE profiles (
1357	profileid                bigint                                    NOT NULL,
1358	userid                   bigint                                    NOT NULL,
1359	idx                      varchar(96)     DEFAULT ''                NOT NULL,
1360	idx2                     bigint          DEFAULT '0'               NOT NULL,
1361	value_id                 bigint          DEFAULT '0'               NOT NULL,
1362	value_int                integer         DEFAULT '0'               NOT NULL,
1363	value_str                varchar(255)    DEFAULT ''                NOT NULL,
1364	source                   varchar(96)     DEFAULT ''                NOT NULL,
1365	type                     integer         DEFAULT '0'               NOT NULL,
1366	PRIMARY KEY (profileid)
1367);
1368CREATE INDEX profiles_1 ON profiles (userid,idx,idx2);
1369CREATE INDEX profiles_2 ON profiles (userid,profileid);
1370CREATE TABLE sessions (
1371	sessionid                varchar(32)     DEFAULT ''                NOT NULL,
1372	userid                   bigint                                    NOT NULL,
1373	lastaccess               integer         DEFAULT '0'               NOT NULL,
1374	status                   integer         DEFAULT '0'               NOT NULL,
1375	PRIMARY KEY (sessionid)
1376);
1377CREATE INDEX sessions_1 ON sessions (userid,status);
1378CREATE TABLE trigger_discovery (
1379	triggerid                bigint                                    NOT NULL,
1380	parent_triggerid         bigint                                    NOT NULL,
1381	PRIMARY KEY (triggerid)
1382);
1383CREATE INDEX trigger_discovery_1 ON trigger_discovery (parent_triggerid);
1384CREATE TABLE application_template (
1385	application_templateid   bigint                                    NOT NULL,
1386	applicationid            bigint                                    NOT NULL,
1387	templateid               bigint                                    NOT NULL,
1388	PRIMARY KEY (application_templateid)
1389);
1390CREATE UNIQUE INDEX application_template_1 ON application_template (applicationid,templateid);
1391CREATE INDEX application_template_2 ON application_template (templateid);
1392CREATE TABLE item_condition (
1393	item_conditionid         bigint                                    NOT NULL,
1394	itemid                   bigint                                    NOT NULL,
1395	operator                 integer         DEFAULT '8'               NOT NULL,
1396	macro                    varchar(64)     DEFAULT ''                NOT NULL,
1397	value                    varchar(255)    DEFAULT ''                NOT NULL,
1398	PRIMARY KEY (item_conditionid)
1399);
1400CREATE INDEX item_condition_1 ON item_condition (itemid);
1401CREATE TABLE application_prototype (
1402	application_prototypeid  bigint                                    NOT NULL,
1403	itemid                   bigint                                    NOT NULL,
1404	templateid               bigint                                    NULL,
1405	name                     varchar(255)    DEFAULT ''                NOT NULL,
1406	PRIMARY KEY (application_prototypeid)
1407);
1408CREATE INDEX application_prototype_1 ON application_prototype (itemid);
1409CREATE INDEX application_prototype_2 ON application_prototype (templateid);
1410CREATE TABLE item_application_prototype (
1411	item_application_prototypeid bigint                                    NOT NULL,
1412	application_prototypeid  bigint                                    NOT NULL,
1413	itemid                   bigint                                    NOT NULL,
1414	PRIMARY KEY (item_application_prototypeid)
1415);
1416CREATE UNIQUE INDEX item_application_prototype_1 ON item_application_prototype (application_prototypeid,itemid);
1417CREATE INDEX item_application_prototype_2 ON item_application_prototype (itemid);
1418CREATE TABLE application_discovery (
1419	application_discoveryid  bigint                                    NOT NULL,
1420	applicationid            bigint                                    NOT NULL,
1421	application_prototypeid  bigint                                    NOT NULL,
1422	name                     varchar(255)    DEFAULT ''                NOT NULL,
1423	lastcheck                integer         DEFAULT '0'               NOT NULL,
1424	ts_delete                integer         DEFAULT '0'               NOT NULL,
1425	PRIMARY KEY (application_discoveryid)
1426);
1427CREATE INDEX application_discovery_1 ON application_discovery (applicationid);
1428CREATE INDEX application_discovery_2 ON application_discovery (application_prototypeid);
1429CREATE TABLE opinventory (
1430	operationid              bigint                                    NOT NULL,
1431	inventory_mode           integer         DEFAULT '0'               NOT NULL,
1432	PRIMARY KEY (operationid)
1433);
1434CREATE TABLE dbversion (
1435	mandatory                integer         DEFAULT '0'               NOT NULL,
1436	optional                 integer         DEFAULT '0'               NOT NULL
1437);
1438INSERT INTO dbversion VALUES ('3000000','3000000');
1439ALTER TABLE ONLY hosts ADD CONSTRAINT c_hosts_1 FOREIGN KEY (proxy_hostid) REFERENCES hosts (hostid);
1440ALTER TABLE ONLY hosts ADD CONSTRAINT c_hosts_2 FOREIGN KEY (maintenanceid) REFERENCES maintenances (maintenanceid);
1441ALTER TABLE ONLY hosts ADD CONSTRAINT c_hosts_3 FOREIGN KEY (templateid) REFERENCES hosts (hostid) ON DELETE CASCADE;
1442ALTER TABLE ONLY group_prototype ADD CONSTRAINT c_group_prototype_1 FOREIGN KEY (hostid) REFERENCES hosts (hostid) ON DELETE CASCADE;
1443ALTER TABLE ONLY group_prototype ADD CONSTRAINT c_group_prototype_2 FOREIGN KEY (groupid) REFERENCES groups (groupid);
1444ALTER TABLE ONLY group_prototype ADD CONSTRAINT c_group_prototype_3 FOREIGN KEY (templateid) REFERENCES group_prototype (group_prototypeid) ON DELETE CASCADE;
1445ALTER TABLE ONLY group_discovery ADD CONSTRAINT c_group_discovery_1 FOREIGN KEY (groupid) REFERENCES groups (groupid) ON DELETE CASCADE;
1446ALTER TABLE ONLY group_discovery ADD CONSTRAINT c_group_discovery_2 FOREIGN KEY (parent_group_prototypeid) REFERENCES group_prototype (group_prototypeid);
1447ALTER TABLE ONLY screens ADD CONSTRAINT c_screens_1 FOREIGN KEY (templateid) REFERENCES hosts (hostid) ON DELETE CASCADE;
1448ALTER TABLE ONLY screens ADD CONSTRAINT c_screens_3 FOREIGN KEY (userid) REFERENCES users (userid);
1449ALTER TABLE ONLY screens_items ADD CONSTRAINT c_screens_items_1 FOREIGN KEY (screenid) REFERENCES screens (screenid) ON DELETE CASCADE;
1450ALTER TABLE ONLY screen_user ADD CONSTRAINT c_screen_user_1 FOREIGN KEY (screenid) REFERENCES screens (screenid) ON DELETE CASCADE;
1451ALTER TABLE ONLY screen_user ADD CONSTRAINT c_screen_user_2 FOREIGN KEY (userid) REFERENCES users (userid) ON DELETE CASCADE;
1452ALTER TABLE ONLY screen_usrgrp ADD CONSTRAINT c_screen_usrgrp_1 FOREIGN KEY (screenid) REFERENCES screens (screenid) ON DELETE CASCADE;
1453ALTER TABLE ONLY screen_usrgrp ADD CONSTRAINT c_screen_usrgrp_2 FOREIGN KEY (usrgrpid) REFERENCES usrgrp (usrgrpid) ON DELETE CASCADE;
1454ALTER TABLE ONLY slideshows ADD CONSTRAINT c_slideshows_3 FOREIGN KEY (userid) REFERENCES users (userid);
1455ALTER TABLE ONLY slideshow_user ADD CONSTRAINT c_slideshow_user_1 FOREIGN KEY (slideshowid) REFERENCES slideshows (slideshowid) ON DELETE CASCADE;
1456ALTER TABLE ONLY slideshow_user ADD CONSTRAINT c_slideshow_user_2 FOREIGN KEY (userid) REFERENCES users (userid) ON DELETE CASCADE;
1457ALTER TABLE ONLY slideshow_usrgrp ADD CONSTRAINT c_slideshow_usrgrp_1 FOREIGN KEY (slideshowid) REFERENCES slideshows (slideshowid) ON DELETE CASCADE;
1458ALTER TABLE ONLY slideshow_usrgrp ADD CONSTRAINT c_slideshow_usrgrp_2 FOREIGN KEY (usrgrpid) REFERENCES usrgrp (usrgrpid) ON DELETE CASCADE;
1459ALTER TABLE ONLY slides ADD CONSTRAINT c_slides_1 FOREIGN KEY (slideshowid) REFERENCES slideshows (slideshowid) ON DELETE CASCADE;
1460ALTER TABLE ONLY slides ADD CONSTRAINT c_slides_2 FOREIGN KEY (screenid) REFERENCES screens (screenid) ON DELETE CASCADE;
1461ALTER TABLE ONLY drules ADD CONSTRAINT c_drules_1 FOREIGN KEY (proxy_hostid) REFERENCES hosts (hostid);
1462ALTER TABLE ONLY dchecks ADD CONSTRAINT c_dchecks_1 FOREIGN KEY (druleid) REFERENCES drules (druleid) ON DELETE CASCADE;
1463ALTER TABLE ONLY applications ADD CONSTRAINT c_applications_1 FOREIGN KEY (hostid) REFERENCES hosts (hostid) ON DELETE CASCADE;
1464ALTER TABLE ONLY httptest ADD CONSTRAINT c_httptest_1 FOREIGN KEY (applicationid) REFERENCES applications (applicationid);
1465ALTER TABLE ONLY httptest ADD CONSTRAINT c_httptest_2 FOREIGN KEY (hostid) REFERENCES hosts (hostid) ON DELETE CASCADE;
1466ALTER TABLE ONLY httptest ADD CONSTRAINT c_httptest_3 FOREIGN KEY (templateid) REFERENCES httptest (httptestid) ON DELETE CASCADE;
1467ALTER TABLE ONLY httpstep ADD CONSTRAINT c_httpstep_1 FOREIGN KEY (httptestid) REFERENCES httptest (httptestid) ON DELETE CASCADE;
1468ALTER TABLE ONLY interface ADD CONSTRAINT c_interface_1 FOREIGN KEY (hostid) REFERENCES hosts (hostid) ON DELETE CASCADE;
1469ALTER TABLE ONLY items ADD CONSTRAINT c_items_1 FOREIGN KEY (hostid) REFERENCES hosts (hostid) ON DELETE CASCADE;
1470ALTER TABLE ONLY items ADD CONSTRAINT c_items_2 FOREIGN KEY (templateid) REFERENCES items (itemid) ON DELETE CASCADE;
1471ALTER TABLE ONLY items ADD CONSTRAINT c_items_3 FOREIGN KEY (valuemapid) REFERENCES valuemaps (valuemapid);
1472ALTER TABLE ONLY items ADD CONSTRAINT c_items_4 FOREIGN KEY (interfaceid) REFERENCES interface (interfaceid);
1473ALTER TABLE ONLY httpstepitem ADD CONSTRAINT c_httpstepitem_1 FOREIGN KEY (httpstepid) REFERENCES httpstep (httpstepid) ON DELETE CASCADE;
1474ALTER TABLE ONLY httpstepitem ADD CONSTRAINT c_httpstepitem_2 FOREIGN KEY (itemid) REFERENCES items (itemid) ON DELETE CASCADE;
1475ALTER TABLE ONLY httptestitem ADD CONSTRAINT c_httptestitem_1 FOREIGN KEY (httptestid) REFERENCES httptest (httptestid) ON DELETE CASCADE;
1476ALTER TABLE ONLY httptestitem ADD CONSTRAINT c_httptestitem_2 FOREIGN KEY (itemid) REFERENCES items (itemid) ON DELETE CASCADE;
1477ALTER TABLE ONLY users_groups ADD CONSTRAINT c_users_groups_1 FOREIGN KEY (usrgrpid) REFERENCES usrgrp (usrgrpid) ON DELETE CASCADE;
1478ALTER TABLE ONLY users_groups ADD CONSTRAINT c_users_groups_2 FOREIGN KEY (userid) REFERENCES users (userid) ON DELETE CASCADE;
1479ALTER TABLE ONLY scripts ADD CONSTRAINT c_scripts_1 FOREIGN KEY (usrgrpid) REFERENCES usrgrp (usrgrpid);
1480ALTER TABLE ONLY scripts ADD CONSTRAINT c_scripts_2 FOREIGN KEY (groupid) REFERENCES groups (groupid);
1481ALTER TABLE ONLY operations ADD CONSTRAINT c_operations_1 FOREIGN KEY (actionid) REFERENCES actions (actionid) ON DELETE CASCADE;
1482ALTER TABLE ONLY opmessage ADD CONSTRAINT c_opmessage_1 FOREIGN KEY (operationid) REFERENCES operations (operationid) ON DELETE CASCADE;
1483ALTER TABLE ONLY opmessage ADD CONSTRAINT c_opmessage_2 FOREIGN KEY (mediatypeid) REFERENCES media_type (mediatypeid);
1484ALTER TABLE ONLY opmessage_grp ADD CONSTRAINT c_opmessage_grp_1 FOREIGN KEY (operationid) REFERENCES operations (operationid) ON DELETE CASCADE;
1485ALTER TABLE ONLY opmessage_grp ADD CONSTRAINT c_opmessage_grp_2 FOREIGN KEY (usrgrpid) REFERENCES usrgrp (usrgrpid);
1486ALTER TABLE ONLY opmessage_usr ADD CONSTRAINT c_opmessage_usr_1 FOREIGN KEY (operationid) REFERENCES operations (operationid) ON DELETE CASCADE;
1487ALTER TABLE ONLY opmessage_usr ADD CONSTRAINT c_opmessage_usr_2 FOREIGN KEY (userid) REFERENCES users (userid);
1488ALTER TABLE ONLY opcommand ADD CONSTRAINT c_opcommand_1 FOREIGN KEY (operationid) REFERENCES operations (operationid) ON DELETE CASCADE;
1489ALTER TABLE ONLY opcommand ADD CONSTRAINT c_opcommand_2 FOREIGN KEY (scriptid) REFERENCES scripts (scriptid);
1490ALTER TABLE ONLY opcommand_hst ADD CONSTRAINT c_opcommand_hst_1 FOREIGN KEY (operationid) REFERENCES operations (operationid) ON DELETE CASCADE;
1491ALTER TABLE ONLY opcommand_hst ADD CONSTRAINT c_opcommand_hst_2 FOREIGN KEY (hostid) REFERENCES hosts (hostid);
1492ALTER TABLE ONLY opcommand_grp ADD CONSTRAINT c_opcommand_grp_1 FOREIGN KEY (operationid) REFERENCES operations (operationid) ON DELETE CASCADE;
1493ALTER TABLE ONLY opcommand_grp ADD CONSTRAINT c_opcommand_grp_2 FOREIGN KEY (groupid) REFERENCES groups (groupid);
1494ALTER TABLE ONLY opgroup ADD CONSTRAINT c_opgroup_1 FOREIGN KEY (operationid) REFERENCES operations (operationid) ON DELETE CASCADE;
1495ALTER TABLE ONLY opgroup ADD CONSTRAINT c_opgroup_2 FOREIGN KEY (groupid) REFERENCES groups (groupid);
1496ALTER TABLE ONLY optemplate ADD CONSTRAINT c_optemplate_1 FOREIGN KEY (operationid) REFERENCES operations (operationid) ON DELETE CASCADE;
1497ALTER TABLE ONLY optemplate ADD CONSTRAINT c_optemplate_2 FOREIGN KEY (templateid) REFERENCES hosts (hostid);
1498ALTER TABLE ONLY opconditions ADD CONSTRAINT c_opconditions_1 FOREIGN KEY (operationid) REFERENCES operations (operationid) ON DELETE CASCADE;
1499ALTER TABLE ONLY conditions ADD CONSTRAINT c_conditions_1 FOREIGN KEY (actionid) REFERENCES actions (actionid) ON DELETE CASCADE;
1500ALTER TABLE ONLY config ADD CONSTRAINT c_config_1 FOREIGN KEY (alert_usrgrpid) REFERENCES usrgrp (usrgrpid);
1501ALTER TABLE ONLY config ADD CONSTRAINT c_config_2 FOREIGN KEY (discovery_groupid) REFERENCES groups (groupid);
1502ALTER TABLE ONLY triggers ADD CONSTRAINT c_triggers_1 FOREIGN KEY (templateid) REFERENCES triggers (triggerid) ON DELETE CASCADE;
1503ALTER TABLE ONLY trigger_depends ADD CONSTRAINT c_trigger_depends_1 FOREIGN KEY (triggerid_down) REFERENCES triggers (triggerid) ON DELETE CASCADE;
1504ALTER TABLE ONLY trigger_depends ADD CONSTRAINT c_trigger_depends_2 FOREIGN KEY (triggerid_up) REFERENCES triggers (triggerid) ON DELETE CASCADE;
1505ALTER TABLE ONLY functions ADD CONSTRAINT c_functions_1 FOREIGN KEY (itemid) REFERENCES items (itemid) ON DELETE CASCADE;
1506ALTER TABLE ONLY functions ADD CONSTRAINT c_functions_2 FOREIGN KEY (triggerid) REFERENCES triggers (triggerid) ON DELETE CASCADE;
1507ALTER TABLE ONLY graphs ADD CONSTRAINT c_graphs_1 FOREIGN KEY (templateid) REFERENCES graphs (graphid) ON DELETE CASCADE;
1508ALTER TABLE ONLY graphs ADD CONSTRAINT c_graphs_2 FOREIGN KEY (ymin_itemid) REFERENCES items (itemid);
1509ALTER TABLE ONLY graphs ADD CONSTRAINT c_graphs_3 FOREIGN KEY (ymax_itemid) REFERENCES items (itemid);
1510ALTER TABLE ONLY graphs_items ADD CONSTRAINT c_graphs_items_1 FOREIGN KEY (graphid) REFERENCES graphs (graphid) ON DELETE CASCADE;
1511ALTER TABLE ONLY graphs_items ADD CONSTRAINT c_graphs_items_2 FOREIGN KEY (itemid) REFERENCES items (itemid) ON DELETE CASCADE;
1512ALTER TABLE ONLY hostmacro ADD CONSTRAINT c_hostmacro_1 FOREIGN KEY (hostid) REFERENCES hosts (hostid) ON DELETE CASCADE;
1513ALTER TABLE ONLY hosts_groups ADD CONSTRAINT c_hosts_groups_1 FOREIGN KEY (hostid) REFERENCES hosts (hostid) ON DELETE CASCADE;
1514ALTER TABLE ONLY hosts_groups ADD CONSTRAINT c_hosts_groups_2 FOREIGN KEY (groupid) REFERENCES groups (groupid) ON DELETE CASCADE;
1515ALTER TABLE ONLY hosts_templates ADD CONSTRAINT c_hosts_templates_1 FOREIGN KEY (hostid) REFERENCES hosts (hostid) ON DELETE CASCADE;
1516ALTER TABLE ONLY hosts_templates ADD CONSTRAINT c_hosts_templates_2 FOREIGN KEY (templateid) REFERENCES hosts (hostid) ON DELETE CASCADE;
1517ALTER TABLE ONLY items_applications ADD CONSTRAINT c_items_applications_1 FOREIGN KEY (applicationid) REFERENCES applications (applicationid) ON DELETE CASCADE;
1518ALTER TABLE ONLY items_applications ADD CONSTRAINT c_items_applications_2 FOREIGN KEY (itemid) REFERENCES items (itemid) ON DELETE CASCADE;
1519ALTER TABLE ONLY mappings ADD CONSTRAINT c_mappings_1 FOREIGN KEY (valuemapid) REFERENCES valuemaps (valuemapid) ON DELETE CASCADE;
1520ALTER TABLE ONLY media ADD CONSTRAINT c_media_1 FOREIGN KEY (userid) REFERENCES users (userid) ON DELETE CASCADE;
1521ALTER TABLE ONLY media ADD CONSTRAINT c_media_2 FOREIGN KEY (mediatypeid) REFERENCES media_type (mediatypeid) ON DELETE CASCADE;
1522ALTER TABLE ONLY rights ADD CONSTRAINT c_rights_1 FOREIGN KEY (groupid) REFERENCES usrgrp (usrgrpid) ON DELETE CASCADE;
1523ALTER TABLE ONLY rights ADD CONSTRAINT c_rights_2 FOREIGN KEY (id) REFERENCES groups (groupid) ON DELETE CASCADE;
1524ALTER TABLE ONLY services ADD CONSTRAINT c_services_1 FOREIGN KEY (triggerid) REFERENCES triggers (triggerid) ON DELETE CASCADE;
1525ALTER TABLE ONLY services_links ADD CONSTRAINT c_services_links_1 FOREIGN KEY (serviceupid) REFERENCES services (serviceid) ON DELETE CASCADE;
1526ALTER TABLE ONLY services_links ADD CONSTRAINT c_services_links_2 FOREIGN KEY (servicedownid) REFERENCES services (serviceid) ON DELETE CASCADE;
1527ALTER TABLE ONLY services_times ADD CONSTRAINT c_services_times_1 FOREIGN KEY (serviceid) REFERENCES services (serviceid) ON DELETE CASCADE;
1528ALTER TABLE ONLY icon_map ADD CONSTRAINT c_icon_map_1 FOREIGN KEY (default_iconid) REFERENCES images (imageid);
1529ALTER TABLE ONLY icon_mapping ADD CONSTRAINT c_icon_mapping_1 FOREIGN KEY (iconmapid) REFERENCES icon_map (iconmapid) ON DELETE CASCADE;
1530ALTER TABLE ONLY icon_mapping ADD CONSTRAINT c_icon_mapping_2 FOREIGN KEY (iconid) REFERENCES images (imageid);
1531ALTER TABLE ONLY sysmaps ADD CONSTRAINT c_sysmaps_1 FOREIGN KEY (backgroundid) REFERENCES images (imageid);
1532ALTER TABLE ONLY sysmaps ADD CONSTRAINT c_sysmaps_2 FOREIGN KEY (iconmapid) REFERENCES icon_map (iconmapid);
1533ALTER TABLE ONLY sysmaps ADD CONSTRAINT c_sysmaps_3 FOREIGN KEY (userid) REFERENCES users (userid);
1534ALTER TABLE ONLY sysmaps_elements ADD CONSTRAINT c_sysmaps_elements_1 FOREIGN KEY (sysmapid) REFERENCES sysmaps (sysmapid) ON DELETE CASCADE;
1535ALTER TABLE ONLY sysmaps_elements ADD CONSTRAINT c_sysmaps_elements_2 FOREIGN KEY (iconid_off) REFERENCES images (imageid);
1536ALTER TABLE ONLY sysmaps_elements ADD CONSTRAINT c_sysmaps_elements_3 FOREIGN KEY (iconid_on) REFERENCES images (imageid);
1537ALTER TABLE ONLY sysmaps_elements ADD CONSTRAINT c_sysmaps_elements_4 FOREIGN KEY (iconid_disabled) REFERENCES images (imageid);
1538ALTER TABLE ONLY sysmaps_elements ADD CONSTRAINT c_sysmaps_elements_5 FOREIGN KEY (iconid_maintenance) REFERENCES images (imageid);
1539ALTER TABLE ONLY sysmaps_links ADD CONSTRAINT c_sysmaps_links_1 FOREIGN KEY (sysmapid) REFERENCES sysmaps (sysmapid) ON DELETE CASCADE;
1540ALTER TABLE ONLY sysmaps_links ADD CONSTRAINT c_sysmaps_links_2 FOREIGN KEY (selementid1) REFERENCES sysmaps_elements (selementid) ON DELETE CASCADE;
1541ALTER TABLE ONLY sysmaps_links ADD CONSTRAINT c_sysmaps_links_3 FOREIGN KEY (selementid2) REFERENCES sysmaps_elements (selementid) ON DELETE CASCADE;
1542ALTER TABLE ONLY sysmaps_link_triggers ADD CONSTRAINT c_sysmaps_link_triggers_1 FOREIGN KEY (linkid) REFERENCES sysmaps_links (linkid) ON DELETE CASCADE;
1543ALTER TABLE ONLY sysmaps_link_triggers ADD CONSTRAINT c_sysmaps_link_triggers_2 FOREIGN KEY (triggerid) REFERENCES triggers (triggerid) ON DELETE CASCADE;
1544ALTER TABLE ONLY sysmap_element_url ADD CONSTRAINT c_sysmap_element_url_1 FOREIGN KEY (selementid) REFERENCES sysmaps_elements (selementid) ON DELETE CASCADE;
1545ALTER TABLE ONLY sysmap_url ADD CONSTRAINT c_sysmap_url_1 FOREIGN KEY (sysmapid) REFERENCES sysmaps (sysmapid) ON DELETE CASCADE;
1546ALTER TABLE ONLY sysmap_user ADD CONSTRAINT c_sysmap_user_1 FOREIGN KEY (sysmapid) REFERENCES sysmaps (sysmapid) ON DELETE CASCADE;
1547ALTER TABLE ONLY sysmap_user ADD CONSTRAINT c_sysmap_user_2 FOREIGN KEY (userid) REFERENCES users (userid) ON DELETE CASCADE;
1548ALTER TABLE ONLY sysmap_usrgrp ADD CONSTRAINT c_sysmap_usrgrp_1 FOREIGN KEY (sysmapid) REFERENCES sysmaps (sysmapid) ON DELETE CASCADE;
1549ALTER TABLE ONLY sysmap_usrgrp ADD CONSTRAINT c_sysmap_usrgrp_2 FOREIGN KEY (usrgrpid) REFERENCES usrgrp (usrgrpid) ON DELETE CASCADE;
1550ALTER TABLE ONLY maintenances_hosts ADD CONSTRAINT c_maintenances_hosts_1 FOREIGN KEY (maintenanceid) REFERENCES maintenances (maintenanceid) ON DELETE CASCADE;
1551ALTER TABLE ONLY maintenances_hosts ADD CONSTRAINT c_maintenances_hosts_2 FOREIGN KEY (hostid) REFERENCES hosts (hostid) ON DELETE CASCADE;
1552ALTER TABLE ONLY maintenances_groups ADD CONSTRAINT c_maintenances_groups_1 FOREIGN KEY (maintenanceid) REFERENCES maintenances (maintenanceid) ON DELETE CASCADE;
1553ALTER TABLE ONLY maintenances_groups ADD CONSTRAINT c_maintenances_groups_2 FOREIGN KEY (groupid) REFERENCES groups (groupid) ON DELETE CASCADE;
1554ALTER TABLE ONLY maintenances_windows ADD CONSTRAINT c_maintenances_windows_1 FOREIGN KEY (maintenanceid) REFERENCES maintenances (maintenanceid) ON DELETE CASCADE;
1555ALTER TABLE ONLY maintenances_windows ADD CONSTRAINT c_maintenances_windows_2 FOREIGN KEY (timeperiodid) REFERENCES timeperiods (timeperiodid) ON DELETE CASCADE;
1556ALTER TABLE ONLY expressions ADD CONSTRAINT c_expressions_1 FOREIGN KEY (regexpid) REFERENCES regexps (regexpid) ON DELETE CASCADE;
1557ALTER TABLE ONLY alerts ADD CONSTRAINT c_alerts_1 FOREIGN KEY (actionid) REFERENCES actions (actionid) ON DELETE CASCADE;
1558ALTER TABLE ONLY alerts ADD CONSTRAINT c_alerts_2 FOREIGN KEY (eventid) REFERENCES events (eventid) ON DELETE CASCADE;
1559ALTER TABLE ONLY alerts ADD CONSTRAINT c_alerts_3 FOREIGN KEY (userid) REFERENCES users (userid) ON DELETE CASCADE;
1560ALTER TABLE ONLY alerts ADD CONSTRAINT c_alerts_4 FOREIGN KEY (mediatypeid) REFERENCES media_type (mediatypeid) ON DELETE CASCADE;
1561ALTER TABLE ONLY acknowledges ADD CONSTRAINT c_acknowledges_1 FOREIGN KEY (userid) REFERENCES users (userid) ON DELETE CASCADE;
1562ALTER TABLE ONLY acknowledges ADD CONSTRAINT c_acknowledges_2 FOREIGN KEY (eventid) REFERENCES events (eventid) ON DELETE CASCADE;
1563ALTER TABLE ONLY auditlog ADD CONSTRAINT c_auditlog_1 FOREIGN KEY (userid) REFERENCES users (userid) ON DELETE CASCADE;
1564ALTER TABLE ONLY auditlog_details ADD CONSTRAINT c_auditlog_details_1 FOREIGN KEY (auditid) REFERENCES auditlog (auditid) ON DELETE CASCADE;
1565ALTER TABLE ONLY service_alarms ADD CONSTRAINT c_service_alarms_1 FOREIGN KEY (serviceid) REFERENCES services (serviceid) ON DELETE CASCADE;
1566ALTER TABLE ONLY autoreg_host ADD CONSTRAINT c_autoreg_host_1 FOREIGN KEY (proxy_hostid) REFERENCES hosts (hostid) ON DELETE CASCADE;
1567ALTER TABLE ONLY dhosts ADD CONSTRAINT c_dhosts_1 FOREIGN KEY (druleid) REFERENCES drules (druleid) ON DELETE CASCADE;
1568ALTER TABLE ONLY dservices ADD CONSTRAINT c_dservices_1 FOREIGN KEY (dhostid) REFERENCES dhosts (dhostid) ON DELETE CASCADE;
1569ALTER TABLE ONLY dservices ADD CONSTRAINT c_dservices_2 FOREIGN KEY (dcheckid) REFERENCES dchecks (dcheckid) ON DELETE CASCADE;
1570ALTER TABLE ONLY graph_discovery ADD CONSTRAINT c_graph_discovery_1 FOREIGN KEY (graphid) REFERENCES graphs (graphid) ON DELETE CASCADE;
1571ALTER TABLE ONLY graph_discovery ADD CONSTRAINT c_graph_discovery_2 FOREIGN KEY (parent_graphid) REFERENCES graphs (graphid);
1572ALTER TABLE ONLY host_inventory ADD CONSTRAINT c_host_inventory_1 FOREIGN KEY (hostid) REFERENCES hosts (hostid) ON DELETE CASCADE;
1573ALTER TABLE ONLY item_discovery ADD CONSTRAINT c_item_discovery_1 FOREIGN KEY (itemid) REFERENCES items (itemid) ON DELETE CASCADE;
1574ALTER TABLE ONLY item_discovery ADD CONSTRAINT c_item_discovery_2 FOREIGN KEY (parent_itemid) REFERENCES items (itemid) ON DELETE CASCADE;
1575ALTER TABLE ONLY host_discovery ADD CONSTRAINT c_host_discovery_1 FOREIGN KEY (hostid) REFERENCES hosts (hostid) ON DELETE CASCADE;
1576ALTER TABLE ONLY host_discovery ADD CONSTRAINT c_host_discovery_2 FOREIGN KEY (parent_hostid) REFERENCES hosts (hostid);
1577ALTER TABLE ONLY host_discovery ADD CONSTRAINT c_host_discovery_3 FOREIGN KEY (parent_itemid) REFERENCES items (itemid);
1578ALTER TABLE ONLY interface_discovery ADD CONSTRAINT c_interface_discovery_1 FOREIGN KEY (interfaceid) REFERENCES interface (interfaceid) ON DELETE CASCADE;
1579ALTER TABLE ONLY interface_discovery ADD CONSTRAINT c_interface_discovery_2 FOREIGN KEY (parent_interfaceid) REFERENCES interface (interfaceid) ON DELETE CASCADE;
1580ALTER TABLE ONLY profiles ADD CONSTRAINT c_profiles_1 FOREIGN KEY (userid) REFERENCES users (userid) ON DELETE CASCADE;
1581ALTER TABLE ONLY sessions ADD CONSTRAINT c_sessions_1 FOREIGN KEY (userid) REFERENCES users (userid) ON DELETE CASCADE;
1582ALTER TABLE ONLY trigger_discovery ADD CONSTRAINT c_trigger_discovery_1 FOREIGN KEY (triggerid) REFERENCES triggers (triggerid) ON DELETE CASCADE;
1583ALTER TABLE ONLY trigger_discovery ADD CONSTRAINT c_trigger_discovery_2 FOREIGN KEY (parent_triggerid) REFERENCES triggers (triggerid);
1584ALTER TABLE ONLY application_template ADD CONSTRAINT c_application_template_1 FOREIGN KEY (applicationid) REFERENCES applications (applicationid) ON DELETE CASCADE;
1585ALTER TABLE ONLY application_template ADD CONSTRAINT c_application_template_2 FOREIGN KEY (templateid) REFERENCES applications (applicationid) ON DELETE CASCADE;
1586ALTER TABLE ONLY item_condition ADD CONSTRAINT c_item_condition_1 FOREIGN KEY (itemid) REFERENCES items (itemid) ON DELETE CASCADE;
1587ALTER TABLE ONLY application_prototype ADD CONSTRAINT c_application_prototype_1 FOREIGN KEY (itemid) REFERENCES items (itemid) ON DELETE CASCADE;
1588ALTER TABLE ONLY application_prototype ADD CONSTRAINT c_application_prototype_2 FOREIGN KEY (templateid) REFERENCES application_prototype (application_prototypeid) ON DELETE CASCADE;
1589ALTER TABLE ONLY item_application_prototype ADD CONSTRAINT c_item_application_prototype_1 FOREIGN KEY (application_prototypeid) REFERENCES application_prototype (application_prototypeid) ON DELETE CASCADE;
1590ALTER TABLE ONLY item_application_prototype ADD CONSTRAINT c_item_application_prototype_2 FOREIGN KEY (itemid) REFERENCES items (itemid) ON DELETE CASCADE;
1591ALTER TABLE ONLY application_discovery ADD CONSTRAINT c_application_discovery_1 FOREIGN KEY (applicationid) REFERENCES applications (applicationid) ON DELETE CASCADE;
1592ALTER TABLE ONLY application_discovery ADD CONSTRAINT c_application_discovery_2 FOREIGN KEY (application_prototypeid) REFERENCES application_prototype (application_prototypeid) ON DELETE CASCADE;
1593ALTER TABLE ONLY opinventory ADD CONSTRAINT c_opinventory_1 FOREIGN KEY (operationid) REFERENCES operations (operationid) ON DELETE CASCADE;
1594