Files
Agent-System-Backend/internal/store/migrate_compat.go
T
weichen 6dbe025ec1 Integrate atomic account maintenance with current authentication
Why: Deliver U7 account transactions and audit without losing main auth_version, restricted-session, project or migration behavior.

Evidence: SELF go vet and all Go tests passed; isolated PostgreSQL store tests, 20 repeated two-process admission rounds, and real SIGTERM/SIGKILL persistence passed. Original failures remain in receipts; exact-head CI and independent Review follow.

Impact: Adds schema v31, noncreating account CLI opens, preflight credential output, same-transaction audit, and bootstrap admission guards. No live database touched.

Refs: Backend PR #185; Dev PR #486; original U7 r2 account specification; 2026-10-14 Root takeover
2026-10-14 03:42:03 +00:00

54 lines
1.5 KiB
Go

package store
// migrationBreaksOldReaders 登记每个迁移版本落地后,schema.target 更低的旧制品
// 还能不能读这个库。新增迁移漏登记时 TestMigrationCompatRegistered 失败。
// true 会抬高 SchemaCompatFloor:候选若要把库迁过该版本,而旧制品的 target
// 低于该下限,切换必须在停旧服务前拒绝,除非走已确认的 forward-only 迁移。
var migrationBreaksOldReaders = map[int]bool{
1: false,
2: false,
3: false,
4: false,
5: false,
6: false,
7: false,
8: false,
9: false,
10: false,
11: false,
12: false,
13: false,
14: false,
15: false,
16: false,
17: false,
18: false,
19: false,
20: false,
21: false,
22: false,
23: false,
24: false,
25: false,
26: false,
27: false,
28: false, // auth_version_account_events:仅加列与新表,旧读者不受影响
29: false, // redeem_attempts:新表,旧读者不受影响
30: false, // project_event_publication_proofs:新表,旧读者不受影响
31: false, // account_audit 给 audit_events 增加带默认值的列,旧制品按列名读取
}
// SchemaTarget 是本二进制会迁移到的 schema 版本。
func SchemaTarget() int { return latestMigrationVersion() }
// SchemaCompatFloor 是旧制品仍能读取的最高破坏性版本。0 表示当前全部迁移都不破坏旧读。
func SchemaCompatFloor() int {
floor := 0
for version, breaks := range migrationBreaksOldReaders {
if breaks && version > floor {
floor = version
}
}
return floor
}