mirror of
https://github.com/khoaliber/LetterFeed.git
synced 2026-03-02 21:19:13 +00:00
fix: alembic migration with no database url defined
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
from logging.config import fileConfig
|
from logging.config import fileConfig
|
||||||
import os
|
|
||||||
|
|
||||||
from sqlalchemy import engine_from_config
|
from sqlalchemy import engine_from_config
|
||||||
from sqlalchemy import pool
|
from sqlalchemy import pool
|
||||||
@@ -18,7 +17,7 @@ if config.config_file_name is not None:
|
|||||||
# add your model's MetaData object here
|
# add your model's MetaData object here
|
||||||
# for 'autogenerate' support
|
# for 'autogenerate' support
|
||||||
from app.core.database import Base
|
from app.core.database import Base
|
||||||
from app.models import newsletters, entries, settings # noqa
|
from app.core.config import settings as app_settings
|
||||||
|
|
||||||
target_metadata = Base.metadata
|
target_metadata = Base.metadata
|
||||||
|
|
||||||
@@ -40,10 +39,7 @@ def run_migrations_offline() -> None:
|
|||||||
script output.
|
script output.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
url = os.environ.get("DATABASE_URL") or os.environ.get("LETTERFEED_DATABASE_URL")
|
url = app_settings.database_url
|
||||||
if url is None:
|
|
||||||
url = config.get_main_option("sqlalchemy.url")
|
|
||||||
|
|
||||||
context.configure(
|
context.configure(
|
||||||
url=url,
|
url=url,
|
||||||
target_metadata=target_metadata,
|
target_metadata=target_metadata,
|
||||||
@@ -62,26 +58,16 @@ def run_migrations_online() -> None:
|
|||||||
and associate a connection with the context.
|
and associate a connection with the context.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
connectable = None
|
configuration = config.get_section(config.config_ini_section, {})
|
||||||
database_url = os.environ.get("DATABASE_URL") or os.environ.get("LETTERFEED_DATABASE_URL")
|
configuration["sqlalchemy.url"] = app_settings.database_url
|
||||||
|
connectable = engine_from_config(
|
||||||
if database_url:
|
configuration,
|
||||||
connectable = engine_from_config(
|
prefix="sqlalchemy.",
|
||||||
{"sqlalchemy.url": database_url},
|
poolclass=pool.NullPool,
|
||||||
prefix="sqlalchemy.",
|
)
|
||||||
poolclass=pool.NullPool,
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
connectable = engine_from_config(
|
|
||||||
config.get_section(config.config_ini_section, {}),
|
|
||||||
prefix="sqlalchemy.",
|
|
||||||
poolclass=pool.NullPool,
|
|
||||||
)
|
|
||||||
|
|
||||||
with connectable.connect() as connection:
|
with connectable.connect() as connection:
|
||||||
context.configure(
|
context.configure(connection=connection, target_metadata=target_metadata)
|
||||||
connection=connection, target_metadata=target_metadata
|
|
||||||
)
|
|
||||||
|
|
||||||
with context.begin_transaction():
|
with context.begin_transaction():
|
||||||
context.run_migrations()
|
context.run_migrations()
|
||||||
|
|||||||
Reference in New Issue
Block a user