<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateQrScanLogsTable extends Migration
{
    public function up(): void
    {
        $this->forge->addField([
            'id'         => ['type' => 'INT', 'auto_increment' => true],
            'student_id' => ['type' => 'INT'],
            'date'       => ['type' => 'DATE'],
            'scan_time'  => ['type' => 'TIME'],
            'source_ip'  => ['type' => 'VARCHAR', 'constraint' => 45, 'null' => true],
            'created_at' => ['type' => 'DATETIME', 'null' => true],
        ]);
        $this->forge->addKey('id', true);
        $this->forge->addUniqueKey(['student_id', 'date']);
        $this->forge->addKey('student_id');
        $this->forge->createTable('qr_scan_logs');
    }

    public function down(): void
    {
        $this->forge->dropTable('qr_scan_logs', true);
    }
}
