<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreatePromotionQueue 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,
                'null'       => false,
            ],
            'from_class_section_id' => [
                'type'       => 'INT',
                'constraint' => 11,
                'unsigned'   => true,
                'null'       => true,
                'default'    => null,
            ],
            'to_class_id' => [
                'type'       => 'INT',
                'constraint' => 11,
                'unsigned'   => true,
                'null'       => false,
            ],
            'to_class_section_id' => [
                'type'       => 'INT',
                'constraint' => 11,
                'unsigned'   => true,
                'null'       => true,
                'default'    => null,
            ],
            'school_year_from' => [
                'type'       => 'VARCHAR',
                'constraint' => 9,
                'null'       => false,
            ],
            'school_year_to' => [
                'type'       => 'VARCHAR',
                'constraint' => 9,
                'null'       => false,
            ],
            'status' => [
                'type'       => 'ENUM',
                'constraint' => ['queued','assigned','applied','cancelled'],
                'default'    => 'queued',
            ],
            'created_at' => [
                'type'    => 'DATETIME',
                'null'    => true,
                'default' => null,
            ],
            'updated_at' => [
                'type'    => 'DATETIME',
                'null'    => true,
                'default' => null,
            ],
            'updated_by' => [
                'type'       => 'INT',
                'constraint' => 11,
                'unsigned'   => true,
                'null'       => true,
                'default'    => null,
            ],
        ]);

        $this->forge->addKey('id', true);
        $this->forge->addKey(['student_id', 'school_year_to'], false, true, 'uq_student_year_to');
        $this->forge->addKey('to_class_id');
        $this->forge->createTable('promotion_queue', true);
    }

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

