<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreatePenugasanDosenTable extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => [
                'type'           => 'INT',
                'constraint'     => 11,
                'unsigned'       => true,
                'auto_increment' => true,
            ],
            'id_registrasi_dosen' => [
                'type'       => 'VARCHAR',
                'constraint' => '36',
                'null'       => true, // From PDDIKTI
            ],
            'id_dosen' => [
                'type'       => 'INT',
                'constraint' => 11,
                'unsigned'   => true,
            ],
            'id_prodi' => [
                'type'       => 'INT',
                'constraint' => 11,
                'unsigned'   => true,
                'null'       => true,
            ],
            'id_tahun_ajaran' => [
                'type'       => 'VARCHAR',
                'constraint' => '10',
                'null'       => true,
            ],
            'nama_tahun_ajaran' => [
                'type'       => 'VARCHAR',
                'constraint' => '50',
                'null'       => true,
            ],
            'nama_program_studi' => [
                'type'       => 'VARCHAR',
                'constraint' => '100',
                'null'       => true,
            ],
            'no_surat_tugas' => [
                'type'       => 'VARCHAR',
                'constraint' => '100',
                'null'       => true,
            ],
            'tanggal_surat_tugas' => [
                'type'       => 'DATE',
                'null'       => true,
            ],
            'is_homebase' => [
                'type'       => 'ENUM',
                'constraint' => ['Ya', 'Tidak'],
                'default'    => 'Tidak',
            ],
            'created_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
            'updated_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
        ]);

        $this->forge->addKey('id', true);
        $this->forge->addForeignKey('id_dosen', 'dosen', 'id', 'CASCADE', 'CASCADE');
        $this->forge->addForeignKey('id_prodi', 'program_studi', 'id', 'SET NULL', 'CASCADE');
        $this->forge->createTable('penugasan_dosen');
    }

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