<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateMissingScoreOverrides extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => [
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
                'auto_increment' => true,
            ],
            'student_id' => [
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
            ],
            'class_section_id' => [
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
            ],
            'semester' => [
                'type' => 'VARCHAR',
                'constraint' => 20,
            ],
            'school_year' => [
                'type' => 'VARCHAR',
                'constraint' => 20,
            ],
            'item_type' => [
                'type' => 'VARCHAR',
                'constraint' => 30,
            ],
            'item_index' => [
                'type' => 'INT',
                'constraint' => 11,
                'null' => true,
            ],
            'is_allowed' => [
                'type' => 'TINYINT',
                'constraint' => 1,
                'default' => 0,
            ],
            'updated_by' => [
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
                'null' => true,
            ],
            'created_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
            'updated_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
        ]);

        $this->forge->addKey('id', true);
        $this->forge->addKey(['class_section_id', 'semester', 'school_year', 'item_type'], false, 'missing_score_overrides_scope');
        $this->forge->addUniqueKey(
            ['student_id', 'class_section_id', 'semester', 'school_year', 'item_type', 'item_index'],
            'missing_score_overrides_unique'
        );
        $this->forge->createTable('missing_score_overrides', true);
    }

    public function down()
    {
        $this->forge->dropTable('missing_score_overrides', true);
    }
}
