<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddIsLockedToScheduleEntries extends Migration
{
    public function up()
    {
        // Tambah kolom is_locked ke schedule_entries
        // Lock per-entry: entry yang di-lock tidak akan dihapus/ditimpa saat re-generate
        $this->forge->addColumn('schedule_entries', [
            'is_locked' => [
                'type'    => 'TINYINT',
                'constraint' => 1,
                'default' => 0,
                'after'   => 'is_manual',
                'comment' => '1=dikunci, tidak akan ditimpa saat generate ulang',
            ],
        ]);

        // Index untuk query cepat saat generator skip locked entries
        $this->db->query('ALTER TABLE schedule_entries ADD INDEX idx_locked (schedule_id, is_locked)');
    }

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