<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddMerchantReferenceIdToPayagents extends Migration
{
    public function up()
    {
        if (! $this->db->tableExists('payagents')) {
            return;
        }

        if ($this->db->fieldExists('merchant_reference_id', 'payagents')) {
            return;
        }

        $this->forge->addColumn('payagents', [
            'merchant_reference_id' => [
                'type'       => 'VARCHAR',
                'constraint' => 191,
                'null'       => true,
                'after'      => 'transaction_id',
            ],
        ]);
    }

    public function down()
    {
        if ($this->db->tableExists('payagents') && $this->db->fieldExists('merchant_reference_id', 'payagents')) {
            $this->forge->dropColumn('payagents', 'merchant_reference_id');
        }
    }
}
