修复:迁移增加 sign 列(生产库缺失)

This commit is contained in:
2026-02-26 22:54:38 +08:00
parent 7126d844dc
commit 6a596a13aa

View File

@@ -1,9 +1,9 @@
<?php <?php
/** /**
* 文件功能:为用户表添加密码保护问题和答案字段 * 文件功能:为用户表添加缺失的字段sign、question、answer
* *
* 用于用户找回密码的密保问题功能。 * 用于个性签名和密码保护问题功能。
* 使用 hasColumn 检查避免重复添加。 * 使用 hasColumn 检查避免重复添加。
*/ */
@@ -14,11 +14,14 @@ use Illuminate\Support\Facades\Schema;
return new class extends Migration return new class extends Migration
{ {
/** /**
* 添加密保问题和答案字段(已存在则跳过) * 添加 sign、question、answer 字段(已存在则跳过)
*/ */
public function up(): void public function up(): void
{ {
Schema::table('users', function (Blueprint $table) { Schema::table('users', function (Blueprint $table) {
if (! Schema::hasColumn('users', 'sign')) {
$table->string('sign', 255)->nullable()->after('sex')->comment('个性签名');
}
if (! Schema::hasColumn('users', 'question')) { if (! Schema::hasColumn('users', 'question')) {
$table->string('question', 100)->nullable()->after('email')->comment('密保问题'); $table->string('question', 100)->nullable()->after('email')->comment('密保问题');
} }
@@ -29,17 +32,16 @@ return new class extends Migration
} }
/** /**
* 回滚:删除密保字段 * 回滚:删除字段
*/ */
public function down(): void public function down(): void
{ {
Schema::table('users', function (Blueprint $table) { Schema::table('users', function (Blueprint $table) {
$columns = []; $columns = [];
if (Schema::hasColumn('users', 'question')) { foreach (['sign', 'question', 'answer'] as $col) {
$columns[] = 'question'; if (Schema::hasColumn('users', $col)) {
} $columns[] = $col;
if (Schema::hasColumn('users', 'answer')) { }
$columns[] = 'answer';
} }
if ($columns) { if ($columns) {
$table->dropColumn($columns); $table->dropColumn($columns);