Add soft deletes via status column

- Add status ENUM('active','disabled','deleted') to 8 tables
- Change all physical DELETE to UPDATE status='deleted'
- All SELECT queries filter by status='active'
- toggleActive now alternates between active/disabled status
- Exceptions: monitoring_history, rate_limits, sessions keep physical purge
- audit_logs remains immutable
This commit is contained in:
2026-06-07 17:26:29 -04:00
parent 921d98bf60
commit 1741545318
6 changed files with 138 additions and 60 deletions

View File

@@ -33,7 +33,7 @@ class CommandHistory
'SELECT ch.*, u.username
FROM command_history ch
LEFT JOIN users u ON ch.user_id = u.id
WHERE ch.server_id = ?
WHERE ch.server_id = ? AND ch.status = \'active\'
ORDER BY ch.executed_at DESC
LIMIT ?',
[$serverId, $limit]
@@ -47,6 +47,7 @@ class CommandHistory
FROM command_history ch
LEFT JOIN users u ON ch.user_id = u.id
LEFT JOIN servers s ON ch.server_id = s.id
WHERE ch.status = \'active\'
ORDER BY ch.executed_at DESC
LIMIT ?',
[$limit]
@@ -60,7 +61,7 @@ class CommandHistory
FROM command_history ch
LEFT JOIN users u ON ch.user_id = u.id
LEFT JOIN servers s ON ch.server_id = s.id
WHERE ch.id = ?',
WHERE ch.id = ? AND ch.status = \'active\'',
[$id]
);
}
@@ -68,8 +69,17 @@ class CommandHistory
public function clearHistory(int $serverId = null): int
{
if ($serverId) {
return $this->db->delete('command_history', 'server_id = ?', [$serverId]);
return $this->db->update(
'command_history',
['status' => 'deleted'],
'server_id = ?',
[$serverId]
);
}
return $this->db->delete('command_history', '1=1');
return $this->db->update(
'command_history',
['status' => 'deleted'],
'1=1'
);
}
}