feat: derive POSTGRES_DB and Redis prefix from DEPLOY_STAGE for pipeline isolation

This commit is contained in:
Celes Renata
2026-04-20 01:33:14 +00:00
parent d64ce82649
commit 8f67d326c9
2 changed files with 11 additions and 2 deletions
+7 -1
View File
@@ -105,6 +105,12 @@ def _bucket(name: str) -> str:
prefix = os.getenv("DEPLOY_STAGE", "") prefix = os.getenv("DEPLOY_STAGE", "")
return f"{prefix}-{name}" if prefix else name return f"{prefix}-{name}" if prefix else name
def _stage_db() -> str:
"""Derive database name from DEPLOY_STAGE. Empty stage = 'stonks'."""
stage = os.getenv("DEPLOY_STAGE", "")
return f"stonks_{stage}" if stage else "stonks"
BUCKET_RETENTION_FIELDS: dict[str, str] = { BUCKET_RETENTION_FIELDS: dict[str, str] = {
_bucket("stonks-raw-market"): "raw_market_days", _bucket("stonks-raw-market"): "raw_market_days",
_bucket("stonks-raw-news"): "raw_news_days", _bucket("stonks-raw-news"): "raw_news_days",
@@ -229,7 +235,7 @@ def load_config() -> AppConfig:
postgres=PostgresConfig( postgres=PostgresConfig(
host=os.getenv("POSTGRES_HOST", "localhost"), host=os.getenv("POSTGRES_HOST", "localhost"),
port=int(os.getenv("POSTGRES_PORT", "5432")), port=int(os.getenv("POSTGRES_PORT", "5432")),
database=os.getenv("POSTGRES_DB", "stonks"), database=os.getenv("POSTGRES_DB", "") or _stage_db(),
user=os.getenv("POSTGRES_USER", "stonks"), user=os.getenv("POSTGRES_USER", "stonks"),
password=os.getenv("POSTGRES_PASSWORD", "stonks_dev"), password=os.getenv("POSTGRES_PASSWORD", "stonks_dev"),
), ),
+4 -1
View File
@@ -1,7 +1,10 @@
"""Redis key conventions and queue abstractions.""" """Redis key conventions and queue abstractions."""
import os
# --- Key prefixes --- # --- Key prefixes ---
PREFIX = "stonks" _STAGE = os.getenv("DEPLOY_STAGE", "")
PREFIX = f"stonks:{_STAGE}" if _STAGE else "stonks"
# Distributed locks # Distributed locks
LOCK_PREFIX = f"{PREFIX}:lock" LOCK_PREFIX = f"{PREFIX}:lock"