<?php

namespace App\Database\Migrations\Elearning;

use CodeIgniter\Database\Migration;

class KompetensiDasar extends Migration
{
    public function up()
    {
        $fields = [
            'id' => ['type' => 'int', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true],
            'nomor' => ['type' => 'integer', 'constraint' => 11, 'unsigned' => true],
            'nama' => ['type' => 'varchar', 'constraint' => 255,],
            'kode' => ['type' => 'enum', 'constraint' => "'KP','KK'"],
            'mapel_id' => ['type' => 'int', 'constraint' => 11, 'unsigned' => true],
            'tingkat_id' => ['type' => 'int', 'constraint' => 11, 'unsigned' => true],
            'user_id' => ['type' => 'int', 'constraint' => 11, 'unsigned' => true],
            'created_at datetime default current_timestamp',
            'updated_at datetime default current_timestamp',
        ];
        $this->forge->addField($fields);
        $this->forge->addKey('id', true);
        $this->forge->addForeignKey('mapel_id', 'm_mapel', 'id', false, 'CASCADE');
        $this->forge->addForeignKey('tingkat_id', 'm_tingkat', 'id', false, 'CASCADE');
        $this->forge->addForeignKey('user_id', 'users', 'id', false, 'CASCADE');
        $this->forge->createTable('kompetensi_dasar', true);
    }

    public function down()
    {
        $this->forge->dropTable('kompetensi_dasar', true);
    }
}
