<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;
use Config\Database;

class RequirePembelianPaymentStatus extends Migration
{
    public function up()
    {
        Database::connect()
            ->table('pembelian')
            ->where('status_pembayaran', null)
            ->update(['status_pembayaran' => 'hutang']);

        $this->forge->modifyColumn('pembelian', [
            'status_pembayaran' => [
                'name'       => 'status_pembayaran',
                'type'       => 'ENUM',
                'constraint' => ['hutang', 'lunas'],
                'null'       => false,
                'default'    => 'hutang',
            ],
        ]);
    }

    public function down()
    {
        $this->forge->modifyColumn('pembelian', [
            'status_pembayaran' => [
                'name'       => 'status_pembayaran',
                'type'       => 'ENUM',
                'constraint' => ['hutang', 'lunas'],
                'null'       => true,
                'default'    => 'hutang',
            ],
        ]);
    }
}
