views:

255

answers:

6

Hey guys -

here's a more general question on how you handle database schema changes in a development team.

We are a team of developers and the databases used during development are running locally on everyone's box as we want to avoid the requirement to have web access all the time. So running a single central database instance somewhere is not a real option.

Whenever one of us decides that it is time to extend/change the db schema, we mail database files (MYI/MYD) or SQL files to execute around, or give others instructions on the phone what they need to do to get the changed code running on their local DBs. That's not the perfect approach for sure. The same problem arises when we need to adjust the DB schema on staging or production once a new release is ready.

I was wondering ... how do you guys handle this kind of stuff? For source code, we use SVN.

Really appreciate your input!

Thanks, Michael

+2  A: 

At the very least you should have the scripts of all the objects in the database (tables, stored procedures, etc) under source control.

I don't think mailing schema changes is a real option for a professional development team.

santiiiii
+1  A: 

We had a system on one of my previous teams that was the best I've encountered for dealing with this situation.

The nightly build of the application included a build of a database (SQL Server). The database got built to the Test DB server. Each developer then had a DTS package (this was a while ago, and I'm sure they upgraded to SSIS packages) to pull down that nightly DB build to their local DB environment.

This kept the master copy in one location and put the onus on the developers to keep their local dev databases fresh.

Justin Niessner
+7  A: 

One approach we've used in the past is to script the entire DDL for the database, along with any test/setup data needed. Store that in SVN, then when there's a change, any developer can pull down the changes, drop the database, and rebuild it from the script files.

Harper Shelby
DaveE
We do that as well (though we use TFS instead of SVN). I love storing the scripts in version control though, because now you can track the history of the changes! Nothings nicer than associating a branch or a label with a particular set of DB scripts.
Joshua
A: 

At my work, we deal with pretty large databases that are time-consuming to generate, so for us, starting from scratch with a new DB isn't ideal. Like Harper, we have our DDL in SVN. Additionally, we store a version number in a database table. Every check-in that changes the DB must be accompanied by a script that:

  1. Will upgrade the database schema and modify any existing data appropriately, and
  2. Will update the version number in the database.

Further, we number the scripts and database versions such that a script we've written knows how to upgrade further along a branch or from an older branch to a newer one without any input from the developer (apart from the database name and the directory to the upgrade scripts).

Thus, if I've got a copy of a customer's 4GB DB that's from a year old version and I want to test how their data will work with the version we cut yesterday, I can just run our script and let it handle the upgrades rather than having to start from scratch and redo every INSERT, UPDATE and DELETE performed since the database was created.

Robert Gowland
A: 

We have a non-SQL description of the database schema. When the application starts, it compares the desired database schema with the actual database schema, and performs whatever ADD TABLE, ADD COLUMN, ADD INDEX, etc. statements it needs to do to get the database to look right.

This doesn't handle every case; sometimes you have to delete the database and recreate if if you've changed something that the schema resolver can't handle, but most of the time we don't need to worry about it.

Kristopher Johnson
A: 

I'd certainly keep the database schema in source code control.

At my present job, every time there's a schema change, we write the SQL for the change (alter table xyz add column ...) and put it in SVN. Then developers can update test databases by running this script. It's pretty clumsy but it works.

At a previous job I wrote some code that at application start-up would automatically compare the actual database schema to what it expected, and if it was not up to date perform the updates. Mostly this was done for deployment reasons: When we shipped new copies of the software, it would then automatically update the user's database. But it was also handy for developers.

I think there should be some generic SQL tool to do this. Maybe there is, but I've never seen one.

Jay