<?php

namespace App\Database\Migrations\Master;

use CodeIgniter\Database\Migration;

class BankSoal extends Migration
{
    public function up()
    {
        $fields = [
            'id'   => ['type' => 'int', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
            'user_id' => ['type' => 'int', 'constraint' => 11, 'unsigned' => true],
            'kode' => ['type' => 'char', 'constraint' => 128],
            'deskripsi' => ['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->addUniqueKey('kode');
        $this->forge->addForeignKey('user_id', 'users', 'id', false, 'CASCADE');
        $this->forge->createTable('m_banksoal', true);
    }

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