<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class RenameMasterColumns extends Migration
{
    public function up()
    {
        // master_depts: name -> dept_name
        $this->db->query("ALTER TABLE master_depts CHANGE COLUMN name dept_name VARCHAR(255) NOT NULL");

        // master_controls: name -> control_name
        $this->db->query("ALTER TABLE master_controls CHANGE COLUMN name control_name VARCHAR(255) NOT NULL");

        // master_tests: name -> test_name, unit -> test_unit, method -> test_method
        $this->db->query("ALTER TABLE master_tests CHANGE COLUMN name test_name VARCHAR(255) NOT NULL");
        $this->db->query("ALTER TABLE master_tests CHANGE COLUMN unit test_unit VARCHAR(100) NULL");
        $this->db->query("ALTER TABLE master_tests CHANGE COLUMN method test_method VARCHAR(255) NULL");
    }

    public function down()
    {
        // master_tests: revert
        $this->db->query("ALTER TABLE master_tests CHANGE COLUMN test_method method VARCHAR(255) NULL");
        $this->db->query("ALTER TABLE master_tests CHANGE COLUMN test_unit unit VARCHAR(100) NULL");
        $this->db->query("ALTER TABLE master_tests CHANGE COLUMN test_name name VARCHAR(255) NOT NULL");

        // master_controls: revert
        $this->db->query("ALTER TABLE master_controls CHANGE COLUMN control_name name VARCHAR(255) NOT NULL");

        // master_depts: revert
        $this->db->query("ALTER TABLE master_depts CHANGE COLUMN dept_name name VARCHAR(255) NOT NULL");
    }
}
