-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdatabase.py
More file actions
39 lines (31 loc) · 871 Bytes
/
database.py
File metadata and controls
39 lines (31 loc) · 871 Bytes
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Module for database connection configuration
This file can be passed as the config file to the Orator CLI, e.g.
`orator migrate -c database.py`
"""
import os
from dotenv import load_dotenv
from orator import DatabaseManager
load_dotenv()
SQL_USER = os.getenv("SQL_USER")
SQL_PASS = os.getenv("SQL_PASS")
SQL_DB = os.getenv("SQL_DB")
SQL_HOST = os.getenv("SQL_HOST")
SQL_PORT = os.getenv("SQL_PORT")
for var in (SQL_USER, SQL_PASS, SQL_DB, SQL_HOST, SQL_PORT):
if var is None:
raise Exception("Cannot find required database login information")
DATABASES = {
'mysql': {
'driver': 'mysql',
'host': SQL_HOST,
'database': SQL_DB,
'user': SQL_USER,
'password': SQL_PASS,
'charset': 'utf8mb4',
'prefix': '',
}
}
db = DatabaseManager(DATABASES)