-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
69 lines (53 loc) · 2.47 KB
/
Copy pathconfig.py
File metadata and controls
69 lines (53 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import os
from dotenv import load_dotenv
load_dotenv()
def get_database_uri():
"""Get database URI - supports PostgreSQL, local SQLite, or Turso."""
basedir = os.path.abspath(os.path.dirname(__file__))
default_db = f'sqlite:///{os.path.join(basedir, "instance", "carehub_dev.db")}'
uri = os.environ.get('DATABASE_URL', default_db)
# For Turso - currently not supported without Rust compilation
# Use PostgreSQL or SQLite instead
if uri.startswith('libsql://'):
print("⚠️ Turso (libsql://) URLs require Rust compilation which may fail on Render")
print("📝 Using local SQLite instead. For production, consider PostgreSQL.")
print("ℹ️ To use Turso: Install Rust locally or use PostgreSQL on Render")
# Fall back to local SQLite
os.makedirs(os.path.join(basedir, 'instance'), exist_ok=True)
return default_db
# PostgreSQL support (recommended for Render production)
if uri.startswith('postgresql://') or uri.startswith('postgres://'):
# Fix postgres:// to postgresql:// for SQLAlchemy 1.4+
if uri.startswith('postgres://'):
uri = uri.replace('postgres://', 'postgresql://', 1)
print("INFO: Using PostgreSQL database")
return uri
# Ensure instance directory exists for local SQLite
os.makedirs(os.path.join(basedir, 'instance'), exist_ok=True)
print("INFO: Using local SQLite database")
return uri
class Config:
"""Base configuration."""
SECRET_KEY = os.environ.get('SECRET_KEY', 'dev-secret-key-change-in-production')
SQLALCHEMY_DATABASE_URI = get_database_uri()
SQLALCHEMY_TRACK_MODIFICATIONS = False
SQLALCHEMY_ENGINE_OPTIONS = {
'pool_pre_ping': True, # drops stale connections before using them
'pool_recycle': 300, # recycle connections every 5 min
'pool_size': 10, # keep 10 connections warm
'max_overflow': 20, # allow 20 extra under burst load
'pool_timeout': 30, # wait max 30s for a free connection
}
class DevelopmentConfig(Config):
"""Development configuration."""
DEBUG = True
# Development uses the same database URI logic from base Config
class ProductionConfig(Config):
"""Production configuration."""
DEBUG = False
# Production uses the same database URI logic from base Config
config = {
'development': DevelopmentConfig,
'production': ProductionConfig,
'default': DevelopmentConfig,
}