steder / goose

Simple configuration driven SQL migration tool
MIT License
3 stars 0 forks source link

Python Migrations #12

Open steder opened 12 years ago

steder commented 12 years ago

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.