<?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('customer_payment_collections', function (Blueprint $table) {
            $table->unsignedBigInteger('advance_payment_master_id')->nullable()->after('invoice_id');
            $table->foreign('advance_payment_master_id', 'cap_payment_master_id_fk')->references('id')->on('customer_advance_payment_masters')->onDelete('cascade');
        });
    }

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