clqms-be/app/Database/Migrations/2026-03-25-000050_CreateAuditLogs.php
root 30c4e47304 chore(repo): normalize EOL and harden contact patch flow
- handle contact PATCH failures by checking model save result and returning HTTP 400 with the model error message
- update ContactDetailModel nested updates to enforce active-detail checks and use model update() with explicit failure propagation
- extend contact patch assertions and align test-create variants expectations to status=success for POST responses
- refresh composer lock metadata/dependency constraints and include generated docs/data/test files updated during normalization
- impact: API contract unchanged except clearer 400 error responses on invalid contact detail updates
2026-04-17 05:38:11 +07:00

138 lines
4.3 KiB
PHP
Executable File

<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateAuditLogs extends Migration
{
private array $logTables = [
'logpatient' => 'LogPatientID',
'logorder' => 'LogOrderID',
'logmaster' => 'LogMasterID',
'logsystem' => 'LogSystemID',
];
public function up(): void
{
foreach ($this->logTables as $table => $pk) {
$this->createLogTable($table, $pk);
}
}
public function down(): void
{
foreach (array_reverse($this->logTables) as $table => $pk) {
$this->forge->dropTable($table, true);
}
}
private function createLogTable(string $table, string $primaryKey): void
{
$fields = [
$primaryKey => [
'type' => 'BIGINT',
'constraint' => 20,
'unsigned' => true,
'auto_increment' => true,
],
'TblName' => [
'type' => 'VARCHAR',
'constraint' => 64,
],
'RecID' => [
'type' => 'VARCHAR',
'constraint' => 64,
],
'FldName' => [
'type' => 'VARCHAR',
'constraint' => 128,
'null' => true,
],
'FldValuePrev' => [
'type' => 'TEXT',
'null' => true,
],
'FldValueNew' => [
'type' => 'TEXT',
'null' => true,
],
'UserID' => [
'type' => 'VARCHAR',
'constraint' => 64,
],
'SiteID' => [
'type' => 'VARCHAR',
'constraint' => 32,
],
'DIDType' => [
'type' => 'VARCHAR',
'constraint' => 32,
'null' => true,
],
'DID' => [
'type' => 'VARCHAR',
'constraint' => 128,
'null' => true,
],
'MachineID' => [
'type' => 'VARCHAR',
'constraint' => 128,
'null' => true,
],
'SessionID' => [
'type' => 'VARCHAR',
'constraint' => 128,
],
'AppID' => [
'type' => 'VARCHAR',
'constraint' => 64,
],
'ProcessID' => [
'type' => 'VARCHAR',
'constraint' => 128,
'null' => true,
],
'WebPageID' => [
'type' => 'VARCHAR',
'constraint' => 128,
'null' => true,
],
'EventID' => [
'type' => 'VARCHAR',
'constraint' => 80,
],
'ActivityID' => [
'type' => 'VARCHAR',
'constraint' => 24,
],
'Reason' => [
'type' => 'VARCHAR',
'constraint' => 512,
'null' => true,
],
'LogDate' => [
'type' => 'DATETIME',
'constraint' => 3,
],
'Context' => [
'type' => 'JSON',
],
'IpAddress' => [
'type' => 'VARCHAR',
'constraint' => 45,
'null' => true,
],
];
$this->forge->addField($fields);
$this->forge->addKey($primaryKey, true);
$this->forge->addKey(['LogDate'], false, false, "idx_{$table}_logdate");
$this->forge->addKey(['RecID', 'LogDate'], false, false, "idx_{$table}_recid_logdate");
$this->forge->addKey(['UserID', 'LogDate'], false, false, "idx_{$table}_userid_logdate");
$this->forge->addKey(['EventID', 'LogDate'], false, false, "idx_{$table}_eventid_logdate");
$this->forge->addKey(['SiteID', 'LogDate'], false, false, "idx_{$table}_site_logdate");
$this->forge->createTable($table, true);
}
}