fix(db): address PR #144 review (#1000)

- Update D-216 amendment text to match the implemented decision:
  events-first uses event_type='colonial_charter' (9 systems, 11 bodies,
  5 diverging from wave) — not the stale founding/first_settlement/
  colonization scaffolding vocabulary.
- Add ORDER BY sort_order ASC to the colonial_charter subquery for a
  deterministic pick if a system ever has two charter rows.
- Add explicit ELSE NULL to the wave-fallback CASE so an unexpected
  settlement_wave leaves a trace instead of silently nulling.

Data unchanged: 269/273 set, 4 Sol NULL; stamp fresh.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-30 22:07:06 +02:00
co-authored by Claude Opus 4.8
parent 4319e40a63
commit 9f4b1bf02c
3 changed files with 3 additions and 1 deletions
+1 -1
View File
@@ -1205,7 +1205,7 @@ Technical foundation decisions that constrain implementation: engine, client-ser
- **Ticket:** #922
- **Raised by:** Generation cascade workshop (#897)
- **Cross-reference:** D-096 (DistrictLayoutMode::Organic — consumes block_irregularity), D-194 (district mix — founding_age is an input), D-214 (PoliticalArchetype — archetype_step source)
- **Amendment (2026-05-26 — `founding_age_years` backfill, ticket #1000):** `founding_age_years` is backfilled on every inhabited body in `tooling/economy-db/import_economics.py` MIGRATION_SQL via `COALESCE(events-first, wave-fallback)`. **Events-first:** the system's authored `historical_events.age_years` for an `event_type ∈ {founding, first_settlement, colonization}` — currently empty in the live DB, so it is forward-compatible scaffolding only. **Wave-fallback** — canonical **founding-edge** of each wave's range (`docs/design/systems-framework-final-miri.md:495499`):
- **Amendment (2026-05-26 — `founding_age_years` backfill, ticket #1000):** `founding_age_years` is backfilled on every inhabited body in `tooling/economy-db/import_economics.py` MIGRATION_SQL via `COALESCE(events-first, wave-fallback)`. **Events-first:** the system's authored `historical_events.age_years` for `event_type = 'colonial_charter'` — the canonical founding event authored during the economics built-world workshop. 9 systems in the live DB carry a colonial_charter row, driving 11 inhabited body values; 5 of those diverge meaningfully from their wave fallback (e.g. GJ 144 = 580 vs wave-1 fallback 600, GJ 338B = 590, GJ 380 = 480). **Wave-fallback** — canonical **founding-edge** of each wave's range (`docs/design/systems-framework-final-miri.md:495499`):
| `settlement_wave` | era | range (years ago) | founding-edge fallback |
|---|---|---|---|
Binary file not shown.
+2
View File
@@ -380,6 +380,7 @@ SET founding_age_years = COALESCE(
FROM historical_events he
WHERE he.system_id = bodies.system_id
AND he.event_type = 'colonial_charter'
ORDER BY he.sort_order ASC
LIMIT 1
),
(
@@ -389,6 +390,7 @@ SET founding_age_years = COALESCE(
WHEN 'wave_3' THEN 300
WHEN 'wave_4' THEN 100
WHEN 'wave_5' THEN 40
ELSE NULL -- unexpected settlement_wave: add a WHEN above
END
FROM system_history sh
WHERE sh.system_id = bodies.system_id