<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

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

        $fields = $this->db->getFieldNames('student_class');
        if (in_array('is_event_only', $fields, true)) {
            return;
        }

        $this->forge->addColumn('student_class', [
            'is_event_only' => ['type' => 'TINYINT', 'constraint' => 1, 'unsigned' => true, 'default' => 0],
        ]);
    }

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

        $fields = $this->db->getFieldNames('student_class');
        if (!in_array('is_event_only', $fields, true)) {
            return;
        }

        $this->forge->dropColumn('student_class', 'is_event_only');
    }
}
