Files
cms-gov/app/Database/Migrations/2025-01-20-100004_CreateAuditLogsTable.php

56 lines
1.5 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateAuditLogsTable extends Migration
{
public function up()
{
$this->forge->addField([
'id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
'auto_increment' => true,
],
'user_id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
'null' => true,
],
'action' => [
'type' => 'VARCHAR',
'constraint' => 100,
],
'ip_address' => [
'type' => 'VARCHAR',
'constraint' => 45,
],
'user_agent' => [
'type' => 'TEXT',
'null' => true,
],
'created_at' => [
'type' => 'DATETIME',
'null' => true,
],
]);
$this->forge->addKey('id', true);
$this->forge->addKey('user_id');
$this->forge->addKey('action');
$this->forge->addKey('created_at');
$this->forge->addForeignKey('user_id', 'users', 'id', 'SET NULL', 'CASCADE');
$this->forge->createTable('audit_logs', true, ['ENGINE' => 'InnoDB']);
}
public function down()
{
$this->forge->dropTable('audit_logs');
}
}