The sole generator of systems.db moves to tooling/domains/ledger/ and is now `reach ledger import`. economy_import/ keeps its name (Rust comments in server/src cite it); the entrypoint becomes service.py; schema_version.py moves with the importer, which is where the version is defined. The stamp survived the move, which is the thing that had to hold: - generated_brands.toml is byte-identical (sha256 e748531…) before and after - `reach check systems-db-stamp` reported STALE after the move (the registry saw it) and OK after the regen - the dry-run carries every count and warning of the baseline transcript, and exit 2 — imported and stamped, coverage gate unmet — still reaches the caller through @command `make regen-db` survives as a one-line delegate, per D-263's muscle-memory clause: about fifty files name it, including the headers of generated wiki TOMLs and the remedies the push gate prints. `make economy-db` is retired; it ran `reach generate brands` before the import, which the import already does as its first step. economy_import.errors is reconciled as DOMAINS.md asked. ImportAborted stays as internal rollback control flow and never reaches a caller; the service converts it to a ReachError carrying the remedy. regenerate_brands caught cargo_binary's ReachError, printed it and raised ImportAborted, dropping the remedy. It runs before the import transaction opens, so there is nothing to roll back — it now propagates. Both sys.path bootstraps are gone; they existed only because the directory was hyphenated. The step labels ran [1/10]…[10/13]…[17/19]; one 24-step counter now drives the event phase and progress. Stale pointers fixed on the way: MIGRATION_SQL has lived in economy_import/migration.py since T-1067, but the asset-pipeline rule, DEVOPS and the schema comments still sent readers to import_economics.py; the rule and DEVOPS also still named the check scripts T-1281 retired. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
34 lines
1.3 KiB
Python
34 lines
1.3 KiB
Python
"""Connection and table-maintenance helpers for the economics import."""
|
|
|
|
import sqlite3
|
|
from pathlib import Path
|
|
|
|
|
|
def connect(db_path: Path) -> sqlite3.Connection:
|
|
"""Open systems.db with foreign-key enforcement on."""
|
|
conn = sqlite3.connect(str(db_path))
|
|
conn.execute("PRAGMA foreign_keys=ON")
|
|
return conn
|
|
|
|
|
|
def clear_economics_tables(conn: sqlite3.Connection) -> None:
|
|
"""Clear economics tables in FK-safe order (children before parents).
|
|
|
|
corp_presence is cleared here; the corporations table is append-only
|
|
(never cleared). Runs inside the caller's transaction, so a failure
|
|
later in the import rolls these DELETEs back too.
|
|
"""
|
|
conn.execute("DELETE FROM corp_presence")
|
|
conn.execute("DELETE FROM brand_inputs")
|
|
conn.execute("DELETE FROM brand_products")
|
|
conn.execute("DELETE FROM system_fiscal")
|
|
conn.execute("DELETE FROM corp_financial_state")
|
|
conn.execute("DELETE FROM corp_lifecycle_events")
|
|
conn.execute("DELETE FROM chain_inputs")
|
|
conn.execute("DELETE FROM production_chains")
|
|
# specialization_vocabulary FK-references commodities — clear it
|
|
# before commodities so the FK-on delete does not fail (D-237).
|
|
conn.execute("DELETE FROM specialization_vocabulary")
|
|
conn.execute("DELETE FROM commodities")
|
|
conn.execute("DELETE FROM gate_links")
|