<?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('codes')) {
            return;
        }

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

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

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