<?php

namespace App\Database\Migrations\Panel;

use CodeIgniter\Database\Migration;

class DraftSoal extends Migration
{
    public function up()
    {
        $fields = [
            'draft_id' => ['type' => 'int', 'constraint' => 11, 'unsigned' => true],
            'soal_id' => ['type' => 'int', 'constraint' => 11, 'unsigned' => true],
        ];
        $this->forge->addField($fields);
        $this->forge->addKey('id', true);
        $this->forge->addForeignKey('soal_id', 'soal_data', 'id', false, 'CASCADE');
        $this->forge->addForeignKey('draft_id', 'draft_ujian', 'id', false, 'CASCADE');
        $this->forge->createTable('draft_soal', true);
    }

    public function down()
    {

        // drop constraints first to prevent errors
        if ($this->db->DBDriver != 'SQLite3') {
            $this->forge->dropForeignKey('draft_soal', 'draft_soal_soal_id_foreign');
            $this->forge->dropForeignKey('draft_soal', 'draft_soal_draft_id_foreign');
        }
        $this->forge->dropTable('draft_soal', true);
    }
}
