<?php
$res = array();
$res[] = tableCreate('eventlog', "
`logid` int(10) unsigned NOT NULL AUTO_INCREMENT,
`dateline` int(10) unsigned NOT NULL,
`logtypeid` varchar(30) NOT NULL,
`description` varchar(255) NOT NULL,
`extra` TEXT NOT NULL,
PRIMARY KEY (`logid`),
KEY `dateline` (`dateline`),
KEY `logtypeid` (`logtypeid`,`dateline`)
");
$res[] = tableCreate('notification_rule', '
`ruleid` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`title` varchar(100) NOT NULL,
`description` text,
`type` varchar(40) CHARACTER SET ascii NOT NULL,
`datafilter` blob NOT NULL,
`subject` varchar(200) NOT NULL,
`message` text NOT NULL,
PRIMARY KEY (`ruleid`),
KEY `type` (`type`)
');
$res[] = tableCreate('notification_backend', '
`transportid` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`title` varchar(100) NOT NULL,
`description` text,
`data` blob,
PRIMARY KEY (`transportid`),
KEY (`title`)
');
$res[] = tableCreate('notification_rule_x_transport', '
`ruleid` int(10) UNSIGNED NOT NULL,
`transportid` int(10) UNSIGNED NOT NULL,
PRIMARY KEY (`ruleid`, `transportid`),
KEY (`transportid`)
');
$res[] = tableCreate('notification_sample', '
`type` varchar(40) CHARACTER SET ascii NOT NULL,
`dateline` int(10) UNSIGNED NOT NULL,
`data` mediumblob,
KEY (`type`, `dateline`)
');
// Update path
if (!tableHasColumn('eventlog', 'extra')) {
if (Database::exec("ALTER TABLE `eventlog` ADD `extra` TEXT NOT NULL") === false) {
finalResponse(UPDATE_FAILED, 'Could not add extra to eventlog: ' . Database::lastError());
}
$res[] = UPDATE_DONE;
}
// 2021-06-15: Add constraints to filter/backend stuff
$res[] = tableAddConstraint('notification_rule_x_transport', 'ruleid',
'notification_rule', 'ruleid', 'ON UPDATE CASCADE ON DELETE CASCADE');
$res[] = tableAddConstraint('notification_rule_x_transport', 'transportid',
'notification_backend', 'transportid', 'ON UPDATE CASCADE ON DELETE CASCADE');
// Create response for browser
if (in_array(UPDATE_DONE, $res)) {
finalResponse(UPDATE_DONE, 'Tables created successfully');
}
finalResponse(UPDATE_NOOP, 'Everything already up to date');