Replace hardcoded database credentials, ntfy tokens, and Uptime Kuma push URLs with environment variable lookups via python-dotenv. Add .env.example template and update .gitignore to exclude .env. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
# config/database.py
|
|
# 统一的数据库配置
|
|
|
|
import os
|
|
|
|
# ================= SQL Server 配置 =================
|
|
SQL_SERVER_CONFIG = {
|
|
'driver': os.environ.get('DB_DRIVER', 'ODBC Driver 18 for SQL Server'),
|
|
'server': os.environ.get('DB_SERVER', ''),
|
|
'database': os.environ.get('DB_DATABASE', ''),
|
|
'username': os.environ.get('DB_USERNAME', ''),
|
|
'password': os.environ.get('DB_PASSWORD', ''),
|
|
'TrustServerCertificate': 'yes'
|
|
}
|
|
|
|
# ================= Access 驱动配置 =================
|
|
ACCESS_DRIVER = "{Microsoft Access Driver (*.mdb, *.accdb)}"
|
|
|
|
# ================= 兼容性别名 =================
|
|
# 为了兼容旧代码,提供不同命名风格的别名
|
|
|
|
# SQL_SERVER_CONN - 兼容 db_utils.py (使用 uid/pwd)
|
|
SQL_SERVER_CONN = {
|
|
'driver': f"{{{SQL_SERVER_CONFIG['driver']}}}",
|
|
'server': SQL_SERVER_CONFIG['server'],
|
|
'database': SQL_SERVER_CONFIG['database'],
|
|
'uid': SQL_SERVER_CONFIG['username'],
|
|
'pwd': SQL_SERVER_CONFIG['password']
|
|
}
|
|
|
|
# DB_CONFIG - 兼容 etl_manager.py, migration.py (使用 username/password)
|
|
DB_CONFIG = SQL_SERVER_CONFIG.copy()
|