<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddTaxPercentToAppSetting extends Migration
{
    public function up()
    {
        $db = \Config\Database::connect();

        if (! $db->fieldExists('pajak_persen', 'app_setting')) {
            $this->forge->addColumn('app_setting', [
                'pajak_persen' => [
                    'type'       => 'INT',
                    'constraint' => 3,
                    'unsigned'   => true,
                    'default'    => 11,
                    'after'      => 'nama_perusahaan',
                ],
            ]);
        }

        $db->table('app_setting')
            ->set('pajak_persen', 11)
            ->where('pajak_persen IS NULL', null, false)
            ->update();
    }

    public function down()
    {
        $db = \Config\Database::connect();

        if ($db->fieldExists('pajak_persen', 'app_setting')) {
            $this->forge->dropColumn('app_setting', 'pajak_persen');
        }
    }
}
