<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

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

        $fields = $this->db->getFieldNames('member_kin');
        if (in_array('is_beneficiary', $fields, true)) {
            $this->forge->dropColumn('member_kin', 'is_beneficiary');
        }
    }

    public function down()
    {
        if (!$this->db->tableExists('member_kin')) {
            return;
        }

        $fields = $this->db->getFieldNames('member_kin');
        if (!in_array('is_beneficiary', $fields, true)) {
            $this->forge->addColumn('member_kin', [
                'is_beneficiary' => [
                    'type' => 'TINYINT',
                    'constraint' => 1,
                    'default' => 0,
                    'after' => 'benefits',
                ],
            ]);
        }
    }
}
