<?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('pay_details', function (Blueprint $table) {

            // =====================================================
            // ADD CV_Id COLUMN
            // =====================================================
            $table->unsignedBigInteger('CV_Id')
                ->nullable()
                ->after('PV_Id');

            // =====================================================
            // FOREIGN KEY
            // =====================================================
            $table->foreign('CV_Id')
                ->references('CV_Id')
                ->on('chl_voucher')
                ->onDelete('cascade')
                ->onUpdate('cascade');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('pay_details', function (Blueprint $table) {

            $table->dropForeign(['CV_Id']);

            $table->dropColumn('CV_Id');
        });
    }
};
