fix(alembic): env.py 優先讀取 DATABASE_URL 環境變數

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
VMIS Developer
2026-03-15 18:34:27 +08:00
parent 8eb3909ca9
commit 405d158660

View File

@@ -16,6 +16,11 @@ config = context.config
if config.config_file_name is not None: if config.config_file_name is not None:
fileConfig(config.config_file_name) fileConfig(config.config_file_name)
# 優先使用環境變數 DATABASE_URL正式環境部署用
_db_url = os.environ.get("DATABASE_URL")
if _db_url:
config.set_main_option("sqlalchemy.url", _db_url)
target_metadata = Base.metadata target_metadata = Base.metadata