$row['machineuuid'], 'new' => $new]) === false) { error_log('Result: ' . Database::lastError()); Database::exec("DELETE FROM machine WHERE machineuuid = :old", ['old' => $row['machineuuid']]); } } } // 2019-10-31: New table for per-machine config override $res[] = tableAddConstraint('setting_machine', 'machineuuid', 'machine', 'machineuuid', 'ON UPDATE CASCADE ON DELETE CASCADE'); // 2020-04-25: Track enter/exit standby count, live CPU load if (!tableHasColumn('machine', 'live_cpuload')) { $ret = Database::exec("ALTER TABLE `machine` ADD COLUMN `live_cpuload` tinyint(3) UNSIGNED NOT NULL DEFAULT '255' AFTER `live_memfree`, ADD COLUMN `live_cputemp` tinyint(3) UNSIGNED NOT NULL DEFAULT '0' AFTER `live_cpuload`, ADD COLUMN `standbysem` tinyint(3) UNSIGNED NOT NULL DEFAULT '0', ADD INDEX `live_cpuload` (`live_cpuload`), ADD INDEX `live_cputemp` (`live_cputemp`)"); if ($ret === false) { finalResponse(UPDATE_FAILED, 'Adding live_cpuload column to machine table failed: ' . Database::lastError()); } $res[] = UPDATE_DONE; } // 2020-06-29: Track current runmode (as reported by client) if (!tableHasColumn('machine', 'currentrunmode')) { $ret = Database::exec("ALTER TABLE `machine` ADD COLUMN `currentrunmode` varchar(30) NOT NULL DEFAULT '' AFTER `hostname`"); if ($ret === false) { finalResponse(UPDATE_FAILED, 'Adding live_cpuload column to machine table failed: ' . Database::lastError()); } $res[] = UPDATE_DONE; } // 2019-01-25: Add memory/temp stats column if (!tableHasColumn('machine', 'live_id45size')) { $ret = Database::exec("ALTER TABLE `machine` ADD COLUMN `live_id45size` int(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `live_tmpfree`, ADD COLUMN `live_id45free` int(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `live_id45size`"); if ($ret === false) { finalResponse(UPDATE_FAILED, 'Adding mem-stat columns to machine table failed: ' . Database::lastError()); } $res[] = UPDATE_DONE; } // 2021-08-19 Enhanced machine property indexing if (stripos(tableColumnType('statistic_hw_prop', 'prop'), 'varchar(64)') === false) { Database::exec("DELETE FROM statistic_hw_prop WHERE prop NOT REGEXP BINARY '^[a-zA-Z0-9_ =@*!.:/\\\\-]+$'"); $ret = Database::exec("ALTER TABLE statistic_hw_prop MODIFY `prop` varchar(64) CHARACTER SET ascii NOT NULL, ADD `numeric` bigint(20) DEFAULT NULL"); if ($ret === false) { finalResponse(UPDATE_FAILED, 'Changing prop of statistic_hw_prop failed: ' . Database::lastError()); } $res[] = UPDATE_DONE; } if (stripos(tableColumnType('machine_x_hw_prop', 'prop'), 'varchar(64)') === false) { Database::exec("DELETE FROM machine_x_hw_prop WHERE prop NOT REGEXP BINARY '^[a-zA-Z0-9_ =@*!.:/\\\\-]+$'"); $ret = Database::exec("ALTER TABLE machine_x_hw_prop MODIFY `prop` varchar(64) CHARACTER SET ascii NOT NULL, ADD `numeric` bigint(20) DEFAULT NULL"); if ($ret === false) { finalResponse(UPDATE_FAILED, 'Changing prop of machine_x_hw_prop failed: ' . Database::lastError()); } $res[] = UPDATE_DONE; } if (stripos(tableColumnType('statistic_hw', 'hwname'), 'char(32)') === false) { Database::exec("DELETE FROM statistic_hw WHERE hwname NOT REGEXP BINARY '^[a-zA-Z0-9_ =@*!.:/\\\\-]+$'"); $ret = Database::exec("ALTER TABLE statistic_hw MODIFY `hwname` char(32) CHARACTER SET ascii NOT NULL, MODIFY `hwtype` char(16) CHARACTER SET ascii NOT NULL"); if ($ret === false) { finalResponse(UPDATE_FAILED, 'Changing hwname/hwtype of statistic_hw failed: ' . Database::lastError()); } $res[] = UPDATE_DONE; } if (stripos(tableColumnType('machine_x_hw', 'devpath'), 'char(32)') === false) { Database::exec("DELETE FROM machine_x_hw WHERE devpath NOT REGEXP BINARY '^[a-zA-Z0-9_ =@*!.:/\\\\-]+$'"); $ret = Database::exec("ALTER TABLE machine_x_hw MODIFY `devpath` char(32) CHARACTER SET ascii NOT NULL"); if ($ret === false) { finalResponse(UPDATE_FAILED, 'Changing devpath of machine_x_hw failed: ' . Database::lastError()); } $res[] = UPDATE_DONE; } if (!tableHasColumn('machine', 'dataparsetime')) { $ret = Database::exec("ALTER TABLE `machine` ADD COLUMN `dataparsetime` int(10) unsigned NOT NULL DEFAULT '0' AFTER `data`"); if ($ret === false) { finalResponse(UPDATE_FAILED, 'Adding dateparsetime column to machine table failed: ' . Database::lastError()); } $res[] = UPDATE_DONE; } if (!tableHasColumn('machine', 'id45mb')) { $ret = Database::exec("ALTER TABLE `machine` ADD COLUMN `id45mb` int(10) unsigned NOT NULL DEFAULT 0 AFTER `id44mb`"); if ($ret === false) { finalResponse(UPDATE_FAILED, 'Adding id45mb column to machine table failed: ' . Database::lastError()); } $res[] = UPDATE_DONE; } // 2022-11-22 Change data column of statistic table from varchar(255) to blob if (stripos(tableColumnType('statistic', 'data'), 'blob') === false) { $ret = Database::exec("ALTER TABLE `statistic` MODIFY COLUMN `data` BLOB NOT NULL"); if ($ret === false) { finalResponse(UPDATE_FAILED, 'Changing statistic.data to blob failed: ' . Database::lastError()); } $res[] = UPDATE_DONE; } // Create response responseFromArray($res);