<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddEventTypeToCalendarEvents extends Migration
{
    public function up()
    {
        $db = \Config\Database::connect();

        if (!$db->fieldExists('event_type', 'calendar_events')) {
            $this->forge->addColumn('calendar_events', [
                'event_type' => [
                    'type'       => 'VARCHAR',
                    'constraint' => 120,
                    'null'       => true,
                    'default'    => null,
                    'after'      => 'description',
                ],
            ]);
        }
    }

    public function down()
    {
        $db = \Config\Database::connect();
        if ($db->fieldExists('event_type', 'calendar_events')) {
            $this->forge->dropColumn('calendar_events', 'event_type');
        }
    }
}
