<?php

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

return new class extends Migration
{
    public function up(): void
    {
        $driver = DB::getDriverName();

        if ($driver === 'mysql') {
            DB::statement(
                "UPDATE members SET qr_code = CONCAT('MC-', YEAR(CURDATE()), '-', id) WHERE qr_code IS NULL OR TRIM(qr_code) = ''"
            );
        } elseif ($driver === 'sqlite') {
            DB::statement(
                "UPDATE members SET qr_code = 'MC-' || strftime('%Y', 'now') || '-' || id WHERE qr_code IS NULL OR trim(qr_code) = ''"
            );
        }
    }

    public function down(): void
    {
        //
    }
};
