<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class FixTabunganRecordedBy extends Migration
{
    public function up()
    {
        $this->db->query('ALTER TABLE tabungan_transactions DROP FOREIGN KEY tabungan_transactions_recorded_by_foreign');
        $this->db->query('ALTER TABLE tabungan_transactions MODIFY recorded_by BIGINT(20) UNSIGNED NULL');
        $this->db->query('ALTER TABLE tabungan_transactions ADD CONSTRAINT tabungan_transactions_recorded_by_foreign FOREIGN KEY (recorded_by) REFERENCES users(id) ON DELETE SET NULL ON UPDATE CASCADE');
    }

    public function down()
    {
        $this->db->query('ALTER TABLE tabungan_transactions DROP FOREIGN KEY tabungan_transactions_recorded_by_foreign');
        $this->db->query('ALTER TABLE tabungan_transactions MODIFY recorded_by BIGINT(20) UNSIGNED NOT NULL');
        $this->db->query('ALTER TABLE tabungan_transactions ADD CONSTRAINT tabungan_transactions_recorded_by_foreign FOREIGN KEY (recorded_by) REFERENCES users(id) ON DELETE RESTRICT ON UPDATE CASCADE');
    }
}