mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-15 04:30:55 +08:00
Move the llm_records and llm_usage DDL out of Go constants into embedded files db/migrations/0001_llm_records.sql and 0002_llm_usage.sql (byte-for-byte the old constants). Open now applies pending migrations after schema.sql and before seedBuiltins, under the existing schema advisory lock and on the lock-holding connection. Each migration runs in its own transaction with its schema_migrations row (version, name, SHA-256 checksum, applied_at). Open fails closed when the database has a version missing from the binary, or an applied migration whose file name or checksum changed. A failing migration is rolled back and blocks startup; earlier ones stay applied. EnsureLLMRecordsTable and EnsureLLMUsageTable re-run the embedded files and keep their transaction-level schema lock; Open never calls them.