leksval
commited on
Commit
·
db4216f
1
Parent(s):
9a9f096
mysql fallback added
Browse files- 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
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 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:
|