Implement REQ-005~009 (dcy-002 slice 1) as an onion stack on top of the
BAT-001 pure domain:
- application: IntentService (admission + single-writer transition +
intent_id idempotency via durable intent_log)
- adapters/persistence: PostgreSQLSlotRepository + PostgreSQLIntentStore +
trex-core-owned migrations (daily_slot per Appendix A, daily_symbol_entries,
slot_transition_log, intent_log) + in-memory intent store
- adapters/api: FastAPI /v1 (healthz, intents/buy|sell|{id}, slots, capacity)
- runtime: trex-core-daemon entrypoint with lifespan migrate+preallocate
Verification (against local PostgreSQL 18): 74 passed, ruff clean, domain
import sweep shows zero web/db deps (NFR-1), 20-thread concurrency admits
exactly the idle count (NFR-2), idempotent resubmit causes no double
transition (NFR-3), EXPECTED_SLOT_FIELDS<->information_schema drift test
(realizes dcy-001 OQ-2's deferred DB-side check), and a daemon E2E smoke.
Align all four baseline docs to the new daemon/API/persistence layers.
BAT-002 -> release-candidate; REQ-005~009 -> Implemented. Full async outbox,
broker execution, safety floor, and strategy daemons remain deferred to a
follow-up Discovery.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
32 lines
1003 B
Python
32 lines
1003 B
Python
"""Apply slot-core SQL migrations in sorted order (REQ-006).
|
|
|
|
Idempotent: every migration uses CREATE TABLE IF NOT EXISTS / CREATE INDEX
|
|
IF NOT EXISTS, so re-running against an existing database is a no-op.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
_SQL_DIR = Path(__file__).resolve().parent / "sql"
|
|
|
|
|
|
def migration_files() -> list[Path]:
|
|
return sorted(_SQL_DIR.glob("*.sql"))
|
|
|
|
|
|
def apply_migrations(dsn: str, *, psycopg_module: Any = None) -> list[str]:
|
|
"""Apply all migrations to `dsn`. Returns the list of applied filenames."""
|
|
if psycopg_module is None:
|
|
import psycopg # type: ignore[import-not-found]
|
|
|
|
psycopg_module = psycopg
|
|
applied: list[str] = []
|
|
with psycopg_module.connect(dsn, autocommit=False) as conn:
|
|
for path in migration_files():
|
|
with conn.cursor() as cur:
|
|
cur.execute(path.read_text())
|
|
applied.append(path.name)
|
|
conn.commit()
|
|
return applied
|