feat(schema): extend systems.db for economics (#804)
Add 5 new tables: gate_links (668 bidirectional edges from star-map.json), commodities (36 types from commodities.toml), production_chains (21 Leontief recipes), chain_inputs (52 input requirements), corp_presence (empty, populated by future pipeline). Add currency_zone column to star_systems (D-172), archetype columns to corporations (D-175). New import pipeline: tooling/economy-db/import_economics.py reads TOML/JSON source files and populates the DB. Idempotent — safe to rerun via `make economy-db`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -38,6 +38,9 @@ CREATE TABLE IF NOT EXISTS star_systems (
|
||||
cultural_corridor TEXT,
|
||||
generation_priority TEXT,
|
||||
|
||||
-- Economics (D-172)
|
||||
currency_zone TEXT DEFAULT 'TRACTUS_PRIMARY', -- TRACTUS_PRIMARY | MARK_PRIMARY | MIXED
|
||||
|
||||
updated_at TEXT DEFAULT (datetime('now'))
|
||||
);
|
||||
|
||||
@@ -201,9 +204,73 @@ CREATE TABLE IF NOT EXISTS corporations (
|
||||
specialization TEXT, -- primary product/service
|
||||
parent_corp TEXT REFERENCES corporations(corp_id),
|
||||
notes TEXT,
|
||||
|
||||
-- Economics (D-175)
|
||||
behavioral_archetype TEXT, -- Monopolist|Distributor|Producer|Specialist|Cooperative|Intermediary
|
||||
supply_chain_role TEXT,
|
||||
shadow_economy_access INTEGER DEFAULT 0,
|
||||
|
||||
updated_at TEXT DEFAULT (datetime('now'))
|
||||
);
|
||||
|
||||
-- Gate adjacency graph — bidirectional edges from star-map.json (D-178)
|
||||
-- Transport cost computation: 5–12% per hop (gate edge), 1–3% (orbital edge)
|
||||
CREATE TABLE IF NOT EXISTS gate_links (
|
||||
from_system_id TEXT NOT NULL REFERENCES star_systems(system_id),
|
||||
to_system_id TEXT NOT NULL REFERENCES star_systems(system_id),
|
||||
PRIMARY KEY (from_system_id, to_system_id)
|
||||
);
|
||||
|
||||
-- Commodity catalog — 36 types (D-184)
|
||||
-- Source: wiki/economics/commodities.toml
|
||||
CREATE TABLE IF NOT EXISTS commodities (
|
||||
commodity_id TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
tier TEXT NOT NULL, -- raw|intermediate|final|service_professional|service_luxury
|
||||
elasticity TEXT NOT NULL, -- perfectly_inelastic|inelastic|unit_elastic|elastic
|
||||
base_price REAL NOT NULL,
|
||||
bulk_class TEXT, -- bulk|liquid|perishable|standard|compact|precision|oversized|non_physical
|
||||
unit TEXT, -- tonnes|units|contracts
|
||||
production_ubiquity TEXT, -- ubiquitous|common|regional|concentrated|monopolistic
|
||||
demand_model TEXT, -- market|utility|compliance
|
||||
commission_certifiable INTEGER DEFAULT 0, -- subject to certification in TRACTUS_PRIMARY zones
|
||||
compact_contested INTEGER DEFAULT 0,
|
||||
shadow_viable INTEGER DEFAULT 0,
|
||||
panic_threshold_weeks INTEGER DEFAULT 0,
|
||||
description TEXT,
|
||||
updated_at TEXT DEFAULT (datetime('now'))
|
||||
);
|
||||
|
||||
-- Leontief production chain recipes (D-178)
|
||||
-- Source: wiki/economics/production_chains.toml
|
||||
CREATE TABLE IF NOT EXISTS production_chains (
|
||||
chain_id TEXT PRIMARY KEY,
|
||||
output_commodity_id TEXT NOT NULL REFERENCES commodities(commodity_id),
|
||||
output_quantity REAL NOT NULL DEFAULT 1.0,
|
||||
location_bound INTEGER DEFAULT 0,
|
||||
description TEXT,
|
||||
updated_at TEXT DEFAULT (datetime('now'))
|
||||
);
|
||||
|
||||
-- Input requirements per production chain
|
||||
CREATE TABLE IF NOT EXISTS chain_inputs (
|
||||
chain_id TEXT NOT NULL REFERENCES production_chains(chain_id),
|
||||
input_commodity_id TEXT NOT NULL REFERENCES commodities(commodity_id),
|
||||
quantity REAL NOT NULL,
|
||||
PRIMARY KEY (chain_id, input_commodity_id)
|
||||
);
|
||||
|
||||
-- Corporation operating locations (D-175)
|
||||
-- Populated by corporation assignment pipeline, not by initial import
|
||||
CREATE TABLE IF NOT EXISTS corp_presence (
|
||||
corp_id TEXT NOT NULL REFERENCES corporations(corp_id),
|
||||
location_id TEXT NOT NULL, -- body_id or station_id
|
||||
location_type TEXT NOT NULL, -- body|station
|
||||
primary_operation TEXT,
|
||||
updated_at TEXT DEFAULT (datetime('now')),
|
||||
PRIMARY KEY (corp_id, location_id)
|
||||
);
|
||||
|
||||
-- Indexes
|
||||
-- astronomical_id removed: system_id IS the GJ catalog number
|
||||
CREATE INDEX IF NOT EXISTS idx_star_systems_sector ON star_systems(geographic_sector);
|
||||
@@ -224,3 +291,11 @@ CREATE INDEX IF NOT EXISTS idx_stations_orbits ON stations(orbits_body_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_stations_type ON stations(station_type);
|
||||
CREATE INDEX IF NOT EXISTS idx_corps_system ON corporations(headquarters_system);
|
||||
CREATE INDEX IF NOT EXISTS idx_corps_type ON corporations(corp_type);
|
||||
CREATE INDEX IF NOT EXISTS idx_star_systems_currency ON star_systems(currency_zone);
|
||||
CREATE INDEX IF NOT EXISTS idx_gate_links_from ON gate_links(from_system_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_gate_links_to ON gate_links(to_system_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_commodities_tier ON commodities(tier);
|
||||
CREATE INDEX IF NOT EXISTS idx_production_chains_output ON production_chains(output_commodity_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_chain_inputs_commodity ON chain_inputs(input_commodity_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_corp_presence_corp ON corp_presence(corp_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_corp_presence_location ON corp_presence(location_id);
|
||||
|
||||
Reference in New Issue
Block a user