steder/goose — Issue #12: Python Migrations
Author: steder
Created: 2012-03-09 09:50:55+00:00
State: open

Python Migrations allow you to run migrations run some logic that is particularly unwieldy in SQL and integrate that migration logic into the rest of your migration process. They might also be used to implement migrations for NoSQL stores.

I'm thinking that every python migration is something like:

# begin python migration
def forward(cursor):
"""Migrate the database forward to the next version by manipulating the cursor"""

def reverse(cursor):
"""Roll back this migration using the cursor provided"""

For SQL migrations the cursor allows us to control the transaction boundary within Goose, the python migration scripts can do whatever they want and apply whatever logic, but they should run within a single transaction if possible.

For NoSQL migrations the signature might be more like:

def forward(connection_to_db):
""""Do migrations using the provided connection_to_db"""

This way, while the migrations really don't have transactions to leverage they can at least not have to figure out independently how to connect to the DB.