Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

managing Sql Server databases version control in large teams

For the last few years I was the only developer that handled the databases we created for our web projects. That meant that I got full control of version management. I can't keep up with doing all the database work anymore and I want to bring some other developers into the cycle.

We use Tortoise SVN and store all repositories on a dedicated server in-house. Some clients require us not to have their real data on our office servers so we only keep scripts that can generate the structure of their database along with scripts to create useful fake data. Other times our clients want us to have their most up to date information on our development machines.

So what workflow do larger development teams use to handle version management and sharing of databases. Most developers prefer to deploy the database to an instance of Sql Server on their development machine. Should we

  1. Keep the scripts for each database in SVN and make developers export new scripts if they make even minor changes
  2. Detach databases after changes have been made and commit MDF file to SVN
  3. Put all development copies on a server on the in-house network and force developers to connect via remote desktop to make modifications
  4. Some other option I haven't thought of
like image 780
Justin C Avatar asked Dec 22 '22 05:12

Justin C


1 Answers

Never have an MDF file in the development source tree. MDFs are a result of deploying an application, not part of the application sources. Thinking at the database in terms of development source is a short-cut to hell.

All the development deliverables should be scripts that deploy or upgrade the database. Any change, no matter how small, takes the form of a script. Some recommend using diff tools, but I think they are a rat hole. I champion version the database metadata and having scripts to upgrade from version N to version N+1. At deployment the application can check the current deployed version, and it then runs all the upgrade scripts that bring the version to current. There is no script to deploy straight the current version, a new deployment deploys first v0 of the database, it then goes through all version upgrades, including dropping object that are no longer used. While this may sound a bit extreme, this is exactly how SQL Server itself keeps track of the various changes occurring in the database between releases.

As simple text scripts, all the database upgrade scripts are stored in version control just like any other sources, with tracking of changes, diff-ing and check-in reviews.

For a more detailed discussion and some examples, see Version Control and your Database.

like image 101
Remus Rusanu Avatar answered Dec 28 '22 23:12

Remus Rusanu