env.py 554 B

123456789101112131415161718192021222324
  1. import asyncio
  2. from alembic import context
  3. from zhifu.oms import models # noqa: F401
  4. from zhifu.oms.database import OmsBase, oms_engine
  5. def migrate(connection):
  6. context.configure(connection=connection, target_metadata=OmsBase.metadata, compare_type=True)
  7. with context.begin_transaction():
  8. context.run_migrations()
  9. async def main():
  10. engine = oms_engine()
  11. try:
  12. async with engine.connect() as connection:
  13. await connection.run_sync(migrate)
  14. finally:
  15. await engine.dispose()
  16. asyncio.run(main())