<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateLearningDeviceRpeAndPekanEfektifTables extends Migration
{
    public function up()
    {
        // 1. learning_device_rpe (Perencanaan Penilaian)
        $this->forge->addField([
            'id' => [
                'type'           => 'BIGINT',
                'unsigned'       => true,
                'auto_increment' => true,
            ],
            'learning_device_id' => [
                'type'       => 'BIGINT',
                'unsigned'   => true,
            ],
            'content_json' => [
                'type' => 'LONGTEXT',
            ],
            'created_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
            'updated_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
        ]);
        $this->forge->addKey('id', true);
        $this->forge->addForeignKey('learning_device_id', 'learning_devices', 'id', 'CASCADE', 'CASCADE');
        $this->forge->createTable('learning_device_rpe', true); // true = IF NOT EXISTS

        // 2. learning_device_pekan_efektif (Rincian Pekan Efektif)
        $this->forge->addField([
            'id' => [
                'type'           => 'BIGINT',
                'unsigned'       => true,
                'auto_increment' => true,
            ],
            'learning_device_id' => [
                'type'       => 'BIGINT',
                'unsigned'   => true,
            ],
            'content_json' => [
                'type' => 'LONGTEXT',
            ],
            'created_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
            'updated_at' => [
                'type' => 'DATETIME',
                'null' => true,
            ],
        ]);
        $this->forge->addKey('id', true);
        $this->forge->addForeignKey('learning_device_id', 'learning_devices', 'id', 'CASCADE', 'CASCADE');
        $this->forge->createTable('learning_device_pekan_efektif', true); // true = IF NOT EXISTS
    }

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