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

            $table->unsignedBigInteger('tech_stack')->change();
            $table->dropUnique('kaalii_package_versions_version_unique');

            $table->string('version', 50)->change();

            // Add foreign key safely
            $table->foreign('tech_stack', 'kpv_tech_stack_fk')
                  ->references('id')
                  ->on('programming_languages')
                  ->onDelete('cascade');
        });
    }

    public function down(): void
    {
        Schema::table('kaalii_package_versions', function (Blueprint $table) {

            $table->dropForeign('kpv_tech_stack_fk');

            $table->string('tech_stack')->change();
            $table->string('version', 50)->unique()->change();
        });
    }
};
