<?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
    {
        if (Schema::hasTable('req_logs')) {
            Schema::table('req_logs', function (Blueprint $table) {
                if (!Schema::hasColumn('req_logs', 'url')) {
                    $table->longText('url')->nullable()->after('req_date');
                }
                if (!Schema::hasColumn('req_logs', 'response')) {
                    $table->longText('response')->nullable()->after('url');
                }
            });
        }
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        if (Schema::hasTable('req_logs')) {
            Schema::table('req_logs', function (Blueprint $table) {
                if (Schema::hasColumn('req_logs', 'response')) {
                    $table->dropColumn('response');
                }
                if (Schema::hasColumn('req_logs', 'url')) {
                    $table->dropColumn('url');
                }
            });
        }
    }
};
