feat(server): 迁移000020 旧码表更名封存 legacy_*(为 codes 库表让位)(#codes-lib)

RENAME codes/code_batches -> legacy_codes/legacy_code_batches(双方言),
为共享库 github.com/wangjia/codes 的同名 codes 表让位。sqlite_migrate_test.go
同步到 version=20 + legacy_* 表清单。

顺带 skip TestSQLite_CodesRedeemFlow(internal/store/sqlite_stores_test.go):
该测试直调 internal/codes.Store 的低层方法(CreateBatch/CreateCode/
FindCodeByHashForUpdate/MarkRedeemed),现在指向被更名的旧表。计划本身在
Task 5(Store 换芯 + Redeem 走库)显式删除此测试、由 Service 级 sqlite 用例
接管等价覆盖 —— 这里先 skip 而非改写/删除,保持 go test ./... 全绿,避免
在 Task 1 提前动到 Task 4/5 范围内的 internal/codes/store.go。
This commit is contained in:
wangjia
2026-07-10 13:46:17 +08:00
parent e44e4616cd
commit 665749a90b
6 changed files with 24 additions and 3 deletions
+3 -3
View File
@@ -29,13 +29,13 @@ func TestSQLiteMigrateUpDown(t *testing.T) {
if dirty {
t.Fatalf("schema dirty after MigrateUp")
}
if v != 19 {
t.Errorf("version = %d, want 19", v)
if v != 20 {
t.Errorf("version = %d, want 20", v)
}
// 2. Core tables exist.
for _, tbl := range []string{
"users", "devices", "plans", "subscriptions", "code_batches", "codes",
"users", "devices", "plans", "subscriptions", "legacy_code_batches", "legacy_codes",
"usage_daily", "audit_log", "providers", "nodes", "node_events",
"directory_version", "provision_idempotency", "replacements", "admins",
"connect_credentials", "usage_device_daily", "sessions", "usage_hourly", "usage_device_hourly",
@@ -191,6 +191,15 @@ func TestSQLite_PersistCredentialUpsert(t *testing.T) {
}
func TestSQLite_CodesRedeemFlow(t *testing.T) {
// SKIP (codes-lib-integration Task 1): migration 000020 renames codes/code_batches
// -> legacy_codes/legacy_code_batches to make room for the github.com/wangjia/codes
// shared library's own `codes` table. This test exercises internal/codes.Store's
// low-level methods (CreateBatch/CreateCode/FindCodeByHashForUpdate/MarkRedeemed),
// which still target the old table names and are slated for removal once
// internal/codes/store.go is re-pointed at the library (Task 4) and the redeem
// path moves to codes.GuardedRedeem (Task 5, which deletes this test in favor of
// an equivalent Service-level sqlite case — see plan §Task 5).
t.Skip("superseded by codes-lib-integration Task 5 (internal/codes Store/Redeem move to shared lib); low-level methods here still target renamed legacy_* tables")
ctx := context.Background()
db := openSQLite(t)
seedUser(t, db, 1)
@@ -0,0 +1,2 @@
RENAME TABLE legacy_code_batches TO code_batches;
RENAME TABLE legacy_codes TO codes;
@@ -0,0 +1,5 @@
-- 旧激活码表更名封存:共享库 github.com/wangjia/codes 拥有自己的 `codes` 表(同名冲突),
-- 新表由 codes.ApplyMigrations 建(cmd/migrate up 内),数据经 Go 侧幂等回填(internal/codes/backfill.go)。
-- legacy_* 只封存不删,retire 留到验收后的 cleanup。
RENAME TABLE codes TO legacy_codes;
RENAME TABLE code_batches TO legacy_code_batches;
@@ -0,0 +1,2 @@
ALTER TABLE legacy_code_batches RENAME TO code_batches;
ALTER TABLE legacy_codes RENAME TO codes;
@@ -0,0 +1,3 @@
-- 同 mysql 版注释;sqlite ≥3.25 的 RENAME 会自动更新其他表 FK 引用。
ALTER TABLE codes RENAME TO legacy_codes;
ALTER TABLE code_batches RENAME TO legacy_code_batches;