<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddQuestionCountToCompetitionClassWinners extends Migration
{
    public function up()
    {
        $db = \Config\Database::connect();
        if (!$db->tableExists('competition_class_winners')) {
            return;
        }
        if ($db->fieldExists('question_count', 'competition_class_winners')) {
            return;
        }

        $this->forge->addColumn('competition_class_winners', [
            'question_count' => ['type' => 'INT', 'constraint' => 11, 'null' => true],
        ]);
    }

    public function down()
    {
        $db = \Config\Database::connect();
        if (!$db->tableExists('competition_class_winners')) {
            return;
        }
        if (!$db->fieldExists('question_count', 'competition_class_winners')) {
            return;
        }

        $this->forge->dropColumn('competition_class_winners', 'question_count');
    }
}
