views:

314

answers:

11

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.

A: 

you can't really put a large database under source control, so your DBA is right.

what you can do practically is to put your schema under source control, and maybe a few smallish 'configuration' tables.

Omry
I meant the schema... Sorry I will clarify.
JohannesH
It is possible as long as everything is in script format, but large files are slowing down the performance, but my guess and recommendation is that we are only talking about schema script as you pointed out.
Hakan Winther
+1  A: 

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.

Ash M
I think we agree... You would think that my dear DBA should be jumping at a tool like VS DB edition. But he's not.
JohannesH
+1  A: 

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.

Thanks for the link, It'll be forwarded promptly. We do have a license to VS DB Edition but the main problem is convincing my DBA that he should use it. ;) He's *really* old school. I mean, we have been using DB Ghost and other DB change management solutions with other projects and other DBAs, but this one DBA is persistant about making modifications directly to each environment.
JohannesH
In that case, if he's *good* at doing it his way, and I'll assume that he is, otherwise he could be forced to change. The main feature that DB edition, or any source control has is that it can be updated by any number of people and they changes will be *automatically* merged. Obviously, someone needs to wtach the merge, but it means that it won't miss changes the way that a manual merge would. If there are many people touching the database, stuff happens. ***bad*** stuff. So, DB source control allows multiple people to work on the same database without *touching* it.
Unfortunately he isn't very good at handling it his way. If he was he wouldn't lose his work. ;) And even worse it isn't the first time his development "process" has caused problems. My problem is that I have no power over the guy so all I can do is present him with pursuading evidence that he should change his wicked ways.
JohannesH
Well, the first part is convincing him that switching will be easy. If he feels that switching will make his job harder, then it could *in fact* be worse to switch. Now of course, using version control is easier, so you're fighting against perception. Start there. Then convince him that it is worth switching to *some* version control. If you can then do some requirements gathering on what he feels are the deficiencies in his own process, then you might be able to find a product that fixes the things that he admits need fixing. Then you can wean him onto all the other useful functions.
Sounds like a plan. Thanks. ;)
JohannesH
A: 

One way to source control database is to store the data in and about the database separately

  1. You can have the all the tables, procedures and function scripts as SQL files and add them to source control.

  2. Export the database data as insert statements into SQL files, each with a fixed size. This is a cumbersome process as it would involve a lot of files that are to be tracked and controlled.

  3. I am not sure if the VSS/SVN are able to read and keep history of changes to dump files created by the database backup options.

Ravi Atluri
+4  A: 

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...

Yuval F
Thanks, I will do my very best.
JohannesH
A: 

Its not clear from you question if you want to protect the data in the Db or the schemas in the Db. If the latter then you could identify all the important schemas and run an cron job that pulls the schema definitions from the Db and inserts them automatically into a source control system (perhaps even via triggers on the schemas??).

But this still just amounts to backing the system up more often. For what you envision you would need source control integrated with the Db tools and I don't know of any product that does that.

(and I shudder to think of VSS integrated into SQL management studio :-(( )

Peter M
I've clarified the question so it more clear that I'm talking about the schema. However, products like DB Ghost and VS DB edition does a great job of extracting schema scripts and generating change scripts between schema versions.
JohannesH
@Johannes As per my comment to the main question after your clarification, the technology is not broken, your DBA is!
Peter M
+1  A: 

Source control for databases can be quite contentious. It's different to use source control for something that produces a binary because you can't lock the source: a stored proc is a row in a table and there is not single table to read to get a table definition.

Also, version to version is mostly a set of ALTER statements. You script out CREATEs and add them to source control. This makes it harder to use in cases like this.

To me, this is more a procedural error.

Why was the change not done from a script? Forget where the script lives, but why no reproducable and re-runnable script? Perhaps linked to the change tracking number? If the database is reset (loaded from prod) then how would the change have been re-applied to prepare for production. And other questions.

I believe in source control and we use it: but it has limits for database work.

gbn
Its true that you script out "create" statements. But is this a problem? I mean, as far as I can understand these create scripts are used to create an empty database. You then do a diff between the empty database (of a specific version) against the target db that you want to update. This diff will result in a up-/down-grade script that you can run on the target server. Is this a misunderstanding on my part? I f not, then I don't see the problem in this deployment process. Please elaborate.
JohannesH
We work against a copy of production rather than an empty build: we want to ensure code works against realistic data
gbn
...and it's more a people/process issue for you i think
gbn
+1  A: 

First you are approaching this incorrectly. If the dba won't bite on Source Control and he is making errors that affect the system, the person you need to persuade is his boss.

If it helps, I'm from the old school too and I love having our database objects in source control. How nice to be able to revert one table without having to restore the whole database backup to a different location and then move the table. How much faster and simpler. How nice to be able to compare two different versions and see what changed. How nice to deploy a change and know exactly which database changes (say, for instance only twelve of the 23 possible ones) go with the part you are deploying and not some other unfinished project. How nice to know exactly which scripts were involved in a particular change you had to rollback. How nice that nobody is making on-the-fly changes on production since we now require all production changes to be from source control scripts. There are so many fewer errors and issues to worry about.

Yes it was a change in how we did business, but we did it through a policy change from on high so three was no argument and the dbas went through a couple of times and reverted any objects different from source control to the source control version, so now nobody will even think of doing a database change without it being in source control.

HLGEM
+1  A: 

It is possible to put your database under version control, you can use a tool called Randolph for sql version control (data & schema).

From the product's site :

...It shifts the responsibility for versioning from the users to the software. Its light-weight, easy to use tool that runs in the background and keeps track of all your databases schema and data changes over time, and enables full review of databases' history, and full rollback to any point in time, as well as optionally push changes into existing systems (Subversion, SourceSafe or Team Foundation Server)

(Its been on the market for more than 5 years now)

Itamar
Thanks for the answer.
JohannesH
A: 

My answer to this same problem was to export all DB objects to text form (more than 136,000 of them) and then create the SourceSafe projects to hold them. Any New or changed objects in the DB now go to the SourceSafe structure, while unchanged are left alone.

Dave
+1  A: 

As the product manager for SQL Compare I've spoken to many 'traditional' DBAs who are uncomfortable with third party tools mainly because they have a system that works for them and sometimes changing can be difficult. There are many situations where I am convinced that they would benefit from our tools if only they gave them a chance. Frustrating.

One thing you might consider trying is Red Gate's upcoming tool, SQL Source Control. This is designed to build source control into SSMS, in other words it doesn't require DBAs to leave the comfort zone of their management environment. The bad news is that the tool hasn't been released yet. The good news is that we have an Early Access Program. Please visit the following link to find out more about the tool:

http://www.red-gate.com/Products/SQL_Source_Control/index.htm

David Atkinson
Just to announce that this has now been released and is available to evaluate and purchase. http://www.red-gate.com/products/SQL_Source_Control/index.htm
David Atkinson