<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

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

        $fields = $this->db->getFieldNames('member');
        if (!in_array('date_of_death', $fields, true)) {
            $this->forge->addColumn('member', [
                'date_of_death' => [
                    'type' => 'DATE',
                    'null' => true,
                    'after' => 'date_of_birth',
                ],
            ]);
        }
    }

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

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