Managing My Database in Source Control

As I am working with a new database project (within VS2008), and as I have never developed a database from scratch, I immediately began looking into how to manage a database within source control (in this case, Subversion).

I found some information on SO, including this post: Keeping development databases in multiple environments in sync. One of the answers in particular pointed to a number of a links, all of which had good, useful information.

  • .NET projects build automation with NAnt/MSBuild + SVN
  • It's possible that Team Foundation Server Version Control support external repo like git
  • Sharing code between two different git projects
  • VS 2015 RC: Git integration crashed
  • How to handle SQL Server CE in source control?
  • Remote agents vs local agents for continous integration and deployment
  • I was reading a series of posts by K. Scott Allen which describe how he manages database change. From my reading (and please pardon the noobishness of my question), it seems as though the database itself is never checked into a repository. Rather, scripts that can build the database, along with test data (which is also populated from scripts) is checked into the repository. Ultimately, this means that, when a developer is testing his or her app, these scripts, which are part of the build process, are run. This ensures that the database is up-to-date, but is also run locally from every developer’s machine.

    This makes sense to me (if I am indeed reading that correctly). However, if I am missing something, I would appreciate correction or additional guidance. In addition, another question I wanted to ask – does this also mean that I should NOT check in the mdf or ldf files that are created from Visual Studio?

    Thanks for any help and additional insight. Always appreciated.

  • Mercurial hooks: how to find the current directory on commit
  • Using git to track only some of a Unity project
  • What's the right way to branch with Visual Source Safe?
  • How can I explain source control (Mercurial/Tortoise specifically) to a non-programmer?
  • Automatically stashing
  • Source Forge repo gives “denying non-fast-forward refs/heads/master” error
  • 5 Solutions collect form web for “Managing My Database in Source Control”

    That is correct you should check in scripts not the database file itself.

    I’m not a fan of building from test data unless the data itself will mimic the size of data that production has (or in,the case of new databases, is intended to have) . Why? because writing code against a table with 100 records doesn’t tell you if it will run in a timely fashion when you have 10,000,000 records. I’ve way too many bad design choices made from people who think a small data set is OK for development.

    Here, we do not allow devs to have a separate database on their box (which typically limits the size the database can be by virture of not being a server attached to SAN), instead they must work against the dev database which is periodically refreshed from prod (and then all the new dev scripts run) to keep the data the right size. I think it is important that your dev datbase environment match prod as closely as possible including equipment configuration, size of the database etc. Nothing more frustrating than spending a long time developng something that either won’t work at all on prod or has to be taken down immediately because it is slowing the system too much.

    Jumping down off my soapbox now.

    It is great idea to check in scripts, since source code control is best suited to working with text files, rather than binary files. Differences in the script files can be easily reviewed as part of the rest of your code changes related to the database change. In addition to checking in the database scripts, we also check in a database schema snapshot. This database schema snapshot allows us to verify that the schema in production matches the expected schema for given version of the product. Besides that, the database schema snapshot is a handy way for searching for columns and tables using a plain text editor.

    I use DataConstructor but am biased because I wrote it.

    Try SQL Examiner:
    How to keep your database under version control

    You could use a tool like Liquibase to manage the database scripts. It is really a database upgrade framework, so it will keep track of the steps that have executed already, so when you want to upgrade production, for example, it only executes the new steps.

    Git Baby is a git and github fan, let's start git clone.