<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class RequireHargaColumnsNotNull extends Migration
{
    public function up()
    {
        $integerPrice = [
            'type'       => 'BIGINT',
            'constraint' => 20,
            'unsigned'   => true,
            'null'       => false,
            'default'    => 0,
        ];

        $this->forge->modifyColumn('barang', [
            'harga_beli'      => ['name' => 'harga_beli'] + $integerPrice,
            'harga_beli_awal' => ['name' => 'harga_beli_awal'] + $integerPrice,
            'harga_jual'      => ['name' => 'harga_jual'] + $integerPrice,
        ]);

        $this->forge->modifyColumn('barang_masuk_detail', [
            'harga_beli' => ['name' => 'harga_beli'] + $integerPrice,
            'subtotal'   => ['name' => 'subtotal'] + $integerPrice,
        ]);
    }

    public function down()
    {
        $integerPrice = [
            'type'       => 'BIGINT',
            'constraint' => 20,
            'unsigned'   => true,
            'null'       => true,
            'default'    => 0,
        ];

        $this->forge->modifyColumn('barang', [
            'harga_beli'      => ['name' => 'harga_beli'] + $integerPrice,
            'harga_beli_awal' => ['name' => 'harga_beli_awal'] + $integerPrice,
            'harga_jual'      => ['name' => 'harga_jual'] + $integerPrice,
        ]);

        $this->forge->modifyColumn('barang_masuk_detail', [
            'harga_beli' => ['name' => 'harga_beli'] + $integerPrice,
            'subtotal'   => ['name' => 'subtotal'] + $integerPrice,
        ]);
    }
}
