<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class RemoveHargaDefaultFromMaklonAndReseller extends Migration
{
    public function up(): void
    {
        if ($this->db->fieldExists('harga_default_maklon', 'tb_maklon')) {
            $this->db->query("ALTER TABLE `tb_maklon` DROP COLUMN `harga_default_maklon`");
        }

        if ($this->db->fieldExists('harga_default_reseller', 'tb_reseller')) {
            $this->db->query("ALTER TABLE `tb_reseller` DROP COLUMN `harga_default_reseller`");
        }
    }

    public function down(): void
    {
        $this->db->query("
            ALTER TABLE `tb_maklon`
            ADD COLUMN `harga_default_maklon` DECIMAL(15,2) NULL DEFAULT '0.00'
            AFTER `alamat_maklon`
        ");

        $this->db->query("
            ALTER TABLE `tb_reseller`
            ADD COLUMN `harga_default_reseller` DECIMAL(15,2) NULL DEFAULT '0.00'
            AFTER `alamat_reseller`
        ");
    }
}