<?php

namespace App\Database\Migrations\Panel;

use CodeIgniter\Database\Migration;

class BeritaAcara extends Migration
{
    public function up()
    {
        $fields = [
            'id' => ['type' => 'int', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
            'jadwal_id' => ['type' => 'int', 'constraint' => 11, 'unsigned' => true],
            'nomor_induk_proktor' => ['type' => 'char', 'constraint' => 32],
            'nama_proktor' => ['type' => 'varchar', 'constraint' => 255],
            'catatan' => ['type' => 'text', 'null' => true],
            'created_at' => ['type' => 'int', 'constraint' => 11, 'unsigned' => true],
            'updated_at' => ['type' => 'int', 'constraint' => 11, 'unsigned' => true],
        ];

        $this->forge->addField($fields);
        $this->forge->addKey('id', true);
        $this->forge->addForeignKey('jadwal_id', 'jadwal_ujian', 'id', false, 'CASCADE');
        $this->forge->createTable('berita_acara', true);
    }

    public function down()
    {
        // drop constraints first to prevent errors
        if ($this->db->DBDriver != 'SQLite3') {
            $this->forge->dropForeignKey('berita_acara', 'berita_acara_jadwal_id_foreign');
        }
        $this->forge->dropTable('berita_acara', true);
    }
}
