how to set sqlalchemy.url in alembic.ini if I have from pydantic import BaseSettings,…
- User
how to set sqlalchemy.url in alembic.ini if I have from pydantic import BaseSettings, PostgresDsn, Field
class Settings(BaseSettings): db_url: PostgresDsn db_port: int db_user: str db_name: str db_pass: str db_host: str port: int host: str
class Config: env_file = '.env'settings = Settings() is that correct sqlalchemy.url = f"postgresql+asyncpg://{settings.database_user}:{settings.database_password}@{settings.database_host}:{settings.database_port}/{settings.database_name}"?async_fallback=True
- Assistant
No, it is not correct. The format of the SQLAlchemy URL in alembic.ini is slightly different.
To set it using your current configuration, you can use the following format:
sqlalchemy.url = postgresql+asyncpg://{db_user}:{db_pass}@{db_host}:{db_port}/{db_name}This will replace the variables with their corresponding values from your
Settingsclass.