Add PostgreSQL analytics dashboard prototype and realistic sample data
This commit is contained in:
24
mockups/database.py
Normal file
24
mockups/database.py
Normal file
@@ -0,0 +1,24 @@
|
||||
"""PostgreSQL connection settings for the development sample service."""
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import psycopg
|
||||
from psycopg.rows import dict_row
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
def database_url():
|
||||
configured = os.environ.get("DATABASE_URL")
|
||||
if configured:
|
||||
return configured
|
||||
local = ROOT / ".local" / "database.json"
|
||||
if local.exists():
|
||||
return json.loads(local.read_text(encoding="utf-8-sig"))["url"]
|
||||
raise RuntimeError("Database is not configured. Run mockups/setup-database.ps1 or set DATABASE_URL.")
|
||||
|
||||
|
||||
def connect():
|
||||
return psycopg.connect(database_url(), row_factory=dict_row, connect_timeout=5,
|
||||
options="-c search_path=analytics,public -c timezone=UTC -c statement_timeout=15000")
|
||||
Reference in New Issue
Block a user