views:

106

answers:

3

We have a php/mysql based application which has slightly different instances for a number of customers. Also we have more than one developer working on the code base.

What is a good way to manage changes to the database schema in this scenario? Should we require developers to write a small script when a DB change is needed? I'm thinking maybe we could incorporate a check in our code which runs update scripts if it finds new ones so that when you do an svn update and then browse to the site, it will run the scripts and update the db schema.

Are there standard libraries in PHP that do this and can be bolted on without having to adopt an entire framework>

A: 

My recommendation would be your approach. You can have each DB update script contain both an upgrade and a downgrade method for easy updates and rollbacks. If adopting an ORM like Doctrine (http://www.doctrine-project.org/) is not an option then I would suggest taking a look at their implementation of "Migrations" for good examples and best practices: http://www.doctrine-project.org/documentation/manual/1_2/en/migrations.

Cryo
+1  A: 

You might want to learn how to use source control branching.

You can keep your uncustomized version of your application in a main branch, and from it create a branch for each customer who needs their own special modifications.

When a new feature or a bugfix is developed in the main branch, you can merge those changes to each branch you want.

You can track changes in this way to both PHP code and database schema files.

Bill Karwin
A: 

I would use / write something like the Akelos framework uses, take a look at this screencast (near minute 4) for a simple example.

Alix Axel