-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.py
69 lines (52 loc) · 1.81 KB
/
settings.py
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
class Config(object):
"""Base configuration"""
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
SQLALCHEMY_TRACK_MODIFICATIONS = False
SWAGGER_UI_DOC_EXPANSION = "list"
# pool_pre_ping should help handle DB connection drops
SQLALCHEMY_ENGINE_OPTIONS = {"pool_pre_ping": True}
class ProductionConfig(Config):
"""Production configuration"""
# if deployed to Fly.io, injected env var DATABASE_URL is used
conn = os.environ.get("DATABASE_URL")
if conn is None:
conn = (
"postgresql://"
+ os.environ.get("DB_USER", "")
+ ":"
+ os.environ.get("DB_PASSWORD", "")
+ "@"
+ os.environ.get("DB_HOST", "")
+ ":"
+ os.environ.get("DB_PORT", "")
+ "/"
+ os.environ.get("DB_NAME", "")
)
else:
if conn.startswith("postgres://"):
conn = conn.replace("postgres://", "postgresql://", 1)
SQLALCHEMY_DATABASE_URI = conn
class TestingConfig(Config):
"""Testing configuration"""
DEBUG = True
TESTING = True
SQLALCHEMY_DATABASE_URI = "sqlite:///:memory:"
os.environ["API_KEY"] = "12345678"
class DevelopmentConfig(Config):
"""Development configuration"""
DEBUG = True
DB_NAME = "dev.db"
DB_PATH = os.path.join(Config.PROJECT_ROOT, DB_NAME)
SQLALCHEMY_DATABASE_URI = "sqlite:///{0}".format(DB_PATH)
class WithoutPersistentDatabaseConfig(Config):
"""Development configuration"""
DB_NAME = "dev.db"
DB_PATH = os.path.join(Config.PROJECT_ROOT, DB_NAME)
SQLALCHEMY_DATABASE_URI = "sqlite:///{0}".format(DB_PATH)
config_dict = {
"dev": DevelopmentConfig,
"test": TestingConfig,
"without_persistent_database": WithoutPersistentDatabaseConfig,
"prod": ProductionConfig,
}