Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you put an large existing database (schema) under source control?

My DBA just lost some development work that he did on our development database. Poor fella. So naturally our manager asked him, at our status meeting, how this could happen and how we could avoid this happening in the future. "Source control could alleviate the problem" I suggested... The dba's response; "No, we just backup the server more often". Now I would like to help my DBA understand what source control is and how it fits together with a database schema and development on that schema.

Previously I've tried to explain him that there's nothing special about the source code behind tables and stored procedures and it should be in a source control system (TFS in this case). But he just didn't bite. Now, while this misap is in recent memory, I would like to take another stab at it.

So my question is, do you know of any good advice I could pass on to my DBA and maybe even a couple of resources explaining how you would go about migrating a DB schema to be under source control and find its proper place in the build and deployment processes?

A couple of facts about the environment:

  • Source Control on a TFS 2008 Server.
  • Database is a MS SQL server 2008 with >300 tables and >300 other objects (sprocs, triggers, functions etc.).

Clarification: We have been using DB Ghost and other change management solutions on other projects with other DBAs, in the past. We even have the license for VS DB edition! The problem is getting the DBA to even think about this way of developing for the database. He's really old school (i.e. migrating changes manually from environment to environment), and unfortunately hes the only one who knows anything about this particular DB.

like image 927
JohannesH Avatar asked Aug 31 '09 11:08

JohannesH


3 Answers

See how to version control sql server databases and Do you source control your databases, among many others. Or use the search page. Basically, your approach seems correct. Good luck persuading the DBA...

like image 130
Yuval F Avatar answered Sep 30 '22 07:09

Yuval F


If you are using Visual Studio Team System, I recommend having a stab at their Database Edition (i think these days it comes with the Developer Edition if you are an MSDN Subscriber). What this will allow you to do is to script out all your schema, stored procs, views, triggers, etc and source control these. This should also make the dba more comfortable since he will be working with a "Database" version of the tool rather than the "Developer" version (naming can go a great lengths with people). As you make changes from Visual Studio, you can manage script changes as you work, and source control them.

like image 31
Ash M Avatar answered Sep 30 '22 09:09

Ash M


If your company has an MSDN license, they can use the Visual Studio Database edition. There's a video tutorial of it here.

I have no power of purchase, so I don't know what the cost breakdowns are. But it has the capability of source controlling all the parts of a DB schema, and includes creating change-scripts as well as auto-deploying straight from VS if you want (I wouldn't recommend that).

In general though, it's pretty solid as a database source control option.

like image 31
DevinB Avatar answered Sep 30 '22 08:09

DevinB