<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddTabunganOfficerToSchoolSettings extends Migration
{
    public function up()
    {
        $this->forge->addColumn('school_settings', [
            'tabungan_officer_teacher_id' => [
                'type'       => 'BIGINT',
                'constraint' => 20,
                'unsigned'   => true,
                'null'       => true,
                'after'      => 'principal_nip',
            ],
        ]);

        $this->db->query('ALTER TABLE school_settings ADD CONSTRAINT school_settings_tabungan_officer_teacher_fk FOREIGN KEY (tabungan_officer_teacher_id) REFERENCES teachers(id) ON DELETE SET NULL ON UPDATE CASCADE');
    }

    public function down()
    {
        $this->db->query('ALTER TABLE school_settings DROP FOREIGN KEY school_settings_tabungan_officer_teacher_fk');
        $this->forge->dropColumn('school_settings', 'tabungan_officer_teacher_id');
    }
}
