tests: test each db schema file for proper format (#6580)

This commit is contained in:
Tony Murray
2017-05-04 15:14:14 -05:00
committed by Neil Lathwood
parent 422b2c8ae1
commit 6f99cb6d69
14 changed files with 53 additions and 25 deletions

View File

@@ -1 +1 @@
SELECT NOW()
SELECT NOW();

View File

@@ -1 +1 @@
ALTER TABLE `devices` ADD COLUMN `icon` VARCHAR(255) DEFAULT NULL
ALTER TABLE `devices` ADD COLUMN `icon` VARCHAR(255) DEFAULT NULL;

View File

@@ -1 +1 @@
UPDATE `sensors` SET sensor_limit=sensor_limit/1.3*1.8 WHERE sensor_class="fanspeed"
UPDATE `sensors` SET sensor_limit=sensor_limit/1.3*1.8 WHERE sensor_class='fanspeed';

View File

@@ -1,8 +1,8 @@
ALTER TABLE `munin_plugins` CHANGE `mplug_type` `mplug_type` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL;
ALTER TABLE slas ENGINE=InnoDB;
ALTER TABLE slas ENGINE=InnoDB;
ALTER TABLE packages ENGINE=InnoDB;
ALTER TABLE munin_plugins_ds ENGINE=InnoDB;
ALTER TABLE munin_plugins ENGINE=InnoDB;
ALTER TABLE munin_plugins ENGINE=InnoDB;
ALTER TABLE loadbalancer_vservers ENGINE=InnoDB;
ALTER TABLE loadbalancer_rservers ENGINE=InnoDB;
ALTER TABLE ipsec_tunnels ENGINE=InnoDB;

View File

@@ -1 +1 @@
CREATE TABLE `alert_template_map` (`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,`alert_templates_id` INT NOT NULL ,`alert_rule_id` INT NOT NULL ,INDEX ( `alert_templates_id` , `alert_rule_id` )) ENGINE = INNODB
CREATE TABLE `alert_template_map` (`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,`alert_templates_id` INT NOT NULL ,`alert_rule_id` INT NOT NULL ,INDEX ( `alert_templates_id` , `alert_rule_id` )) ENGINE = INNODB;

View File

@@ -1 +1 @@
insert into `config` (`config_name`,`config_value`,`config_default`,`config_descr`,`config_group`,`config_group_order`,`config_sub_group`,`config_sub_group_order`,`config_hidden`,`config_disabled`) values ('alert.macros.rule.sensor','(%sensors.sensor_alert = 1)','(%sensors.sensor_alert = 1)','Sensors of interest','alerting',0,'macros',0,'1','0')
insert into `config` (`config_name`,`config_value`,`config_default`,`config_descr`,`config_group`,`config_group_order`,`config_sub_group`,`config_sub_group_order`,`config_hidden`,`config_disabled`) values ('alert.macros.rule.sensor','(%sensors.sensor_alert = 1)','(%sensors.sensor_alert = 1)','Sensors of interest','alerting',0,'macros',0,'1','0');

View File

@@ -1,3 +1,3 @@
CREATE TABLE `proxmox` ( `id` int(11) NOT NULL AUTO_INCREMENT, `device_id` int(11) NOT NULL DEFAULT '0', `vmid` int(11) NOT NULL, `cluster` varchar(255) NOT NULL, `description` varchar(255) DEFAULT NULL, `last_seen` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `cluster_vm` (`cluster`,`vmid`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `proxmox` ( `id` int(11) NOT NULL AUTO_INCREMENT, `device_id` int(11) NOT NULL DEFAULT '0', `vmid` int(11) NOT NULL, `cluster` varchar(255) NOT NULL, `description` varchar(255) DEFAULT NULL, `last_seen` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `cluster_vm` (`cluster`,`vmid`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `proxmox_ports` ( `id` int(11) NOT NULL AUTO_INCREMENT, `vm_id` int(11) NOT NULL, `port` varchar(10) NOT NULL, `last_seen` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `vm_port` (`vm_id`,`port`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `applications` ADD COLUMN `app_instance` varchar(255) NOT NULL;

View File

@@ -1,2 +1,2 @@
CREATE TABLE `dashboards` ( `dashboard_id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL DEFAULT 0, `dashboard_name` varchar(255) NOT NULL, `access` int(1) NOT NULL DEFAULT 0, PRIMARY KEY (`dashboard_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `dashboards` ( `dashboard_id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL DEFAULT 0, `dashboard_name` varchar(255) NOT NULL, `access` int(1) NOT NULL DEFAULT 0, PRIMARY KEY (`dashboard_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `users_widgets` ADD COLUMN `dashboard_id` int(11) NOT NULL;

View File

@@ -1 +1 @@
ALTER TABLE `stp` CHANGE `timeSinceTopologyChange` `timeSinceTopologyChange` INT UNSIGNED NOT NULL
ALTER TABLE `stp` CHANGE `timeSinceTopologyChange` `timeSinceTopologyChange` INT UNSIGNED NOT NULL;

View File

@@ -1,3 +1,3 @@
ALTER TABLE port_in_measurements ADD INDEX (`port_id`, `timestamp`);
ALTER TABLE port_out_measurements ADD INDEX (`port_id`, `timestamp`);
ALTER TABLE bill_data ADD INDEX (`bill_id`, `timestamp`);
ALTER TABLE port_in_measurements ADD INDEX (`port_id`, `timestamp`);
ALTER TABLE port_out_measurements ADD INDEX (`port_id`, `timestamp`);
ALTER TABLE bill_data ADD INDEX (`bill_id`, `timestamp`);

View File

@@ -1,10 +1,10 @@
CREATE TABLE bill_port_counters_tmp(port_id int NOT NULL PRIMARY KEY, `timestamp` timestamp NOT NULL DEFAULT current_timestamp, in_counter bigint, in_delta bigint NOT NULL DEFAULT 0, out_counter bigint, out_delta bigint NOT NULL DEFAULT 0);
INSERT INTO bill_port_counters_tmp(port_id, timestamp, in_counter, out_counter) SELECT q.port_id, q.max_timestamp, max(i.counter), max(o.counter) FROM (SELECT port_id, MAX(`timestamp`) AS max_timestamp FROM port_in_measurements GROUP BY port_id) q INNER JOIN port_in_measurements i ON q.port_id = i.port_id AND q.max_timestamp = i.timestamp INNER JOIN port_out_measurements o ON q.port_id = o.port_id AND q.max_timestamp = o.timestamp GROUP BY q.port_id, q.max_timestamp;
RENAME TABLE bill_port_counters_tmp TO bill_port_counters;
ALTER TABLE bill_data ADD id int NOT NULL PRIMARY KEY AUTO_INCREMENT FIRST;
DELETE bill_data FROM bill_data INNER JOIN (SELECT bill_id, timestamp, MIN(id) as first_id FROM bill_data GROUP BY bill_id, timestamp HAVING COUNT(id) > 1) q ON bill_data.bill_id = q.bill_id AND bill_data.timestamp = q.timestamp;
ALTER TABLE bill_data DROP id;
ALTER TABLE bill_data ADD PRIMARY KEY (bill_id, timestamp);
ALTER TABLE bill_data DROP INDEX bill_id_2;
DROP TABLE port_in_measurements;
DROP TABLE port_out_measurements;
CREATE TABLE bill_port_counters_tmp(port_id int NOT NULL PRIMARY KEY, `timestamp` timestamp NOT NULL DEFAULT current_timestamp, in_counter bigint, in_delta bigint NOT NULL DEFAULT 0, out_counter bigint, out_delta bigint NOT NULL DEFAULT 0);
INSERT INTO bill_port_counters_tmp(port_id, timestamp, in_counter, out_counter) SELECT q.port_id, q.max_timestamp, max(i.counter), max(o.counter) FROM (SELECT port_id, MAX(`timestamp`) AS max_timestamp FROM port_in_measurements GROUP BY port_id) q INNER JOIN port_in_measurements i ON q.port_id = i.port_id AND q.max_timestamp = i.timestamp INNER JOIN port_out_measurements o ON q.port_id = o.port_id AND q.max_timestamp = o.timestamp GROUP BY q.port_id, q.max_timestamp;
RENAME TABLE bill_port_counters_tmp TO bill_port_counters;
ALTER TABLE bill_data ADD id int NOT NULL PRIMARY KEY AUTO_INCREMENT FIRST;
DELETE bill_data FROM bill_data INNER JOIN (SELECT bill_id, timestamp, MIN(id) as first_id FROM bill_data GROUP BY bill_id, timestamp HAVING COUNT(id) > 1) q ON bill_data.bill_id = q.bill_id AND bill_data.timestamp = q.timestamp;
ALTER TABLE bill_data DROP id;
ALTER TABLE bill_data ADD PRIMARY KEY (bill_id, timestamp);
ALTER TABLE bill_data DROP INDEX bill_id_2;
DROP TABLE port_in_measurements;
DROP TABLE port_out_measurements;

View File

@@ -1,2 +1,2 @@
ALTER TABLE `alert_schedule` CHANGE `start` `start` DATETIME NOT NULL DEFAULT '1970-01-02 00:00:01', CHANGE `end` `end` DATETIME NOT NULL DEFAULT '1970-01-02 00:00:01';
ALTER TABLE alert_schedule ADD COLUMN `recurring` tinyint (1) UNSIGNED NOT NULL DEFAULT 0 AFTER `schedule_id`, ADD COLUMN `start_recurring_dt` DATE NOT NULL DEFAULT '1970-01-01 00:00:01' AFTER `end`, ADD COLUMN `end_recurring_dt` DATE DEFAULT NULL AFTER `start_recurring_dt`, ADD COLUMN `start_recurring_hr` TIME NOT NULL DEFAULT '00:00:00' AFTER `end_recurring_dt`, ADD COLUMN `end_recurring_hr` TIME NOT NULL DEFAULT '00:00:00' AFTER `start_recurring_hr`, ADD COLUMN `recurring_day` VARCHAR(15) AFTER `end_recurring_hr`;
ALTER TABLE alert_schedule ADD COLUMN `recurring` tinyint (1) UNSIGNED NOT NULL DEFAULT 0 AFTER `schedule_id`, ADD COLUMN `start_recurring_dt` DATE NOT NULL DEFAULT '1970-01-01 00:00:01' AFTER `end`, ADD COLUMN `end_recurring_dt` DATE DEFAULT NULL AFTER `start_recurring_dt`, ADD COLUMN `start_recurring_hr` TIME NOT NULL DEFAULT '00:00:00' AFTER `end_recurring_dt`, ADD COLUMN `end_recurring_hr` TIME NOT NULL DEFAULT '00:00:00' AFTER `start_recurring_hr`, ADD COLUMN `recurring_day` VARCHAR(15) AFTER `end_recurring_hr`;

View File

@@ -1 +1 @@
INSERT INTO config (config_name,config_value,config_default,config_descr,config_group,config_group_order,config_sub_group,config_sub_group_order,config_hidden,config_disabled) values ('alert.transports.smseagle.url','','','SMSEagle API URL','alerting',0,'transports',0,'0','0'),('alert.transports.smseagle.user','','','SMSEagle User','alerting',0,'transports',0,'0','0'),('alert.transports.smseagle.token','','','SMSEagle Token','alerting',0,'transports',0,'0','0')
INSERT INTO config (config_name,config_value,config_default,config_descr,config_group,config_group_order,config_sub_group,config_sub_group_order,config_hidden,config_disabled) values ('alert.transports.smseagle.url','','','SMSEagle API URL','alerting',0,'transports',0,'0','0'),('alert.transports.smseagle.user','','','SMSEagle User','alerting',0,'transports',0,'0','0'),('alert.transports.smseagle.token','','','SMSEagle Token','alerting',0,'transports',0,'0','0');

View File

@@ -39,6 +39,34 @@ class DBSetupTest extends DBTestCase
}
}
public function testSchemaFiles()
{
global $config;
$files = glob($config['install_dir'].'/sql-schema/*.sql');
foreach ($files as $file) {
$content = file_get_contents($file);
foreach (explode("\n", $content) as $line) {
// skip comments and empty lines
if (empty($line) || starts_with($line, array('#', '--'))) {
continue;
}
// each line must end with ;, prevents multiline and makes sql easy to run by hand
// Warning may include whitespace such as space and \r
if (!ends_with($line, ';')) {
throw new PHPUnitException("Each line must end with a semicolin (;)\n$file: $line");
}
// cannot assume user use the librenms database name
if (str_contains($line, 'librenms')) {
throw new PHPUnitException("Do not include the database name in schema files\n$file: $line");
}
}
}
}
public function testSchema()
{
$schema = get_db_schema();