39 lines
1.4 KiB
PHP
39 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Database\Migrations;
|
|
|
|
use CodeIgniter\Database\Migration;
|
|
|
|
class CreateActivityLogs extends Migration
|
|
{
|
|
public function up(): void
|
|
{
|
|
if ($this->db->tableExists('activity_logs')) {
|
|
return;
|
|
}
|
|
|
|
$this->forge->addField([
|
|
'id' => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true],
|
|
'actor_user_id' => ['type' => 'INT', 'unsigned' => true, 'null' => true],
|
|
'actor_role' => ['type' => 'VARCHAR', 'constraint' => 20, 'null' => true],
|
|
'action' => ['type' => 'VARCHAR', 'constraint' => 100],
|
|
'description' => ['type' => 'TEXT', 'null' => true],
|
|
'target_type' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
|
|
'target_id' => ['type' => 'INT', 'unsigned' => true, 'null' => true],
|
|
'ip_address' => ['type' => 'VARCHAR', 'constraint' => 45, 'null' => true],
|
|
'user_agent' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
|
|
'created_at' => ['type' => 'DATETIME'],
|
|
]);
|
|
$this->forge->addKey('id', true);
|
|
$this->forge->addKey('actor_user_id');
|
|
$this->forge->addKey('action');
|
|
$this->forge->addKey('created_at');
|
|
$this->forge->createTable('activity_logs', true);
|
|
}
|
|
|
|
public function down(): void
|
|
{
|
|
$this->forge->dropTable('activity_logs', true);
|
|
}
|
|
}
|