fix(db): 把校正标题/活跃时间修补搬成迁移

BUG-699 / BUG-704 的数据修补原先只存在于
frontend/scripts/repair-rectification-session-titles.mjs,需要
SCHEMA_DATABASE_URL 才能跑,产品负责人没有任何按钮能执行它,所以那批
错日期的会话标题一直没修。

脚本里本来就是纯 SQL,搬进一次性迁移即可复用现成的
`Migrate Staging Database` 按钮:

- 新增 20260916020000_rectification_session_title_repair.sql,两段 update
  逐字取自脚本(合同测试比对,改了哪边都会红);权限守卫沿用
  20260915010000 的 schema_owner 写法。
- 幂等:改完之后两段 where 都不再匹配同一行,重复应用影响 0 行。
- 各自 get diagnostics + raise notice 打出行数;db-migrate.mjs 加 notice
  转发,否则 node-postgres 会把 NOTICE 丢掉,迁移日志里一个数字都看不到。
- 脚本降级为只读核对工具:--apply 改为报错并指向迁移;导入不再连库。

生产停在 7b620c7a(没有 use-rectification-surface.ts,标题固定且不写库),
两段 where 自然匹配 0 行,是预期内的 no-op。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JUei7K13cYxLHE3Axe4A45
This commit is contained in:
Jesse_Chen
2026-09-16 01:35:01 +00:00
co-authored by Claude Opus 5
parent 37e6c519f7
commit d6c359b205
4 changed files with 210 additions and 21 deletions
+7
View File
@@ -139,6 +139,13 @@ export async function runMigrations({
}) {
const files = await loadMigrationFiles(migrationsDirectories ?? migrationsDirectory);
const client = new Client({ connectionString });
// Data-repair migrations report how many rows they touched with RAISE NOTICE.
// node-postgres drops notices when nothing listens, which would leave the
// staging migration log with no row counts at all (BUG-699 / BUG-704 repair).
client.on("notice", (notice) => {
const message = typeof notice?.message === "string" ? notice.message.trim() : "";
if (message) logger.log(`notice ${message}`);
});
let locked = false;
try {