<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddShortCodeToTeachers extends Migration
{
    public function up()
    {
        $this->forge->addColumn('teachers', [
            'short_code' => [
                'type'       => 'VARCHAR',
                'constraint' => 20,
                'null'       => true,
                'default'    => null,
                'comment'    => 'Kode singkat guru, misal: 01, 32 — sesuai kode di aSc Timetables',
                'after'      => 'nip',
            ],
        ]);

        // Tambahkan index untuk mempercepat pencarian saat matching
        $this->forge->addKey('short_code');
        $this->db->query('ALTER TABLE teachers ADD INDEX idx_teacher_short_code (short_code)');
    }

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