saibalajiomg commited on
Commit
1533d3f
·
verified ·
1 Parent(s): afd0cbd

Upload folder using huggingface_hub

Browse files
docker-compose.monitoring.yml CHANGED
@@ -42,6 +42,6 @@ services:
42
  networks:
43
  - customercore
44
  ports:
45
- - "3000:3000"
46
  depends_on:
47
  - prometheus
 
42
  networks:
43
  - customercore
44
  ports:
45
+ - "3001:3000"
46
  depends_on:
47
  - prometheus
src/api/main.py CHANGED
@@ -131,6 +131,13 @@ async def lifespan(app: FastAPI):
131
  env=os.getenv("APP_ENV", "development"),
132
  version="1.0.0")
133
 
 
 
 
 
 
 
 
134
  # Register Langfuse as LiteLLM callback (Phase 11 — LLM Observability)
135
  try:
136
  from src.monitoring.langfuse_tracer import setup_litellm_tracing
 
131
  env=os.getenv("APP_ENV", "development"),
132
  version="1.0.0")
133
 
134
+ # Run database migration checks
135
+ try:
136
+ from src.db.migrations import run_db_migrations
137
+ run_db_migrations()
138
+ except Exception as exc:
139
+ log.warning("Database migration checks failed (non-fatal)", error=str(exc))
140
+
141
  # Register Langfuse as LiteLLM callback (Phase 11 — LLM Observability)
142
  try:
143
  from src.monitoring.langfuse_tracer import setup_litellm_tracing
src/db/migrations.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import psycopg2
3
+ import logging
4
+
5
+ logger = logging.getLogger("customercore.db.migrations")
6
+
7
+ def run_db_migrations():
8
+ """
9
+ Checks if tickets table has missing columns and updates it.
10
+ Also notifies PostgREST to reload its schema cache.
11
+ Fails gracefully if the database is unreachable (e.g., in IPv6-unsupported environments).
12
+ """
13
+ db_url = os.environ.get("SUPABASE_DB_URL")
14
+ if not db_url:
15
+ logger.warning("SUPABASE_DB_URL is not set. Skipping DDL migrations.")
16
+ return
17
+
18
+ logger.info("Running database migration checks...")
19
+ try:
20
+ # Connect to Postgres
21
+ conn = psycopg2.connect(db_url, connect_timeout=5)
22
+ conn.autocommit = True
23
+ cursor = conn.cursor()
24
+
25
+ # Add columns if not present
26
+ cursor.execute("""
27
+ ALTER TABLE tickets
28
+ ADD COLUMN IF NOT EXISTS customer_tier TEXT NOT NULL DEFAULT 'free'
29
+ CHECK (customer_tier IN ('free','starter','growth','enterprise','vip'));
30
+ """)
31
+
32
+ cursor.execute("""
33
+ ALTER TABLE tickets
34
+ ADD COLUMN IF NOT EXISTS masked_text TEXT;
35
+ """)
36
+
37
+ # Reload PostgREST schema cache
38
+ cursor.execute("SELECT pg_notify('pgrst', 'reload schema');")
39
+ logger.info("Database migration check completed successfully. PostgREST schema reloaded.")
40
+
41
+ cursor.close()
42
+ conn.close()
43
+ except psycopg2.OperationalError as oe:
44
+ # Graceful fallback: log warning and continue so local app startup does not crash
45
+ logger.warning(
46
+ "Database connection timed out or unreachable (normal in local environments without IPv6 routing). "
47
+ f"Details: {oe}"
48
+ )
49
+ except Exception as e:
50
+ logger.error(f"Failed to execute database migrations: {e}")