<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddPayGrpOnEmployee extends Migration
{
    public function up()
    {
        $fields = [
            'pay_group_id' => [
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
                'null' => false,
                'default' => 0, // Remove this if you want to recreate Employee migration
                'after' => 'emp_status_id',
            ],
        ];

        $this->forge->addColumn('employee', $fields);

        $this->forge->addForeignKey('pay_group_id', 'pay_group', 'pay_group_id', 'CASCADE', 'RESTRICT');
        $this->forge->processIndexes('employee');
    }

    public function down()
    {
        $this->forge->dropForeignKey('employee', 'employee_pay_group_id_foreign');
        $this->forge->processIndexes('employee');
        $this->forge->dropColumn('employee', 'pay_group_id');
    }
}
