<?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('photos', function (Blueprint $table) {
            if (! Schema::hasColumn('photos', 'ingest_source')) {
                $table->string('ingest_source', 32)
                    ->default('guest_pwa')
                    ->after('guest_name');
                $table->index('ingest_source');
            }
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('photos', function (Blueprint $table) {
            if (Schema::hasColumn('photos', 'ingest_source')) {
                $table->dropIndex('photos_ingest_source_index');
                $table->dropColumn('ingest_source');
            }
        });
    }
};
