<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

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

        $this->forge->addField([
            'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
            'batch_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true],
            'student_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true],
            'score' => ['type' => 'SMALLINT', 'constraint' => 3, 'unsigned' => true],
            'created_by' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'null' => true],
            '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->addUniqueKey(['batch_id', 'student_id'], 'unique_batch_student');
        $this->forge->addKey('batch_id');
        $this->forge->createTable('placement_scores');
    }

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