mirror of
https://github.com/itflow-org/itflow
synced 2026-12-04 10:09:01 +00:00
Racks: devices side by side in a holder - a rack item that holds devices across and wraps into rows for stacks, with slots to add to, drag between and Undo, the holder moving and removing what is in it, the slot shown on assets, the export and the API, and database 4.1.3 for rack_units slots, holder and position
This commit is contained in:
51
admin/database_updates/4.1.3.php
Normal file
51
admin/database_updates/4.1.3.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* ITFlow - Database update to version 4.1.3 (from 4.1.2)
|
||||
* Included by admin/database_updates.php - do not access directly
|
||||
*
|
||||
* More than one device on a rack row - two Tiny PCs in a 1U bracket, eight PLCs on
|
||||
* a shelf, a media converter chassis. A holder is a rack item that devices go in
|
||||
* side by side; each device is a rack item of its own, in one of the holder's slots.
|
||||
*
|
||||
* rack_units.unit_slots how many fit side by side, on a holder - 0 for any other item.
|
||||
* Devices past that wrap onto another row, for stacks.
|
||||
* rack_units.unit_parent_id the holder a device sits in, NULL for one in the rack itself.
|
||||
* Removing the holder takes its devices out with it.
|
||||
* rack_units.unit_position the device's slot in its holder - 1 is the first, counting across
|
||||
* and then a row on.
|
||||
*
|
||||
* A device in a holder keeps the holder's units, face and depth in its own columns, so
|
||||
* whatever reads where something is racked reads it the same way.
|
||||
*
|
||||
* Re-runnable: it only adds what isn't there.
|
||||
*/
|
||||
|
||||
defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
|
||||
|
||||
$itflow_has = function ($what, $name) use ($mysqli) {
|
||||
$table = $what === 'column' ? 'COLUMNS' : ($what === 'key' ? 'STATISTICS' : 'TABLE_CONSTRAINTS');
|
||||
$field = $what === 'column' ? 'COLUMN_NAME' : ($what === 'key' ? 'INDEX_NAME' : 'CONSTRAINT_NAME');
|
||||
$schema = $what === 'constraint' ? 'CONSTRAINT_SCHEMA' : 'TABLE_SCHEMA';
|
||||
$result = mysqli_query($mysqli, "SELECT 1 FROM information_schema.$table
|
||||
WHERE $schema = DATABASE() AND TABLE_NAME = 'rack_units' AND $field = '$name' LIMIT 1");
|
||||
return $result && mysqli_num_rows($result) > 0;
|
||||
};
|
||||
|
||||
if (!$itflow_has('column', 'unit_slots')) {
|
||||
mysqli_query($mysqli, "ALTER TABLE `rack_units` ADD `unit_slots` int(11) NOT NULL DEFAULT 0 AFTER `unit_notes`");
|
||||
}
|
||||
if (!$itflow_has('column', 'unit_position')) {
|
||||
mysqli_query($mysqli, "ALTER TABLE `rack_units` ADD `unit_position` int(11) NOT NULL DEFAULT 0 AFTER `unit_slots`");
|
||||
}
|
||||
if (!$itflow_has('column', 'unit_parent_id')) {
|
||||
mysqli_query($mysqli, "ALTER TABLE `rack_units` ADD `unit_parent_id` int(11) DEFAULT NULL AFTER `unit_rack_id`");
|
||||
}
|
||||
if (!$itflow_has('key', 'unit_parent_id')) {
|
||||
mysqli_query($mysqli, "ALTER TABLE `rack_units` ADD KEY `unit_parent_id` (`unit_parent_id`)");
|
||||
}
|
||||
if (!$itflow_has('constraint', 'rack_units_ibfk_2')) {
|
||||
mysqli_query($mysqli, "ALTER TABLE `rack_units` ADD CONSTRAINT `rack_units_ibfk_2` FOREIGN KEY (`unit_parent_id`) REFERENCES `rack_units` (`unit_id`) ON DELETE CASCADE");
|
||||
}
|
||||
|
||||
unset($itflow_has);
|
||||
Reference in New Issue
Block a user