35 lines
957 B
Python
35 lines
957 B
Python
from alembic import context
|
|
from sqlalchemy import engine_from_config, pool
|
|
from app.models.announcement import Base
|
|
|
|
config = context.config
|
|
|
|
target_metadata = Base.metadata
|
|
|
|
|
|
def run_migrations_offline():
|
|
from app.config import settings
|
|
url = settings.database_url
|
|
context.configure(url=url, target_metadata=target_metadata, literal_binds=True)
|
|
with context.begin_transaction():
|
|
context.run_migrations()
|
|
|
|
|
|
def run_migrations_online():
|
|
from app.config import settings
|
|
connectable = engine_from_config(
|
|
{"sqlalchemy.url": settings.database_url},
|
|
prefix="sqlalchemy.",
|
|
poolclass=pool.NullPool,
|
|
)
|
|
with connectable.connect() as connection:
|
|
context.configure(connection=connection, target_metadata=target_metadata)
|
|
with context.begin_transaction():
|
|
context.run_migrations()
|
|
|
|
|
|
if context.is_offline_mode():
|
|
run_migrations_offline()
|
|
else:
|
|
run_migrations_online()
|