Spaces:
Sleeping
Sleeping
Fix: use options for client_encoding, strip URL newlines, clear engine opts on SQLite fallback
Browse files- backend/app.py +2 -0
- backend/config.py +3 -3
backend/app.py
CHANGED
|
@@ -87,6 +87,7 @@ if db_url.startswith('postgresql') or db_url.startswith('postgres'):
|
|
| 87 |
print(f"[Database] PostgreSQL connection failed: {e}")
|
| 88 |
print("[Database] Falling back to local SQLite database...")
|
| 89 |
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///personaflow.db'
|
|
|
|
| 90 |
else:
|
| 91 |
print(f"[Database] Using SQLite database.")
|
| 92 |
|
|
@@ -102,6 +103,7 @@ with app.app_context():
|
|
| 102 |
print(f"[Database] db.create_all() failed on PostgreSQL: {e}")
|
| 103 |
print("[Database] Falling back to SQLite and retrying...")
|
| 104 |
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///personaflow.db'
|
|
|
|
| 105 |
# Re-initialize with SQLite
|
| 106 |
db.init_app(app)
|
| 107 |
db.create_all()
|
|
|
|
| 87 |
print(f"[Database] PostgreSQL connection failed: {e}")
|
| 88 |
print("[Database] Falling back to local SQLite database...")
|
| 89 |
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///personaflow.db'
|
| 90 |
+
app.config['SQLALCHEMY_ENGINE_OPTIONS'] = {}
|
| 91 |
else:
|
| 92 |
print(f"[Database] Using SQLite database.")
|
| 93 |
|
|
|
|
| 103 |
print(f"[Database] db.create_all() failed on PostgreSQL: {e}")
|
| 104 |
print("[Database] Falling back to SQLite and retrying...")
|
| 105 |
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///personaflow.db'
|
| 106 |
+
app.config['SQLALCHEMY_ENGINE_OPTIONS'] = {}
|
| 107 |
# Re-initialize with SQLite
|
| 108 |
db.init_app(app)
|
| 109 |
db.create_all()
|
backend/config.py
CHANGED
|
@@ -7,8 +7,8 @@ class Config:
|
|
| 7 |
# Flask
|
| 8 |
SECRET_KEY = os.environ.get('SECRET_KEY', 'personaflow-secret-key-change-in-production')
|
| 9 |
|
| 10 |
-
# Database
|
| 11 |
-
db_url = os.environ.get('DATABASE_URL', 'sqlite:///personaflow.db')
|
| 12 |
if db_url.startswith('postgres://'):
|
| 13 |
db_url = db_url.replace('postgres://', 'postgresql://', 1)
|
| 14 |
if 'pgbouncer=' in db_url:
|
|
@@ -31,8 +31,8 @@ class Config:
|
|
| 31 |
if _is_pg:
|
| 32 |
SQLALCHEMY_ENGINE_OPTIONS = {
|
| 33 |
'connect_args': {
|
| 34 |
-
'client_encoding': 'utf8',
|
| 35 |
'connect_timeout': 10,
|
|
|
|
| 36 |
},
|
| 37 |
'pool_pre_ping': True,
|
| 38 |
'pool_recycle': 300,
|
|
|
|
| 7 |
# Flask
|
| 8 |
SECRET_KEY = os.environ.get('SECRET_KEY', 'personaflow-secret-key-change-in-production')
|
| 9 |
|
| 10 |
+
# Database — strip whitespace/newlines from env var
|
| 11 |
+
db_url = os.environ.get('DATABASE_URL', 'sqlite:///personaflow.db').strip()
|
| 12 |
if db_url.startswith('postgres://'):
|
| 13 |
db_url = db_url.replace('postgres://', 'postgresql://', 1)
|
| 14 |
if 'pgbouncer=' in db_url:
|
|
|
|
| 31 |
if _is_pg:
|
| 32 |
SQLALCHEMY_ENGINE_OPTIONS = {
|
| 33 |
'connect_args': {
|
|
|
|
| 34 |
'connect_timeout': 10,
|
| 35 |
+
'options': '-c client_encoding=UTF8',
|
| 36 |
},
|
| 37 |
'pool_pre_ping': True,
|
| 38 |
'pool_recycle': 300,
|