feat(deploy): 接入生产密钥与数据库迁移
Deploy Production / deploy (push) Successful in 1m42s

This commit is contained in:
yuxuanhui
2026-08-05 22:45:57 +08:00
parent d7d5ed8979
commit afdc5ca909
9 changed files with 139 additions and 33 deletions
@@ -31,6 +31,31 @@ class Settings(BaseSettings):
)
def sqlalchemy_database_url(database_url: str) -> str:
"""Add SQLAlchemy's Psycopg 3 driver to a PostgreSQL URL.
``Settings.database_url`` remains a plain ``postgresql://`` URL because
Psycopg 3 accepts that form directly. Alembic and SQLAlchemy need the
explicit ``postgresql+psycopg://`` dialect, while the rest of the URL
(including query parameters such as ``sslmode``) must remain unchanged.
Args:
database_url: PostgreSQL connection URL from the process environment.
Returns:
The URL with SQLAlchemy's Psycopg 3 dialect prefix.
Raises:
ValueError: If the URL does not use a supported PostgreSQL scheme.
"""
if database_url.startswith("postgresql+psycopg://"):
return database_url
if database_url.startswith("postgresql://"):
return "postgresql+psycopg://" + database_url.removeprefix("postgresql://")
raise ValueError("database_url must use postgresql:// or postgresql+psycopg://")
@lru_cache
def get_settings() -> Settings:
"""Return one immutable-by-convention configuration object per process.