I've got a standard run of the mill Pylons Pyramid application, that uses SQLAlchemy for its database persistence.
I have set up an SQLAlchemy-migrate repo and have it functioning, but I really want to have the ability to use paster to upgrade and downgrade the database, or at least some way of having the user (after installing the egg) upgrade/downgrading the database to the version required.
I've got it built-into my app now, so upon app startup it does the version upgrade, but I would rather go with something where the user explicitly has to upgrade the database so that they know exactly what is going on, and know to make backups beforehand.
How would I go about that? How do I add commands to paste?
The way users would se开发者_运维问答t up the application is:
paste make-config appname production.ini
paste setup-app production.ini#appname
To set it up the first time, to do the database upgrade or upgrade in general I would want:
paste upgrade-app production.ini#appname
Or something along those lines.
You can create your own paster command, e.g. upgrade-app
, and then call it from anywhere with paster --plugin=appname upgrade-app /path/to/production.ini appname
. You can refer to how pyramid implements the PShellCommand.
It's not quite what you're looking for, but one way I handle this is with Fabric commands. My OSS app I have a fabric command you run that creates a .ini file for your app and then, after you adjust the sqlalchemy.url in it, you run a fabric command that init's SA migrations and runs the upgrade. From then on, to upgrade you run fab db_upgrade.
http://bmark.us/install.html
is an example of the install docs I have setup.
https://github.com/mitechie/Bookie/blob/master/fabfile/database.py
Is the set of db specific commands available through the Fabric interface.
精彩评论