<?php

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

/**
 * 兼容已执行过 2026_08_04_120000 但尚未含 login_account 的环境
 */
return new class extends Migration {
    public function up()
    {
        if (!Schema::hasTable('user_login') || Schema::hasColumn('user_login', 'login_account')) {
            return;
        }

        Schema::table('user_login', function (Blueprint $table) {
            $table->string('login_account', 64)->default('')->comment('尝试登录的账号')->after('user_id');
        });
    }

    public function down()
    {
        if (!Schema::hasTable('user_login') || !Schema::hasColumn('user_login', 'login_account')) {
            return;
        }

        Schema::table('user_login', function (Blueprint $table) {
            $table->dropColumn('login_account');
        });
    }
};
