<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddEventCategoryToEvents extends Migration
{
    public function up()
    {
        $fields = $this->db->getFieldNames('events');

        if (!in_array('event_category', $fields, true)) {
            $this->forge->addColumn('events', [
                'event_category' => [
                    'type'       => 'VARCHAR',
                    'constraint' => 100,
                    'null'       => true,
                    'after'      => 'event_name',
                    'comment'    => 'Admin-only category label',
                ],
            ]);
        }
    }

    public function down()
    {
        $fields = $this->db->getFieldNames('events');

        if (in_array('event_category', $fields, true)) {
            $this->forge->dropColumn('events', 'event_category');
        }
    }
}
