使用 yii php 框架保持数据库版本控制的最佳方法是什么?

发布于 2024-10-07 12:45:31 字数 153 浏览 0 评论 0原文

来自 ruby​​ on Rails 世界,我正在寻找一种有效的方法来版本化我的数据库(对于 Rails,迁移就是为了这个目的)。

目前,我正在定期拍摄数据库快照并导出整个架构,但整个过程非常手动。

有更好的方法吗?

ps我用的是mysql。

Coming from the ruby on rails world, I'm looking for an efficient way to version my database (in case of rails, migration serves that purpose).

Currently I'm taking snapshots of the database and exporting the entire schema on a regular bases, but the entire process is pretty manual.

Is there a better way to do this?

p.s. I'm using mysql.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

七七 2024-10-14 12:45:31

在 Yii 1.1.6 中将出现数据库迁移的概念。这将允许我们使用 PHP 代码以与数据库无关的方式进行数据库操作。请参阅 http://code.google.com/p/yii/issues/详细信息?id=1191了解更多详情。

In Yii 1.1.6 there will be concept of database migrations. This will allow us to do database manipulation in DB-agnostic way using PHP code. See http://code.google.com/p/yii/issues/detail?id=1191 for more details.

樱娆 2024-10-14 12:45:31

基本上:。不是 php 的库存。

但是...协调方案(例如来自 SHOW CREATE; 命令)仍然是执行您正在讨论的操作的可靠方法 - 如果本质上非常重要。如果您要检测和复制模式定义的机制,您必须非常了解模式定义的细节。不过,您可以自由地开发一个专门的字段,该字段跟踪您在更新架构时更新的版本号。然后,至少您可以通过比较该版本字段中的数据来知道其他复制目标何时也需要更新。

我通常看到的实现方式是跟踪所有 ALTER TABLE 命令(等)并跟踪它们。您可以将“r12345.sql”文件之类的文件签入 SVN,以实现自动执行数据库更新的系统。它涉及到,但我的意思是,php 脚本可以检查所有数据库模式 .sql 文件并执行每个文件(串联),这些文件将回放当前数据库的更改。

很大程度上取决于您想要实现的目标。如果您提供更多信息,我会详细说明。

Basically: NO. Not something stock with php.

HOWEVER... Reconciling scheme, such as from a SHOW CREATE <table_name>; command, is still a reliable way to do what you're talking about -- if quite nontrivial in nature. You have to be very aware of the particulars in mechanics of schema definition if you're to detect and replicate that. You are free to develop a specialized field, though, that tracks a version number which you update when updating the schema. Then, at least you'd know when the other replication targets need to be updated as well -- by comparing the data in that version field.

The way I've usually seen this implemented is to track all ALTER TABLE commands (etc) and track them. You could check in something like an 'r12345.sql' file into SVN for a system of automatically executing db updates. It's involved, but what I mean is that a php script can check against all the db schema .sql files and execute each of the ones (in series) that will play back the changes onto the current database.

A lot depends on what you're trying to accomplish. If you provide more info, I'd expound.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文