<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateAscSubjects extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => [
                'type'           => 'INT',
                'constraint'     => 11,
                'unsigned'       => true,
                'auto_increment' => true,
            ],
            'import_id' => [
                'type'       => 'INT',
                'constraint' => 11,
                'unsigned'   => true,
            ],
            'asc_id' => [
                'type'       => 'VARCHAR',
                'constraint' => 50,
                'comment'    => 'ID asli dari XML aSc',
            ],
            'name' => [
                'type'       => 'VARCHAR',
                'constraint' => 150,
            ],
            'short_code' => [
                'type'       => 'VARCHAR',
                'constraint' => 20,
                'comment'    => 'Kode singkat, misal: MAT, BIG, IPA',
            ],
            // Untuk mapping ke data asli aplikasi (nanti)
            'school_subject_id' => [
                'type'       => 'INT',
                'constraint' => 11,
                'unsigned'   => true,
                'null'       => true,
                'default'    => null,
                'comment'    => 'FK ke school_subjects (nanti)',
            ],
            'created_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
            'updated_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
        ]);

        $this->forge->addKey('id', true);
        $this->forge->addKey('import_id');
        $this->forge->addKey('asc_id');
        $this->forge->createTable('asc_subjects');
    }

    public function down()
    {
        $this->forge->dropTable('asc_subjects');
    }
}