views:

145

answers:

3

This is a problem that I come to on occasion and have yet to work out an answer that I'm happy with. I'm looking for a build system that works well for building a database - that is running all of the SQL files in the correct database instance as the correct user and in the correct order, and handling dependencies and the like properly.

I have a system that I hacked together using Gnu Make and it works, but it's not especially flexable and frankly can be a bit of a pain to work with in some situations. I've considered looking at things like SCons and CMake too, but I don't know how much better they are likely to be, or if there's a better system out there that already exists...

A: 

For SQL Server, I just use a batch file with SQLCMD.EXE and a bunch of .SQL files. It's not perfect, but it seems to work.

Roger Lipscombe
A: 

For my database, I use Migrator.NET This is a .NET framework which allows you to create classes in where you define your DDL statements. The framework comes with a command-line tool with which you can execute your 'migrations' in the correct order. It also has a msbuild - task, so you can integrate it in a continuous integration build as well.

Frederik Gheysels
+1  A: 

Just a shell script that runs all the create statements and imports in the proper order. You may also find migrations (comes with rails) interesting. It provides a make like infrastructure that let's you maintain a database the structure of which evolves over time.

Say you add a new column to some table. In migrations you'd write a snippet of code which describes the requirements for adding the column and also to rollback the change so you can switch to different versions of your schema automatically.

I'm not a big fan of the tight integration with rails, though, but the principles behind it are very interesting.

I think it's fairer to say that Rails is (somewhat) tightly integrated with ActiveRecord. Not completely, other ORMs are possible, and Rails3/Merb2 will open the space up greatly. ActiveRecord can quite comfortably be used on its own.
Mike Woodhouse
You're absolutely correct. I guess what I meant was that you wouldn't be using it to manage a database schema that has no ruby/active record/rails dependancies otherwise. I'd like to see a "general purpose" migrations like tool. Which sounds a little like what the poster is asking about.
I've been playing with them, and Migrations seem like a really nice clever way of handling this. Can just ignore the rest of the rails stuff that gets bundled with it for now too :)
Graham