<?php

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

return new class extends Migration
{
    public function up(): void
    {
        if (! Schema::hasTable('push_subscriptions')) {
            return;
        }

        $driver = Schema::getConnection()->getDriverName();

        if ($driver === 'mysql') {
            DB::statement('ALTER TABLE push_subscriptions MODIFY endpoint TEXT NOT NULL');
        } elseif ($driver === 'pgsql') {
            DB::statement('ALTER TABLE push_subscriptions ALTER COLUMN endpoint TYPE TEXT');
        }
    }

    public function down(): void
    {
        if (! Schema::hasTable('push_subscriptions')) {
            return;
        }

        $driver = Schema::getConnection()->getDriverName();

        if ($driver === 'mysql') {
            DB::statement('ALTER TABLE push_subscriptions MODIFY endpoint VARCHAR(1024) NOT NULL');
        } elseif ($driver === 'pgsql') {
            DB::statement('ALTER TABLE push_subscriptions ALTER COLUMN endpoint TYPE VARCHAR(1024)');
        }
    }
};
