如何使用 GitHub 为独立 PHP 项目实现自动更新?
我的项目是使用MySQL作为数据库的PHP脚本集合,需要使用WAMP/LAMP/MAMP本地安装。
此前,我一直向用户发送一个压缩存档的链接,并让他们覆盖它,但自从我尝试使用 GitHub 后,我意识到还有更好的方法;即 GitHub 中的 Service Hooks。但是,只要我不以任何方式更改数据库,这就可以正常工作,这是一个很好的可能性。
我一直在考虑如何实现这一点,但我找不到明确的解决方案。到目前为止,我得出的结论是,我需要一个目录(例如 update/),其中包含每次更新的 .sql 文件。然后,PHP 脚本将检查所述目录中是否有与新版本号对应的文件(不确定我将如何定义版本号;我正在考虑使用提交 ID,但直到提交之后才可用,所以...)。
我希望对此有一些意见!
My project is a collection of PHP scripts using MySQL as a database and needs to be installed locally using WAMP/LAMP/MAMP.
Previously I've been sending the users a link to a zipped archive and having them overwrite it, but since I took the plunge to GitHub, I've realized that there are far better ways; namely Service Hooks in GitHub. However, this would work fine as long as I don't alter the database in any way, which is a good possibility.
I've been toying with the idea of how I would implement this, but I can't find a clear solution. So far I've concluded with that I need to have a directory (say update/) which contains .sql files for each update. The PHP script will then check said directory for a file corresponding with the new version number (not sure how I will define a version number; I was thinking of using the commit ID, but that won't be available until after the commit, so...).
I would love some input on this!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是我解决这个问题的方法(不是最优雅或最高性能的):
update/
中的 PHP 文件,该文件将在数据库服务器上运行一系列ALTER TABLE
命令交替地,您可以拥有一个由数据库接口 PHP 文件生成的文件(并用 .gitignore 忽略),而不是查询数据库,您可以直接使用该文件如上所述。
Here's how I would tackle this (not the most elegant or performant):
update/
which would have a series ofALTER TABLE
commands to be run on the DB serverAlternately instead of querying the DB you can have a file which is generated by your DB interface PHP file (and ignored with .gitignore) which you can just as above.
我真的建议您查看 Doctrine 及其 迁移功能。
这正是您所寻找的,而且您还获得了一个非常好的工具来处理数据库处理的所有其他方面。
I would really recommend checking out Doctrine and its migration feature.
This does exactly what you are looking for, plus you get a very nice tool for working with all other aspects of your database handling.