<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * Migration 017 — Admin activity log (audit trail)
 * Records who did what and when, across the back-office.
 */
class Migration_Create_activity_log extends CI_Migration {

	public function up()
	{
		$this->dbforge->add_field(array(
			'id'         => array('type' => 'INT', 'constraint' => 11, 'unsigned' => TRUE, 'auto_increment' => TRUE),
			'user_id'    => array('type' => 'INT', 'constraint' => 11, 'null' => TRUE),
			'action'     => array('type' => 'VARCHAR', 'constraint' => 160),
			'detail'     => array('type' => 'TEXT', 'null' => TRUE),
			'ip_address' => array('type' => 'VARCHAR', 'constraint' => 45, 'null' => TRUE),
			'created_at' => array('type' => 'DATETIME', 'null' => TRUE),
		));
		$this->dbforge->add_key('id', TRUE);
		$this->dbforge->add_key('user_id');
		$this->dbforge->create_table('activity_log', TRUE, array('ENGINE' => 'InnoDB'));
	}

	public function down()
	{
		$this->dbforge->drop_table('activity_log', TRUE);
	}
}
