修复:新增独立迁移将 reserved_until 改为 nullable

上次 add_type_reason 迁移已在生产跑过(无 change),
导致 permanent 类型插入 NULL 时报 1048 错误。
新建专用迁移用 DB::statement ALTER TABLE 直接生效,
绕过 doctrine/dbal ->change() 的潜在兼容问题。
This commit is contained in:
2026-03-01 14:07:42 +08:00
parent 211075b77c
commit f114c6b168

View File

@@ -0,0 +1,36 @@
<?php
/**
* 文件功能:将 username_blacklist.reserved_until 修改为可空列
*
* permanent 类型的永久禁用词无到期时间reserved_until 必须支持 NULL
* 同时用 DB::statement 直接 ALTER确保在所有 MySQL 模式下都能生效。
*/
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
/**
* 执行迁移:将 reserved_until 列修改为 NULL 允许。
*/
public function up(): void
{
DB::statement(
"ALTER TABLE `username_blacklist`
MODIFY `reserved_until` TIMESTAMP NULL DEFAULT NULL
COMMENT '保留截止时间temp 类型有效permanent 类型为 NULL'"
);
}
/**
* 回滚:恢复为 NOT NULL(会导致现有 NULL 行出错,生产慎用)。
*/
public function down(): void
{
// 先把现有 NULL 行补一个兜底值,再改回 NOT NULL
DB::statement("UPDATE `username_blacklist` SET `reserved_until` = NOW() + INTERVAL 365 DAY WHERE `reserved_until` IS NULL");
DB::statement("ALTER TABLE `username_blacklist` MODIFY `reserved_until` TIMESTAMP NOT NULL");
}
};