升级 Pyramid/SQLAlchemy Web 应用程序
我有一个标准运行的 Pylons Pyramid 应用程序,它使用 SQLAlchemy 来实现数据库持久性。
我已经建立了一个 SQLAlchemy-migrate 存储库并使其正常运行,但我真的希望能够使用 Paster 来升级和降级数据库,或者至少以某种方式让用户(安装 Egg 后)升级/降级将数据库升级到所需的版本。
我现在已经将它内置到我的应用程序中,因此在应用程序启动时它会进行版本升级,但我宁愿选择用户明确必须升级数据库的东西,以便他们确切地知道发生了什么,并且知道提前做好备份。
我该怎么办呢?如何添加要粘贴的命令?
用户设置应用程序的方式是:
paste make-config appname production.ini
paste setup-app production.ini#appname
第一次设置它,进行数据库升级或一般升级,我想要:
paste upgrade-app production.ini#appname
或者类似的东西。
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 set 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以创建自己的 Paster 命令,例如
upgrade-app
,然后使用paster --plugin=appnameupgrade-app /path/to/production.ini appname
从任何地方调用它代码>.你可以参考pyramid如何实现PShellCommand。You can create your own paster command, e.g.
upgrade-app
, and then call it from anywhere withpaster --plugin=appname upgrade-app /path/to/production.ini appname
. You can refer to how pyramid implements the PShellCommand.这不完全是你正在寻找的,但我处理这个问题的一种方法是使用 Fabric 命令。我的 OSS 应用程序中,您运行一个 Fabric 命令,该命令为您的应用程序创建一个 .ini 文件,然后在调整其中的 sqlalchemy.url 后,运行一个 Fabric 命令来初始化 SA 迁移并运行升级。从那时起,要升级,请运行 fab db_upgrade。
http://bmark.us/install.html
是我设置的安装文档的示例。
https://github.com/mitechie/Bookie/blob/master/fabfile /database.py
是通过 Fabric 接口可用的一组特定于数据库的命令。
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.