doctor-appointment-system/app/Database/Migrations/2026-04-15-120000_AlterActivityLogsTable.php
2026-04-17 10:46:29 +05:30

133 lines
4.1 KiB
PHP

<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class AlterActivityLogsTable extends Migration
{
public function up()
{
// Drop the old table
$this->db->disableForeignKeyChecks();
$this->forge->dropTable('activity_logs', true);
$this->db->enableForeignKeyChecks();
// Create the new table with the specified structure
$this->forge->addField([
'id' => [
'type' => 'BIGINT',
'auto_increment' => true,
],
'ip' => [
'type' => 'VARCHAR',
'constraint' => 45,
'null' => true,
],
'action' => [
'type' => 'VARCHAR',
'constraint' => 100,
'null' => false,
],
'description' => [
'type' => 'TEXT',
'null' => true,
],
'activity_user_id' => [
'type' => 'BIGINT',
'null' => true,
],
'activity_user_type' => [
'type' => 'ENUM',
'constraint' => ['admin', 'doctor', 'patient'],
'null' => true,
],
'target_user_id' => [
'type' => 'BIGINT',
'null' => true,
],
'target_user_type' => [
'type' => 'ENUM',
'constraint' => ['admin', 'doctor', 'patient'],
'null' => true,
],
'activity_page' => [
'type' => 'VARCHAR',
'constraint' => 255,
'null' => true,
],
'activity_at' => [
'type' => 'DATETIME',
'null' => false,
],
]);
$this->forge->addKey('id', true);
$this->forge->addKey('activity_user_id');
$this->forge->addKey('target_user_id');
$this->forge->addKey('action');
$this->forge->addKey('activity_at');
$this->forge->addKey('ip');
$this->forge->createTable('activity_logs');
}
public function down()
{
// Revert to original table structure if rollback
$this->db->disableForeignKeyChecks();
$this->forge->dropTable('activity_logs', true);
$this->db->enableForeignKeyChecks();
// Recreate original structure
$this->forge->addField([
'id' => [
'type' => 'BIGINT',
'auto_increment' => true,
],
'actor_user_id' => [
'type' => 'BIGINT',
'null' => true,
],
'actor_role' => [
'type' => 'VARCHAR',
'constraint' => 50,
'null' => true,
],
'action' => [
'type' => 'VARCHAR',
'constraint' => 100,
],
'description' => [
'type' => 'TEXT',
'null' => true,
],
'target_type' => [
'type' => 'VARCHAR',
'constraint' => 100,
'null' => true,
],
'target_id' => [
'type' => 'BIGINT',
'null' => true,
],
'ip_address' => [
'type' => 'VARCHAR',
'constraint' => 45,
'null' => true,
],
'user_agent' => [
'type' => 'TEXT',
'null' => true,
],
'created_at' => [
'type' => 'DATETIME',
'null' => false,
],
]);
$this->forge->addKey('id', true);
$this->forge->createTable('activity_logs');
}
}