<?php

declare(strict_types=1);

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddIdPegawaiToAdminUsers extends Migration
{
    public function up(): void
    {
        if (! $this->db->tableExists('admin_users')) {
            return;
        }
        if ($this->db->fieldExists('id_pegawai', 'admin_users')) {
            return;
        }

        $this->forge->addColumn('admin_users', [
            'id_pegawai' => [
                'type'       => 'INT',
                'constraint' => 11,
                'unsigned'   => true,
                'null'       => true,
            ],
        ]);
    }

    public function down(): void
    {
        if (! $this->db->tableExists('admin_users')) {
            return;
        }
        if (! $this->db->fieldExists('id_pegawai', 'admin_users')) {
            return;
        }

        $this->forge->dropColumn('admin_users', 'id_pegawai');
    }
}
