reorganize database migrations with corrected numbering

This commit is contained in:
mahdahar 2026-02-23 05:11:23 +07:00
parent d173098652
commit 5272efa7b9
10 changed files with 3 additions and 165 deletions

View File

@ -1,162 +0,0 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateAuditLogs extends Migration {
public function up() {
// Drop old audit tables if they exist
$this->forge->dropTable('patreglog', true);
$this->forge->dropTable('patvisitlog', true);
$this->forge->dropTable('specimenlog', true);
// Create data_audit_log table
$this->forge->addField([
'id' => ['type' => 'BIGINT', 'constraint' => 20, 'unsigned' => true, 'auto_increment' => true],
'operation' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => false],
'entity_type' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => false],
'entity_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => false],
'table_name' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
'field_name' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
'previous_value' => ['type' => 'JSON', 'null' => true],
'new_value' => ['type' => 'JSON', 'null' => true],
'mechanism' => ['type' => 'ENUM', 'constraint' => ['MANUAL', 'AUTOMATIC'], 'null' => false, 'default' => 'MANUAL'],
'application_id' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
'web_page' => ['type' => 'VARCHAR', 'constraint' => 500, 'null' => true],
'session_id' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
'event_type' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
'site_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => true],
'workstation_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => true],
'pc_name' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
'ip_address' => ['type' => 'VARCHAR', 'constraint' => 45, 'null' => true],
'user_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => false],
'created_at' => ['type' => 'DATETIME', 'null' => false],
'reason' => ['type' => 'TEXT', 'null' => true],
'context' => ['type' => 'JSON', 'null' => true]
]);
$this->forge->addKey('id', true);
$this->forge->addKey('idx_operation_created', ['operation', 'created_at']);
$this->forge->addKey('idx_entity', ['entity_type', 'entity_id', 'created_at']);
$this->forge->addKey('idx_user_created', ['user_id', 'created_at']);
$this->forge->addKey('idx_mechanism', ['mechanism', 'created_at']);
$this->forge->addKey('idx_table', ['table_name', 'created_at']);
$this->forge->addKey('idx_site', ['site_id', 'created_at']);
$this->forge->addKey('idx_created', 'created_at');
$this->forge->addKey('idx_session', ['session_id', 'created_at']);
$this->forge->createTable('data_audit_log', true);
// Create service_audit_log table
$this->forge->addField([
'id' => ['type' => 'BIGINT', 'constraint' => 20, 'unsigned' => true, 'auto_increment' => true],
'operation' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => false],
'entity_type' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => false],
'entity_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => false],
'service_class' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
'resource_type' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
'resource_details' => ['type' => 'JSON', 'null' => true],
'previous_value' => ['type' => 'JSON', 'null' => true],
'new_value' => ['type' => 'JSON', 'null' => true],
'mechanism' => ['type' => 'ENUM', 'constraint' => ['MANUAL', 'AUTOMATIC'], 'null' => false, 'default' => 'AUTOMATIC'],
'application_id' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
'service_name' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
'session_id' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
'event_type' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
'site_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => true],
'workstation_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => true],
'pc_name' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
'ip_address' => ['type' => 'VARCHAR', 'constraint' => 45, 'null' => true],
'port' => ['type' => 'INT', 'null' => true],
'user_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => false],
'created_at' => ['type' => 'DATETIME', 'null' => false],
'reason' => ['type' => 'TEXT', 'null' => true],
'context' => ['type' => 'JSON', 'null' => true]
]);
$this->forge->addKey('id', true);
$this->forge->addKey('idx_operation_created', ['operation', 'created_at']);
$this->forge->addKey('idx_entity', ['entity_type', 'entity_id', 'created_at']);
$this->forge->addKey('idx_service_class', ['service_class', 'created_at']);
$this->forge->addKey('idx_user_created', ['user_id', 'created_at']);
$this->forge->addKey('idx_mechanism', ['mechanism', 'created_at']);
$this->forge->addKey('idx_site', ['site_id', 'created_at']);
$this->forge->addKey('idx_created', 'created_at');
$this->forge->createTable('service_audit_log', true);
// Create security_audit_log table
$this->forge->addField([
'id' => ['type' => 'BIGINT', 'constraint' => 20, 'unsigned' => true, 'auto_increment' => true],
'operation' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => false],
'entity_type' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => false],
'entity_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => false],
'security_class' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
'resource_path' => ['type' => 'VARCHAR', 'constraint' => 500, 'null' => true],
'previous_value' => ['type' => 'JSON', 'null' => true],
'new_value' => ['type' => 'JSON', 'null' => true],
'mechanism' => ['type' => 'ENUM', 'constraint' => ['MANUAL', 'AUTOMATIC'], 'null' => false, 'default' => 'MANUAL'],
'application_id' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
'web_page' => ['type' => 'VARCHAR', 'constraint' => 500, 'null' => true],
'session_id' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
'event_type' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
'site_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => true],
'workstation_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => true],
'pc_name' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
'ip_address' => ['type' => 'VARCHAR', 'constraint' => 45, 'null' => true],
'user_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => false],
'created_at' => ['type' => 'DATETIME', 'null' => false],
'reason' => ['type' => 'TEXT', 'null' => true],
'context' => ['type' => 'JSON', 'null' => true]
]);
$this->forge->addKey('id', true);
$this->forge->addKey('idx_operation_created', ['operation', 'created_at']);
$this->forge->addKey('idx_entity', ['entity_type', 'entity_id', 'created_at']);
$this->forge->addKey('idx_security_class', ['security_class', 'created_at']);
$this->forge->addKey('idx_user_created', ['user_id', 'created_at']);
$this->forge->addKey('idx_event_type', ['event_type', 'created_at']);
$this->forge->addKey('idx_site', ['site_id', 'created_at']);
$this->forge->addKey('idx_created', 'created_at');
$this->forge->addKey('idx_session', ['session_id', 'created_at']);
$this->forge->createTable('security_audit_log', true);
// Create error_audit_log table
$this->forge->addField([
'id' => ['type' => 'BIGINT', 'constraint' => 20, 'unsigned' => true, 'auto_increment' => true],
'operation' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => false],
'entity_type' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => false],
'entity_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => false],
'error_code' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
'error_message' => ['type' => 'TEXT', 'null' => true],
'error_details' => ['type' => 'JSON', 'null' => true],
'previous_value' => ['type' => 'JSON', 'null' => true],
'new_value' => ['type' => 'JSON', 'null' => true],
'mechanism' => ['type' => 'ENUM', 'constraint' => ['MANUAL', 'AUTOMATIC'], 'null' => false, 'default' => 'MANUAL'],
'application_id' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
'web_page' => ['type' => 'VARCHAR', 'constraint' => 500, 'null' => true],
'session_id' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
'event_type' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
'site_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => true],
'workstation_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => true],
'pc_name' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
'ip_address' => ['type' => 'VARCHAR', 'constraint' => 45, 'null' => true],
'user_id' => ['type' => 'VARCHAR', 'constraint' => 36, 'null' => false],
'created_at' => ['type' => 'DATETIME', 'null' => false],
'reason' => ['type' => 'TEXT', 'null' => true],
'context' => ['type' => 'JSON', 'null' => true]
]);
$this->forge->addKey('id', true);
$this->forge->addKey('idx_operation_created', ['operation', 'created_at']);
$this->forge->addKey('idx_entity', ['entity_type', 'entity_id', 'created_at']);
$this->forge->addKey('idx_error_code', ['error_code', 'created_at']);
$this->forge->addKey('idx_event_type', ['event_type', 'created_at']);
$this->forge->addKey('idx_user_created', ['user_id', 'created_at']);
$this->forge->addKey('idx_site', ['site_id', 'created_at']);
$this->forge->addKey('idx_created', 'created_at');
$this->forge->createTable('error_audit_log', true);
}
public function down() {
$this->forge->dropTable('error_audit_log');
$this->forge->dropTable('security_audit_log');
$this->forge->dropTable('service_audit_log');
$this->forge->dropTable('data_audit_log');
}
}

View File

@ -127,19 +127,19 @@ class TestSeeder extends Seeder
$data = ['SiteID' => '1', 'TestSiteCode' => 'BMI', 'TestSiteName' => 'Body Mass Index', 'TestType' => 'CALC', 'Description' => 'Indeks Massa Tubuh - weight/(height^2)', 'SeqScr' => '45', 'SeqRpt' => '45', 'IndentLeft' => '0', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '0', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['BMI'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['BMI'], 'DisciplineID' => '10', 'DepartmentID' => '', 'FormulaInput' => 'WEIGHT,HEIGHT', 'FormulaCode' => 'WEIGHT / ((HEIGHT/100) * (HEIGHT/100))', 'ResultType' => 'NMRIC', 'RefType' => 'RANGE', 'Unit1' => 'kg/m2', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'CreateDate' => "$now"];
$data = ['TestSiteID' => $tIDs['BMI'], 'DisciplineID' => '10', 'DepartmentID' => '', 'FormulaInput' => 'WEIGHT,HEIGHT', 'FormulaCode' => 'WEIGHT / ((HEIGHT/100) * (HEIGHT/100))', 'RefType' => 'RANGE', 'Unit1' => 'kg/m2', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'CreateDate' => "$now"];
$this->db->table('testdefcal')->insert($data);
$data = ['SiteID' => '1', 'TestSiteCode' => 'EGFR', 'TestSiteName' => 'eGFR (CKD-EPI)', 'TestType' => 'CALC', 'Description' => 'Estimated Glomerular Filtration Rate', 'SeqScr' => '20', 'SeqRpt' => '20', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '0', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['EGFR'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['EGFR'], 'DisciplineID' => '2', 'DepartmentID' => '2', 'FormulaInput' => 'CREA,AGE,GENDER', 'FormulaCode' => 'CKD_EPI(CREA,AGE,GENDER)', 'ResultType' => 'NMRIC', 'RefType' => 'RANGE', 'Unit1' => 'mL/min/1.73m2', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'CreateDate' => "$now"];
$data = ['TestSiteID' => $tIDs['EGFR'], 'DisciplineID' => '2', 'DepartmentID' => '2', 'FormulaInput' => 'CREA,AGE,GENDER', 'FormulaCode' => 'CKD_EPI(CREA,AGE,GENDER)', 'RefType' => 'RANGE', 'Unit1' => 'mL/min/1.73m2', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'CreateDate' => "$now"];
$this->db->table('testdefcal')->insert($data);
$data = ['SiteID' => '1', 'TestSiteCode' => 'LDLCALC', 'TestSiteName' => 'LDL Cholesterol (Calculated)', 'TestType' => 'CALC', 'Description' => 'Friedewald formula: TC - HDL - (TG/5)', 'SeqScr' => '21', 'SeqRpt' => '21', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '0', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['LDLCALC'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['LDLCALC'], 'DisciplineID' => '2', 'DepartmentID' => '2', 'FormulaInput' => 'CHOL,HDL,TG', 'FormulaCode' => 'CHOL - HDL - (TG/5)', 'ResultType' => 'NMRIC', 'RefType' => 'RANGE', 'Unit1' => 'mg/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'CreateDate' => "$now"];
$data = ['TestSiteID' => $tIDs['LDLCALC'], 'DisciplineID' => '2', 'DepartmentID' => '2', 'FormulaInput' => 'CHOL,HDL,TG', 'FormulaCode' => 'CHOL - HDL - (TG/5)', 'RefType' => 'RANGE', 'Unit1' => 'mg/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'CreateDate' => "$now"];
$this->db->table('testdefcal')->insert($data);
// ========================================