chore(db): switch meta.schema_version to monotonic semver (#888)
Replace SHA-1 hash in meta.schema_version with an orderable semver
string ("1.0.0"). SHA preserved in new schema_sha column for tamper
detection. Enables savegame migration lineage in Phase 5+ — saves can
record their schema version and determine which migrations to apply.
Updated both generators, check-systems-db-stamp validation (rejects
old SHA-hex values), schema DDL, and asset-pipeline docs.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -44,12 +44,21 @@ After every successful non-dry-run, each generator writes a row to the `meta` ta
|
||||
```sql
|
||||
CREATE TABLE meta (
|
||||
generator_name TEXT PRIMARY KEY, -- 'import_economics' | 'generate_atlas'
|
||||
schema_version TEXT NOT NULL, -- SHA-1 of server/data/systems-schema.sql at generation time
|
||||
schema_version TEXT NOT NULL, -- monotonic semver string (e.g. "1.0.0") — see #888
|
||||
schema_sha TEXT, -- SHA-1 of server/data/systems-schema.sql (tamper detection)
|
||||
generator_sha TEXT NOT NULL, -- SHA-1 of the generator source file(s)
|
||||
generated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
);
|
||||
```
|
||||
|
||||
`schema_version` is a **monotonic semver string** (e.g. `"1.0.0"`), not a hash.
|
||||
It is defined as the `SCHEMA_VERSION` constant in `tooling/economy-db/import_economics.py`
|
||||
and must be bumped manually whenever the schema changes in a backwards-incompatible way.
|
||||
Unlike a SHA-1 hash, semver strings are orderable — this enables savegame migration
|
||||
lineage in Phase 5+: a save file can record which schema version it derives from and
|
||||
determine exactly which migrations to apply (#888). The old SHA-1 is preserved in
|
||||
`schema_sha` for tamper detection alongside the semver.
|
||||
|
||||
The `generator_sha` is the SHA-1 of the concatenated bytes of the generator's
|
||||
source files (sorted by path, so order is deterministic). If any source file
|
||||
changes and `make regen-db` is not re-run, the stamped SHA will differ from the
|
||||
@@ -166,8 +175,14 @@ no hand-edit path that survives regen.
|
||||
|
||||
---
|
||||
|
||||
## Future: savegame migration lineage
|
||||
## Savegame migration lineage (Phase 5+)
|
||||
|
||||
The `meta.schema_version` field records the schema SHA at generation time. When the
|
||||
savegame system is built (Phase 5+), a save file can record which systems.db snapshot
|
||||
it derives from, enabling forward migration without branching the DB file itself.
|
||||
`meta.schema_version` now stores a monotonic semver string (#888). When the savegame
|
||||
system is built (Phase 5+), a save file records its `schema_version` string; the
|
||||
loader can determine which migrations to apply by comparing that version to the
|
||||
current one. `meta.schema_sha` retains the old SHA-1 for tamper detection.
|
||||
|
||||
**When to bump `SCHEMA_VERSION`:** edit the `SCHEMA_VERSION = "1.0.0"` constant in
|
||||
`tooling/economy-db/import_economics.py` whenever a schema change is backwards-incompatible
|
||||
(column removed, type changed, FK constraint added, table dropped). Additive changes
|
||||
(new nullable columns, new tables, new indexes) do not require a bump.
|
||||
|
||||
Reference in New Issue
Block a user