<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

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

        if (! $db->fieldExists('nota_penjualan_ukuran', 'app_setting')) {
            $this->forge->addColumn('app_setting', [
                'nota_penjualan_ukuran' => [
                    'type'       => 'VARCHAR',
                    'constraint' => 20,
                    'default'    => 'thermal_58',
                    'after'      => 'pajak_persen',
                ],
            ]);
        }

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

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

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