-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathenv.py
42 lines (29 loc) · 1 KB
/
env.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import asyncio
from alembic import context
from sqlalchemy.ext.asyncio import create_async_engine
from app.config import settings
from app.models.base import Base
target_metadata = Base.metadata
def do_run_migrations(connection):
context.configure(
compare_type=True,
dialect_opts={"paramstyle": "named"},
connection=connection,
target_metadata=target_metadata,
include_schemas=True,
# literal_binds=True,
version_table_schema=target_metadata.schema,
)
with context.begin_transaction():
context.run_migrations()
async def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
connectable = create_async_engine(
settings.asyncpg_url.unicode_string(), future=True
)
async with connectable.connect() as connection:
await connection.run_sync(do_run_migrations)
asyncio.run(run_migrations_online())