views:

183

answers:

2

(Make this CW if needed) We are two developers working on a web application based (PHP5, ZF, Doctrine, MySQL5). We are working each with a local webserver and a local database. The database schema is defined in a YAML file.

What's the best way to keep our database schemas in sync?

Here's how we do it: Whenever developer "A" makes a change, he generates a migration class. Then he commits the migration file developer "B" executes the migration class.

But creating a migration class on every db change is a rather tedious process.

Do you have a better solution?

+1  A: 

I don't know how you do in the Zend Framework with Doctrine. Here's how I would do it in Symfony with Propel. Though the exact procedure may vary, but the underlying concept is the same.

I have unit tests on my DAL.

Whenever the schema changes, we check in the yml and the generated ORM code ( You do have a source control, don't you). I set the check-in to auto-mode, meaning I will get all the check-in instantly.

If the schema changes don't affect my thing, then I would just ignore the changes. But if the schema changes break my thing, then I will rebuild my form, ORM classes and whatnot by using symfony propel build command. Rebuilding those infrastructures is just a single command line thing, so there is no problem for me.

Finally, after rebuilding, I will run my unit tests, to make sure everything is OK. If not, I better get them fixed!

Ngu Soon Hui
In your setup, do you have your own local copy of the database? And if yes whenever the schema changes you rebuild your local copy of the database from scratch?
Silvan Mühlemann
Yes, to both question
Ngu Soon Hui
A: 

I see that this question is already answered but Doctrine can migrate your databases for you without having to blow away the whole thing. We use this for every schema change where one developer changes his/her local yaml file, generates new models locally, creates a migration using Doctrine, runs that migration locally to change the db, then checks in both the new yaml file and the migration. Then other developers check out the changed yaml file and migration, then they generate new models and run the migration to sync their db. Deploying the code to our QA and production environments is pretty much the same process.

More information on Doctrine migrations can be found on the Doctrine site.

Chris Williams