开发者

What's the best way to keep database versioning with the yii php framework?

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 an开发者_运维百科d 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜