leksval commited on
Commit
db4216f
Β·
1 Parent(s): 9a9f096

mysql fallback added

Browse files
Files changed (1) hide show
  1. database.py +13 -18
database.py CHANGED
@@ -31,30 +31,25 @@ class DatabaseManager:
31
  }
32
  self.init_database()
33
 
 
 
 
34
  def get_connection(self):
35
- """Get PostgreSQL connection with proper configuration"""
36
  try:
37
  conn = psycopg2.connect(**self.db_config)
38
  return conn
39
  except Exception as e:
40
  print(f"❌ Database connection failed: {e}")
41
- # Fallback connection attempts
42
- fallback_configs = [
43
- {'host': 'localhost', 'port': 5432, 'database': 'langfuse', 'user': 'langfuse', 'password': 'langfuse'},
44
- {'host': 'langfuse-db-local', 'port': 5432, 'database': 'langfuse', 'user': 'langfuse', 'password': 'langfuse'}
45
- ]
46
-
47
- for config in fallback_configs:
48
- try:
49
- conn = psycopg2.connect(**config)
50
- print(f"βœ… Connected to PostgreSQL via fallback: {config['host']}")
51
- self.db_config = config
52
- return conn
53
- except:
54
- continue
55
-
56
- raise Exception(f"All database connection attempts failed")
57
-
58
  def init_database(self):
59
  """Initialize database schema with proper tables and indexes"""
60
  try:
 
31
  }
32
  self.init_database()
33
 
34
+ import sqlite3
35
+ import os
36
+
37
  def get_connection(self):
38
+ """Get PostgreSQL connection with proper configuration, fallback to SQLite"""
39
  try:
40
  conn = psycopg2.connect(**self.db_config)
41
  return conn
42
  except Exception as e:
43
  print(f"❌ Database connection failed: {e}")
44
+ # Fallback to SQLite
45
+ try:
46
+ sqlite_path = os.getenv('SQLITE_DB_PATH', 'fhirflame_fallback.db')
47
+ conn = sqlite3.connect(sqlite_path)
48
+ print(f"βœ… Connected to SQLite fallback database at {sqlite_path}")
49
+ return conn
50
+ except Exception as e2:
51
+ print(f"❌ SQLite fallback connection failed: {e2}")
52
+ raise e
 
 
 
 
 
 
 
 
53
  def init_database(self):
54
  """Initialize database schema with proper tables and indexes"""
55
  try: