<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('dsg_pay_map', function (Blueprint $table) {
            $table->unsignedBigInteger('EGM_Id')->nullable()->after('PL_Id');

            // Add foreign key
            $table->foreign('EGM_Id', 'fk_dsg_pay_egm')
                ->references('EGM_Id')
                ->on('emp_grade_master')
                ->cascadeOnUpdate()
                ->restrictOnDelete();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('dsg_pay_map', function (Blueprint $table) {
            $table->dropForeign('fk_dsg_pay_egm');
            $table->dropColumn('EGM_Id');
        });
    }
};
