<?php

namespace Tenant\Database\Migrations;

use CodeIgniter\Database\Migration;

/**
 * Captures the request IP address at the moment BaseController::
 * logActivity() writes a row (see that method) — nullable because every
 * row written before this migration has no IP to backfill; those simply
 * show "—" on the Activity Log page rather than a fabricated address.
 * VARCHAR(45) is the standard sizing for either an IPv4 or IPv6 string.
 */
class AddIpAddressToActivityLog extends Migration
{
    public function up()
    {
        $this->forge->addColumn('activity_log', [
            'ip_address' => [
                'type'       => 'VARCHAR',
                'constraint' => 45,
                'null'       => true,
                'after'      => 'action',
            ],
        ]);
    }

    public function down()
    {
        $this->forge->dropColumn('activity_log', 'ip_address');
    }
}
