Skip to content

修复存量 PG 库缺 agenda_token_ledger 表(/api/token_usage 500)#43

Merged
Protocol-zero-0 merged 1 commit into
masterfrom
fix/agenda-ledger-pg-migration
Jun 11, 2026
Merged

修复存量 PG 库缺 agenda_token_ledger 表(/api/token_usage 500)#43
Protocol-zero-0 merged 1 commit into
masterfrom
fix/agenda-ledger-pg-migration

Conversation

@Protocol-zero-0

Copy link
Copy Markdown
Contributor

问题

生产(Postgres,存量库)部署 #41 后 /api/token_usage 返回 500:relation "agenda_token_ledger" does not exist。

根因

  • 增量迁移 _ensure_agenda_isolation_schema 只补列、不建 ledger 表(新表只存在于 schema_agenda*.sql,供全新库使用);
  • PG 初始化路径对 schema 文件的 best-effort 逐语句重放,在某条语句失败后事务进入 aborted 状态,后续语句(含建表)被 except-pass 静默吞掉——SQLite 无此事务语义,因此测试未暴露。

修复

  1. 迁移函数显式 CREATE TABLE IF NOT EXISTS agenda_token_ledger + 索引(PG/SQLite 双 DDL);
  2. 四处 schema 重放循环里,语句失败后 rollback 再继续,消除整类静默跳过。

验证

  • 新回归测试:删表后跑迁移→表重建→record_usage 正常记账;
  • 全套 pytest:15 failed / 505 passed,失败清单与 master 既有 15 条一致,无新增。

增量迁移 _ensure_agenda_isolation_schema 此前只补列不建表,而 PG 路径的
schema 文件 best-effort 重放在前序语句失败后整个事务 aborted,后续
CREATE TABLE 被静默跳过。两处修复:迁移函数显式建 ledger 表+索引
(双后端 DDL);schema 重放循环逐语句失败后 rollback,让剩余语句继续。
@Protocol-zero-0 Protocol-zero-0 merged commit b023ce5 into master Jun 11, 2026
2 checks passed
@Protocol-zero-0 Protocol-zero-0 mentioned this pull request Jun 11, 2026
@Protocol-zero-0 Protocol-zero-0 deleted the fix/agenda-ledger-pg-migration branch June 11, 2026 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant