<?php

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

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

        Schema::table('form_data', function (Blueprint $table) {
            if (!Schema::hasColumn('form_data', 'ip_provider')) {
                $table->string('ip_provider')->nullable()->after('ip');
            }
        });
    }

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

        Schema::table('form_data', function (Blueprint $table) {
            if (Schema::hasColumn('form_data', 'ip_provider')) {
                $table->dropColumn('ip_provider');
            }
        });
    }
};
