<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

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

        $this->forge->addField([
            'id' => [
                'type'           => 'INT',
                'constraint'     => 11,
                'unsigned'       => true,
                'auto_increment' => true,
            ],
            'student_id' => [
                'type'       => 'INT',
                'constraint' => 11,
                'unsigned'   => true,
            ],
            'semester' => [
                'type'       => 'VARCHAR',
                'constraint' => 20,
            ],
            'school_year' => [
                'type'       => 'VARCHAR',
                'constraint' => 20,
            ],
            'decision' => [
                'type'       => 'VARCHAR',
                'constraint' => 100,
                'null'       => true,
            ],
            'notes' => [
                'type' => 'TEXT',
                'null' => true,
            ],
            'decided_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->addUniqueKey(['student_id', 'semester', 'school_year']);
        $this->forge->addKey(['school_year', 'semester']);
        $this->forge->createTable('below_sixty_decisions');
    }

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