diff --git a/server/data/systems.db b/server/data/systems.db index be1a6323f..c9d63db87 100644 Binary files a/server/data/systems.db and b/server/data/systems.db differ diff --git a/tooling/economy-db/import_economics.py b/tooling/economy-db/import_economics.py index 07f71e5f1..f2f493ae0 100755 --- a/tooling/economy-db/import_economics.py +++ b/tooling/economy-db/import_economics.py @@ -358,6 +358,50 @@ UPDATE bodies SET economic_role = 'extraction' WHERE economic_role IN ('minin UPDATE bodies SET economic_role = 'transit_hub' WHERE economic_role = 'transit'; UPDATE bodies SET economic_role = 'service_mixed' WHERE economic_role IN ('commercial', 'coordination'); UPDATE bodies SET economic_role = 'residential' WHERE economic_role = 'frontier'; + +-- Backfill bodies.founding_age_years for all inhabited bodies in player scope (D-216 amendment, +-- ticket #1000). Idempotent: WHERE clause limits to NULL rows, so a re-run is a no-op. +-- +-- Strategy: COALESCE(events-first, wave-fallback) +-- events-first: the system's colonial_charter event age_years (authored; 9 systems in live DB). +-- system_history is keyed PRIMARY KEY on system_id, so the wave subquery returns +-- at most one row; LIMIT 1 is used on historical_events for safety (max one +-- colonial_charter per system in the data). +-- wave-fallback: canonical founding-edge of each settlement_wave range per D-216: +-- wave_1=600, wave_2=500, wave_3=300, wave_4=100, wave_5=40. +-- +-- Exclusions (founding_age_years stays NULL): +-- origin — Sol; out of player scope per D-236. +-- unsettled — 24 systems with inhabited=0; the EXISTS guard also excludes them. +UPDATE bodies +SET founding_age_years = COALESCE( + ( + SELECT he.age_years + FROM historical_events he + WHERE he.system_id = bodies.system_id + AND he.event_type = 'colonial_charter' + LIMIT 1 + ), + ( + SELECT CASE sh.settlement_wave + WHEN 'wave_1' THEN 600 + WHEN 'wave_2' THEN 500 + WHEN 'wave_3' THEN 300 + WHEN 'wave_4' THEN 100 + WHEN 'wave_5' THEN 40 + END + FROM system_history sh + WHERE sh.system_id = bodies.system_id + ) +) +WHERE founding_age_years IS NULL + AND inhabited = 1 + AND EXISTS ( + SELECT 1 + FROM system_history sh2 + WHERE sh2.system_id = bodies.system_id + AND sh2.settlement_wave NOT IN ('origin', 'unsettled') + ); """ # Columns to add to existing tables (ALTER TABLE is idempotent via try/except)