Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run alembic upgrade migrations in a transaction

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

like image 569
Petrus Theron Avatar asked Feb 28 '14 12:02

Petrus Theron


People also ask

How do you run all alembic migrations?

Alembic is keeping track of the migrations in the alembic_version table on your database. Simple drop the table to start from scratch using the following command: DROP TABLE alembic_version; And then try to run your migration again!

What is alembic revision?

Alembic provides for the creation, management, and invocation of change management scripts for a relational database, using SQLAlchemy as the underlying engine. This tutorial will provide a full introduction to the theory and usage of this tool.

How does alembic Autogenerate work?

Alembic can view the status of the database and compare against the table metadata in the application, generating the “obvious” migrations based on a comparison. This is achieved using the --autogenerate option to the alembic revision command, which places so-called candidate migrations into our new migrations file.

How do you change heads in alembic?

Show activity on this post. Delete (or move to another folder) the specific migration file (in migrations/versions folder). The head will automatically revert to the most recent remaining migration. Using stamp will set the db version value to the specified revision; not alter the head revision number.


1 Answers

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.

like image 177
Rachel Sanders Avatar answered Oct 12 '22 01:10

Rachel Sanders