<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('user_subscriptions', function (Blueprint $table) {
            $table->foreignId('source_video_id')->nullable()->after('channel_id')
                ->constrained('videos')->nullOnDelete();
            $table->index('source_video_id');
        });
    }

    public function down(): void
    {
        Schema::table('user_subscriptions', function (Blueprint $table) {
            $table->dropForeign(['source_video_id']);
            $table->dropIndex(['source_video_id']);
            $table->dropColumn('source_video_id');
        });
    }
};
