Brussels / 1 & 2 February 2014


Some recipes with Alembic

The SysGrove® project is mainly based on PyQt4 and SQLAlchemy. Application development and enhancement is ongoing and as a matter of fact, the database scheme is changing quite often with many migrations per day.

As the minimal set of data to test and run the application is quite important, we use Alembic to handle database migrations. It is rather simple to put Alembic in place and to run automatic migrations. The process is well documented in Alembic itself and has been detailed in some places on the web ( for example). However it is more difficult to find examples of complex migration problems. Alembic auto-migration only handles the following cases : - Table additions, removals. - Column additions, removals. - Change of nullable status on columns. - Basic changes in indexes and explicitly-named unique constraints Combining Alembic together with SQLAlchemy provides many ways to handle more complex cases. In this talk, we will deal with examples such as : - rename a column in a table - adding an Enum column - add a none nullable columns in a table containing data - dealing with sequences - updating data from a migration scripts - ...


Claude Huchet