<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('product_variant_components', function (Blueprint $table) {
            $table->unsignedBigInteger('parent_variant_id');
            $table->unsignedBigInteger('component_variant_id');

            $table->foreign('parent_variant_id')
                ->references('id')->on('variants')
                ->onDelete('CASCADE')->onUpdate('CASCADE');
            $table->foreign('component_variant_id')
                ->references('id')->on('variants')
                ->onDelete('CASCADE')->onUpdate('CASCADE');
        });
    }

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