<?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('events', function (Blueprint $table) {
            // Foreign Key zu locations-Tabelle hinzufügen
            $table->unsignedBigInteger('location_id')->nullable()->after('category');
            $table->foreign('location_id')->references('id')->on('locations')->onDelete('set null');
            
            // Alte location-Spalte droppen
            $table->dropColumn('location');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('events', function (Blueprint $table) {
            // location-Spalte wiederherstellen
            $table->string('location')->nullable();
            
            // Foreign Key entfernen
            $table->dropForeign(['location_id']);
            $table->dropColumn('location_id');
        });
    }
};
