As far as I understand, if I want to get my database under source control then I need to be checking in change scripts for each change and then running them from some revision to get the correct DB.
I am trying to make a batch file that will be checked in too, that allows other developers on the team to re-build the DB locally without too much trouble. I believe sqlcmd is the way to achieve this. I have it setup to enumerate all files in the dir of .sql files and run sqlcmd for each.
My question is who has done this before and do you have an advice on the best way to achieve this? Is the way I intend to do this the best way or is there a better way?
Hope that’s not too vague.
Thanks in advance,
Martin.
If you are using a ORM tool like NHibernate you save yourself the trouble of having DB change scripts because the ORM can recreate the database from it’s mapping files (that are under source control).
That’s a pretty easy way of having the appropriate db version for every revision.
I also then recreate the whole schema whenever executing tests to make sure I have a consistent state.
I recently blogged about that: http://www.tigraine.at/2008/10/30/sourcecontrol-and-databases-when-orm-comes-in-handy/
I also once had a project that had Sql update scripts, and we just had a little helper tool built (very very basic) that opened the folder, sorted all scripts (we were naming them 1 – foo.sql, 2 – bar.sql) and executed them in order against the DB.
If a developer had a new script he simply added it to the end (34 – bla bla.sql).