<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('sessions', function (Blueprint $table) {
            $table->string('guard', 50)->default('web')->after('user_id')->index();
        });

        // Update existing sessions to have 'web' as default guard
        DB::statement("UPDATE sessions SET guard = 'web' WHERE guard IS NULL OR guard = ''");
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('sessions', function (Blueprint $table) {
            $table->dropColumn('guard');
        });
    }
};
