开发者

PHP ORM auto-schema-sync

Is there any PHP ORM that can automatically sync my database to schema defined in code?

The pr开发者_运维百科oblem is that I have a lot of machines to deploy code to and no access to command line and no idea when deployment is complete.

Basically, I need to re-sync databases as soon as PHP sees that schema defined in code changed, without any command line or even possibility of manual migration.

Any of ORMs already solved that?


As user716189 said, RedBean is a good solution.

Unlike what 'Slava N' said, you may as well use one to many relationships. RedBeanPHP offers no special functionality to handle foreign key relations, but using foreign key or N:1 associations manually is easy:

$page->book_id = $book->id

And loading a foreign key association is also a no-brainer:

$pages = R::find("page"," book_id = ? ",array($book->id));

Or the other way around:

$book = R::load("book", $page->book_id );

Quoted from: RedBean Relations (and fixed some typos)


try doctrine ORM

http://www.doctrine-project.org/ use symfony it has built in integration to the doctrine its very powerful


RedBean is just what you want: http://www.redbeanphp.com/

It lets you focus on your code during the dev phase by updating your schema on the fly and lets you fine tune your schema before production.


Redbean 2 fully supports n:1 relations it will be released on August 1


Propel PHP ORM has a feature to build models from an existing schema.

However, when syncing schemas, I tend to use http://www.quest.com/toad-for-mysql/

It's really solid.


RedBean comes with a sync-tool called redshoe that can sync any MySQL database for you. You dont need commandline access, it can put the required SQL on the screen for you. Another way is to use the querylogger in RedBean and just log all the modifications and send them to the other servers.


Actually db.php orm (http://dbphp.net) has just one method $database->update() that synchs everything on every sql connection link defined in orm.

You can also rename old tables to new names or old fields to new fields. For example if you had field username and property username and then you renamed your property to login:

/**
* rename username
*/
public $login

This will rename field username to login (in table related to this class).


Yes, I implemented one - An ORM that can automatically sync or diff schema changes with the any database. (multiple data-source is also supported)

You may try LazyRecord https://github.com/c9s/LazyRecord

LazyRecord integrates full featured PHP-based schema and the related migration features.

The most powerful feature is - automatic migration, which is similar to UIKit's lightweight database migration.

This project has been in active development for more than 5 years and has been deployed to many production environments.

here are some screencasts:

PHP ORM auto-schema-sync

You can also manually edit the auto-generated migration script

PHP ORM auto-schema-sync

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜