How do you deal with source control management and automated deployment (configuration management) of database tables. I work in a SQL Server environment and it’s pretty easy to script out drop and create files for stored procedures/triggers/functions even jobs. It’s also easy to handle scripting out the creation of a new db table. However, if at a later point you want to modify that table, you can’t necessarily just drop it and recreate it with the new field for fear of losing data. Is there an automated way to deal with this problem? Do you script out a temp table and backfill after updating the new changed table? (could be rough if there is a lot of data)
Any suggestions would be greatly appreciated.
You can automatically create the initial creation script, but ALTER scripts really need to be hand-coded on a case-by-case basis, because in practice you need to do custom stuff in them.
In any case, you’ll need some way of creating apply and rollback scripts for each change, and have an installer script which runs them (and a rollback which rolls them back of course). Such an installer should probably remember what version the schema is in, and run all the necessary migrations, in the right order.
See my article here:
http://marksverbiage.blogspot.com/2008/07/versioning-your-schema.html