<?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('user_flights', function (Blueprint $table) {
            $table->timestamp('arrival_processed_at')->nullable()->after('departure_processed_at');
        });

        DB::table('user_flights')
            ->where('arrival_date', '<=', now()->utc())
            ->whereNull('arrival_processed_at')
            ->update(['arrival_processed_at' => now()->utc()]);
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
    }
};
