Run alembic upgrade migrations in a transaction

人盡茶涼 提交于 2019-12-04 00:40:38

问题


Does alembic upgrade head run inside a transaction so that all database alterations succeed, or fail? If not, why was it designed this way?


回答1:


My understanding is alembic runs inside a transaction for databases that support it, like Postgres. If you're on a database that does not support this (cough MySQL cough), you can't use this functionality.




回答2:


That's something you can decide within the env.py, which is where you customize the behaviour of the migrations to suit your setup. You can see how to make sure your upgrades happen in a transaction from the template provided as an example for generic databases: https://github.com/zzzeek/alembic/blob/eaaafbca88f85f5432e04affe1f94cbf1ad06080/alembic/templates/generic/env.py#L64

def run_migrations_online():
    # ...
    with context.begin_transaction():
        context.run_migrations()


来源:https://stackoverflow.com/questions/22095039/run-alembic-upgrade-migrations-in-a-transaction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!