Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pyramid schema migrations

I'm using "vanilla" Pyramid 1.4 under Gentoo and I want to make changes to my tables and commit them without having to delete the table (and all of it's data) and then recreate it. I've heard the solution to this is schema migrations.

Being a long-time Django user, I've been using django-south, but now I'm using Pyramid I can't find any way to handle migrations. I've read about sqlalchemy-migrate, which looks really good but I'm unsure how to get it to work with Pyramid.

Are there any ways to handle schema migrations in Pyramid 1.4? And if using sqlalchemy-migrate is the sensible option, how do I get it working with Pyramid?

Cheers.

like image 487
q3d Avatar asked Dec 01 '22 21:12

q3d


2 Answers

While that doesn't directly answer your question: Did you consider Alembic instead, a new SQLAlchemy migration tool by Mike Bayer himself (SQLAlchemy's author)? Development on sqlalchemy-migrate seems to have stopped in January whereas Alembic is quite active.

like image 152
Martin S. Avatar answered Dec 15 '22 17:12

Martin S.


As Martin says, I'd suggest going with Alembic for your migrations. It's from the creator of SqlAlchemy and should keep in sync with any SqlAlchemy changes pretty nicely.

As for wiring it into your framework, that's up to you. I set it up in Bookie by updating the env.py in Alembic to load my Pyramid .ini file. You can see the changes in the code here:

https://github.com/mitechie/Bookie/blob/develop/dbversions/env.py#L8

This also loads the models so that you can use the auto generation of changes.

I then control the migrations via helpers in my Makefile that allow me to generate, update, etc.

https://github.com/mitechie/Bookie/blob/develop/Makefile#L67

These could probably be turned into pyramid p* commands but I've not done so. http://pyramid.readthedocs.org/en/latest/narr/commandline.html#writing-a-script

like image 25
Rick Avatar answered Dec 15 '22 18:12

Rick