<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateStudentAcademicHistoriesTable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id'                 => ['type' => 'BIGINT', 'unsigned' => true, 'auto_increment' => true],
            'student_id'         => ['type' => 'BIGINT', 'unsigned' => true],
            'academic_period_id' => ['type' => 'BIGINT', 'unsigned' => true],
            'classroom_id'       => ['type' => 'BIGINT', 'unsigned' => true],
            'status'             => [
                'type'       => 'ENUM',
                'constraint' => ['Aktif', 'Naik Kelas', 'Tinggal Kelas', 'Lulus', 'Mutasi', 'Drop Out'],
                'default'    => 'Aktif'
            ],
            'notes'              => ['type' => 'TEXT', 'null' => true],
            'created_at'         => ['type' => 'DATETIME', 'null' => true],
            'updated_at'         => ['type' => 'DATETIME', 'null' => true],
        ]);
        $this->forge->addPrimaryKey('id');
        $this->forge->addForeignKey('student_id', 'students', 'id', 'CASCADE', 'CASCADE');
        $this->forge->addForeignKey('academic_period_id', 'academic_periods', 'id', 'CASCADE', 'CASCADE');
        $this->forge->addForeignKey('classroom_id', 'classrooms', 'id', 'CASCADE', 'CASCADE');
        $this->forge->createTable('student_academic_histories');
    }

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