Version source control for sql dbs

Hi... curious who's using a source control product like Git, Mercurial, Subversion, etc for their Impresario database?  If you are can you post some experiences (whether good, bad or ugly) about how that's worked for you?

Thanks!

Parents
  • Bumping this -- was going to ask a similar question.

    Generally one should stay away from Subversion these days -- it's effectively obsoleted by DVCSs like Git and Mercurial.

    I recently found out about Bitbucket (from Atlassian), which is a cloud platform for Git and Mercurial repos that is free for small teams, and allows for private repos unlike GitHub. Atlassian also has a git/mercurial GUI client called SourceTree that can help you avoid needing to use the command line. So that's going to be my starting point for this.

    Doing some research it looks like Microsoft now provides a Git plugin for Visual Studio, so perhaps that can be useful for any work done there. (SSRS reports maybe?) SSMS also has the capability to use source control plugins, but the only ones I can find are paid from a 3rd party called Red Gate. They come highly recommended, but are expensive. But in the first place, the only way to version a database is to have SSMS generate scripts for you and then version those -- effectively the blueprint for creating your database and stored procedures in .sql files. So, my plan at the moment for some database customizations/local objects I'm working on are to write my customizations as SQL scripts and check those into version control. (Git vs. Mercurial doesn't really matter at this level unless some plugin requires one or the other.)

    I think the catch is that you have to write your scripts to account for the procedure already existing or not in the database, and object permissions as well. Would be interesting to hear from anyone else doing this on their experiences; I've just been getting started.

  • In case someone comes across this in the future, I just had to figure out an issue I was having with my source control setup -- Git was treating my SQL files as binary files -- unable to do diffs and merges.

    The reason for this is that SSMS, by default (and you can't change this either), saves SQL files with UTF-16 LE encoding, although it just calls it "Unicode" (see also). Git wants UTF-8 or ASCII, that's it.

    There's an easy fix for this -- just use the "Advanced Save Options" in SSMS to specify an ASCII-compatible encoding (Western European - Windows 1252 works fine). You only have to do this once for every .sql file you version control, but it's still kind of annoying.

Reply
  • In case someone comes across this in the future, I just had to figure out an issue I was having with my source control setup -- Git was treating my SQL files as binary files -- unable to do diffs and merges.

    The reason for this is that SSMS, by default (and you can't change this either), saves SQL files with UTF-16 LE encoding, although it just calls it "Unicode" (see also). Git wants UTF-8 or ASCII, that's it.

    There's an easy fix for this -- just use the "Advanced Save Options" in SSMS to specify an ASCII-compatible encoding (Western European - Windows 1252 works fine). You only have to do this once for every .sql file you version control, but it's still kind of annoying.

Children
No Data