<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddDetailFieldsToBarangTable extends Migration
{
    public function up()
    {
        $this->forge->addColumn('barang', [
            'deskripsi_barang' => [
                'type' => 'TEXT',
                'null' => true,
                'after' => 'nama_barang',
            ],
            'lokasi_barang' => [
                'type'       => 'VARCHAR',
                'constraint' => 150,
                'null'       => true,
                'after'      => 'satuan',
            ],
            'stok_awal' => [
                'type'       => 'INT',
                'constraint' => 11,
                'default'    => 0,
                'after'      => 'stok_minimum',
            ],
        ]);

        $this->db->table('barang')
            ->set('stok_awal', 'stok', false)
            ->update();
    }

    public function down()
    {
        $this->forge->dropColumn('barang', [
            'deskripsi_barang',
            'lokasi_barang',
            'stok_awal',
        ]);
    }
}
