Skip to content

feat: 實作 SQLite 持久化與明確 migration - #16

Merged
Command1264 merged 10 commits into
developfrom
codex/feat/sqlite-storage
Sep 22, 2026
Merged

Command1264 merged 10 commits into
developfrom
codex/feat/sqlite-storage

Conversation

@Command1264

Copy link
Copy Markdown
Owner

問題與結果

InviteCodeKt 原先只有儲存模組骨架,Invitation、Qualification、Reward 與稽核資料無法透過 production SQLite backend 跨重啟保存。本 PR 實作 SQLite persistence adapter 與五版明確 schema migration,並以 transaction、unique constraint 及狀態驗證維持領域不變量。

完成後:

  • 玩家識別、First Seen At、Invite Code、Invitation、Qualification Fact、Reward Delivery/Action 與 Audit Record 都能跨重啟保存。
  • 初始 Invitation 只能以 CLAIMED 寫入;一般 qualification 會把 Qualified Invitation 與相符 Facts 原子保存,管理操作則原子保存狀態與 Audit Record。
  • Eligibility Reset 以新世代恢復 Claim 資格,同時保留舊 Invitation 歷史。
  • Reward aggregate 必須整組從 PENDING 建立;Delivery 與 Action 狀態、完整集合、Invitation 歸屬及 idempotency 邊界會在寫入前驗證。
  • Reward 狀態轉換保留 append-only 歷史;重啟可將中斷的 PROCESSING Action 原子轉成 UNCERTAIN,只有帶 actor 與 reason 的管理操作可重試或標記已交付。
  • migration 與一般 write 的 rollback 失敗會明確回報資料庫狀態不確定,不會切換到 fallback backend。
  • 所有 SQLite 入口都要求 BlockingOperationGuard,避免在 server main thread 執行 blocking I/O。
  • 插件 JAR 內含 SQLite JDBC driver、service descriptor,以及 Windows/Linux x86_64 原生程式庫。

使用 org.xerial:sqlite-jdbc:3.53.4.0 作為 SQLite driver。

驗證

  • mise exec -- .\gradlew.bat clean check shadowJar(Java 11)
  • mise exec java@local-8 -- .\gradlew.bat clean check shadowJar(Java 8)
  • 63 個核心/SQLite contract tests:0 failures、0 skipped
  • Java 8 直接從最終插件 JAR 建立 SQLite database、執行 migration 並開啟 schema 5
  • verifyJava8Bytecode 與 verifyPluginJar 通過
  • 最終獨立 review:Spec: 0 findings、Standards: 0 findings

成品 SHA-256:DF72A7679E18774B939626809E09603988CD33B0E0B2C262EAB54370648F0941

Closes #5

@Command1264
Command1264 merged commit 0621a1d into develop Sep 22, 2026
4 checks passed
@Command1264
Command1264 deleted the codex/feat/sqlite-storage branch September 22, 2026 01:27
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