Skip to content

Commit

Permalink
Change schema. change_log.note -> change_log.notes. Varchar to text, …
Browse files Browse the repository at this point in the history
…as per other notes columns.
  • Loading branch information
mark-unwin committed Mar 18, 2024
1 parent 8676183 commit 471ef06
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/Models/ComponentsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,7 @@ public function upsert(string $table = '', object $device = null, array $data =
}
$alert_details = substr($alert_details, 0, -2);
$alert_details = "Item added to {$table} - {$alert_details}";
$sql = 'INSERT INTO change_log (device_id, db_table, db_row, db_action, details, `timestamp`) VALUES (?, ?, ?, ?, ?, ?)';
$sql = 'INSERT INTO change_log (device_id, db_table, db_row, db_action, details, `timestamp`, `notes`) VALUES (?, ?, ?, ?, ?, ?, "")';
$query = $this->db->query($sql, [intval($device->id), "{$table}", intval($id), 'create', "{$alert_details}", "{$device->last_seen}"]);
// add a count to our chart table
$sql = "INSERT INTO chart (`when`, `what`, `org_id`, `count`) VALUES (DATE(NOW()), '{$table}_create', " . intval($device->org_id) . ', 1) ON DUPLICATE KEY UPDATE `count` = `count` + 1';
Expand Down Expand Up @@ -1384,7 +1384,7 @@ public function upsert(string $table = '', object $device = null, array $data =
}
$alert_details = substr($alert_details, 0, -2);
$alert_details = "Item removed from {$table} - {$alert_details}";
$sql = 'INSERT INTO change_log (device_id, db_table, db_row, db_action, details, `timestamp`) VALUES (?, ?, ?, ?, ?, ?)';
$sql = 'INSERT INTO change_log (device_id, db_table, db_row, db_action, details, `timestamp`, `notes`) VALUES (?, ?, ?, ?, ?, ?, "")';
$query = $this->db->query($sql, [intval($device->id), "{$table}", intval($db_item->id), 'delete', "{$alert_details}", "{$device->last_seen}"]);
// add a count to our chart table
$sql = "INSERT INTO chart (`when`, `what`, `org_id`, `count`) VALUES (DATE(NOW()), '{$table}_delete', " . intval($device->org_id) . ', 1) ON DUPLICATE KEY UPDATE `count` = `count` + 1';
Expand Down
9 changes: 8 additions & 1 deletion app/Models/db_upgrades/db_5.2.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@
}

if (!$db->fieldExists('ack_by', 'change_log')) {
$sql = "ALTER TABLE `change_log` ADD `ack_by` varchar(200) NOT NULL DEFAULT ''";
$sql = "ALTER TABLE `change_log` ADD `ack_by` varchar(200) NOT NULL DEFAULT '' AFTER `details`";
$db->query($sql);
$output .= str_replace("\n", " ", (string)$db->getLastQuery()) . "\n\n";
log_message('info', (string)$db->getLastQuery());
}

if (!$db->fieldExists('notes', 'change_log') and $db->fieldExists('note', 'change_log')) {
$sql = "ALTER TABLE `change_log` CHANGE `note` `notes` TEXT NOT NULL";
$db->query($sql);
$output .= str_replace("\n", " ", (string)$db->getLastQuery()) . "\n\n";
log_message('info', (string)$db->getLastQuery());
Expand Down
2 changes: 1 addition & 1 deletion other/open-audit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ CREATE TABLE `change_log` (
`ack_time` datetime NOT NULL DEFAULT '2000-01-01 00:00:00',
`external_link` varchar(200) NOT NULL DEFAULT '',
`external_ident` varchar(200) NOT NULL DEFAULT '',
`note` varchar(200) NOT NULL DEFAULT '',
`notes` text NOT NULL,
`change_id` int(10) unsigned DEFAULT NULL,
`change_type` enum('','standard','normal','emergency','unauthorised') NOT NULL DEFAULT '',
`timestamp` datetime NOT NULL DEFAULT '2000-01-01 00:00:00',
Expand Down

0 comments on commit 471ef06

Please sign in to comment.