<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddAngkaKreditToPengajuan extends Migration
{
    public function up()
    {
        $fields = [
            'angka_kredit_lama' => [
                'type' => 'VARCHAR',
                'constraint' => '50',
                'null' => true,
                'after' => 'masa_kerja_bulan'
            ],
            'angka_kredit_baru' => [
                'type' => 'VARCHAR',
                'constraint' => '50',
                'null' => true,
                'after' => 'angka_kredit_lama'
            ],
        ];

        // Indempotent check
        if (!$this->db->fieldExists('angka_kredit_lama', 'pengajuan')) {
            $this->forge->addColumn('pengajuan', $fields);
        }
    }

    public function down()
    {
        $this->forge->dropColumn('pengajuan', 'angka_kredit_lama');
        $this->forge->dropColumn('pengajuan', 'angka_kredit_baru');
    }
}
