<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class ChapterFieldForTpAndModul extends Migration
{
    public function up()
    {
        if ($this->db->fieldExists('chapter', 'learning_device_tps')) return;
        // Tambah kolom chapter di learning_device_tps
        $this->forge->addColumn('learning_device_tps', [
            'chapter' => [
                'type'       => 'VARCHAR',
                'constraint' => 255,
                'null'       => true,
                'after'      => 'sort_order',
            ],
        ]);

        // Tambah kolom chapter_index di learning_device_moduls
        $this->forge->addColumn('learning_device_moduls', [
            'chapter_index' => [
                'type'       => 'INT',
                'constraint' => 11,
                'unsigned'   => true,
                'default'    => 0,
                'after'      => 'tp_id',
            ],
        ]);
    }

    public function down()
    {
        $this->forge->dropColumn('learning_device_tps', 'chapter');
        $this->forge->dropColumn('learning_device_moduls', 'chapter_index');
    }
}
