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).
来自ruby on rails世界,我正在寻找一种有效的方式来版本化我的数据库(如果是rails,迁移就是为了这个目的)。
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.
附:我正在使用mysql。
2 个解决方案
#1
4
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.
在Yii 1.1.6中,将有数据库迁移的概念。这将允许我们使用PHP代码以数据库无关的方式进行数据库操作。有关详细信息,请参阅http://code.google.com/p/yii/issues/detail?id=1191。
#2
0
Basically: NO. Not something stock with php.
基本上:不。没有库存的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.
但是......协调方案,例如来自SHOW CREATE
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.
我通常看到这种方式实现的方法是跟踪所有ALTER TABLE命令(等)并跟踪它们。您可以将类似'r12345.sql'文件的内容检入SVN,以获取自动执行数据库更新的系统。它涉及到,但我的意思是php脚本可以检查所有db模式.sql文件并执行将回放到当前数据库的每个(串联)文件。
A lot depends on what you're trying to accomplish. If you provide more info, I'd expound.
很大程度上取决于你想要完成的事情。如果你提供更多信息,我会解释。
#1
4
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.
在Yii 1.1.6中,将有数据库迁移的概念。这将允许我们使用PHP代码以数据库无关的方式进行数据库操作。有关详细信息,请参阅http://code.google.com/p/yii/issues/detail?id=1191。
#2
0
Basically: NO. Not something stock with php.
基本上:不。没有库存的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.
但是......协调方案,例如来自SHOW CREATE
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.
我通常看到这种方式实现的方法是跟踪所有ALTER TABLE命令(等)并跟踪它们。您可以将类似'r12345.sql'文件的内容检入SVN,以获取自动执行数据库更新的系统。它涉及到,但我的意思是php脚本可以检查所有db模式.sql文件并执行将回放到当前数据库的每个(串联)文件。
A lot depends on what you're trying to accomplish. If you provide more info, I'd expound.
很大程度上取决于你想要完成的事情。如果你提供更多信息,我会解释。