<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    /**
     * 5130 output.num → SAM orders.id 매핑 테이블
     * 마이그레이션 추적 및 롤백을 위해 사용
     */
    public function up(): void
    {
        Schema::create('order_id_mappings', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('source_num')->unsigned()->comment('5130 output.num');
            $table->bigInteger('order_id')->unsigned()->comment('SAM orders.id');
            $table->timestamps();

            $table->unique('source_num');
            $table->index('order_id');

            $table->foreign('order_id')->references('id')->on('orders')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('order_id_mappings');
    }
};
