- supabase_client.py: lazy singleton client (no-ops when env vars absent)
- persistence.py: persist_upload writes batch, source_files, normalized_records,
mapping_decisions, report_runs; persist_export records export_files
- schema.sql: 11-table schema with RLS + WORM rules for audit/raw tables
- main.py: wire persist_upload/persist_export; add ExportRequest body model
so export accepts {records, batch_id}; batch_id returned on upload response
- api.js: add exportFromBackend helper passing batch_id through
- requirements.txt: add supabase>=2.0.0
- smoke_test.py: update export call to new body format
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
28 lines
636 B
Python
28 lines
636 B
Python
import logging
|
|
import os
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
_client = None
|
|
|
|
|
|
def get_client():
|
|
"""Return a Supabase client or None if env vars are not set (dev mode)."""
|
|
global _client
|
|
if _client is not None:
|
|
return _client
|
|
|
|
url = os.getenv("SUPABASE_URL", "")
|
|
key = os.getenv("SUPABASE_SERVICE_KEY", "")
|
|
|
|
if not url or not key:
|
|
return None
|
|
|
|
try:
|
|
from supabase import create_client
|
|
_client = create_client(url, key)
|
|
logger.info("Supabase client initialized")
|
|
except Exception as e:
|
|
logger.error(f"Supabase client init failed: {e}")
|
|
|
|
return _client
|