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'); } }