<?php

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

return new class extends Migration
{
    /**
     * Existing accounts were all created through the magic-link registration
     * flow (or by admins), so grandfather them in as verified now that the
     * `verified` middleware is enforced.
     */
    public function up(): void
    {
        DB::table('users')
            ->whereNull('email_verified_at')
            ->update(['email_verified_at' => DB::raw('created_at')]);
    }

    public function down(): void
    {
        // Irreversible: we can't distinguish backfilled rows afterwards.
    }
};
