7

Our IT shop is first starting to build a group of DBA's. All of us (myself included) have come over from the application development/architecture world, so the DBA world is still fairly new to us.

Along with building a DBA group, we are looking to build change manage procedures and processes (hopefully based on best practices) for when we need to move changes.

I've found the following post which is helpful for mostly trigger, stored procedure, and/or DDL changes. But it doesn't necessarily address indexes or vendor databases.

We have a mix of both our own and vendor databases. In our case some of the vendors (though not all) are working with our company to build the database(s) and applications. We are in the process of performance testing our applications now before they "go live". Thus we are analyzing indexes (or the lack thereof) pretty heavily.

As we come across indexes that we feel should be made, how do we best deal with change management with regard to these, both for our own databases as well as for any vendors?

What do you do in your shop? I'm worried less about tools then about the process.

EDIT: So far, I'm appreciating the feedback, comments, and answers for this question. I have noticed that some of the answers are a bit tool specific. I'm looking for more "agnostic" practices, if that can be had.

However if agnostic is not possible, then for tool sets, we use IBM DB2 LUW (and that actually on AIX) mostly. We have some DB2 on Windows and DB2 for i (IBM's i5/OS), but we are mostly AIX DB2. We do use source control, specifically Subversion.

Again, looking for general best practices, but above is what we use that would be vendor specific.

EDIT: Current Decision: We intend to track our reasoning as well as our changes. So we are going to open an issue in our issue-tracking software (which in our case is JIRA). Now we can add in documentation as to what priority the change has, data that backs up what the change should be, the change, and the results of the change from another environment where the change was tested.

We then also intend to keep track of our changes in scripts in SVN (much like was suggested below). This way we can track what version of what exists where. This can be recorded in our JIRA issue (and in any other auditing software we use, ie. pasted links). We can know with more certainty what change went to what environment and why. We can then also track if the index was something we added beyond the vendors implementation or ahead of their implementation, etc.)

4
  • 1
    Google Accidental dba and you will find there is a wealth of information for people like you who suddenly got thrown into being a dba.
    – HLGEM
    Mar 2, 2012 at 19:11
  • @HLGEM -- I'll take you up on that. Although I wasn't thrown into it. I actually chose to switch worlds. Always was fascinated with the database world. Our company had an opening and I saw that as an opportunity and I took it. Mar 2, 2012 at 20:55
  • 1
    @ChrisAldrich Welcome to the dark side. Feel free to chew the fat with your fellow database folk on the heap. Mar 3, 2012 at 1:43
  • 1
    @MarkStorey-Smith - And here I finally thought I saw the light! ;) Of course, the dark side is stronger.... Mar 5, 2012 at 13:48

3 Answers 3

11

I would strongly recommend that you treat your database basically the same way as you treat your application code. You can script your database out to it's component parts and check those into source control and then use the same labels & versions there that you use for your apps.

To get the objects into source control there are a number of tools you can use. Microsoft has a tool that is nicknamed Data Dude. It works with Visual Studio. They're also preparing to release a new tool called SQL Server Database Tools (SSDT), again, working with Visual Studio. My company, Red Gate Software, makes a tool that works with SSMS called SQL Source Control.

In terms of process, I wrote several chapters for the book Red Gate Guide to Team Development. It's available as a free download (or if you want to kill a tree you can purcahse one from Amazon). I go into a lot more details about working with databases in development teams there.

5
  • "use the same labels & versions there that you use for your apps." You may have implied this, but one additional thought is I've seen index versions change more frequently than app versions. so I'd version control even index revisions regardless of the app code version they were initially deployed with. Mar 2, 2012 at 16:53
  • 2
    And do not allow any one ever to promote a change to Prod without a source Controlled script. Never under any circumstances make a table or toher opbject chanage using te GUI, all changes must be by script.
    – HLGEM
    Mar 2, 2012 at 19:05
  • +1 For giving the competition first. Also, I really like SQL Source Control.
    – user4742
    Mar 2, 2012 at 19:55
  • While scripting out your database objects, don't forget to script out (sp_help_revlogin) Windows and SQL logins, and your SQL Agent jobs if for some reason you have to rebuild a database server completely.
    – jl01
    Mar 2, 2012 at 22:28
  • 1
    @EricHiggins Yes, if there are database changes independent of the code changes, you can deploy them, no argument. You should still be versioning and deploying them in conjunction with the app code, using the app's published methods (whatever they might be) for patches & hotfixes. You can still coordinate and lable the deployments so that you know what's deployed and what isn't. Mar 5, 2012 at 13:42
3
  1. We maintain database scripts as part of our application codebase which is maintained under version control. However we use different "processes" for development and production code

  2. Development we maintain the following scripts:

    • base.sql - creates the schema tables and sample data
    • stagingchanges.sql - makes changes to the base.sql for staging environment, mainly email addresses, paths and other assets which might change
    • prodchanges.sql - makes changes to the base.sql for a production deployment. For new projects we usually get to test these out in actual production environments
  3. Maintenance

    • base.sql - a sanitized version of the production database
    • stagingchanges.sql and prodchanges.sql - as above
    • changerequest.sql (usually has the id of the change request) which applies any schema changes for the current change request we are working on
    • changerequest-rollback.sql - reverses the changes made for the change request and resets the database back to production
    • archive (folder) for previous change request scripts

So in maintenance mode all we need to do is apply the changerequest.sql script during deployment to production

4
  • How do you track changes to a base object (e.g. table, procedure or index) using this methodology? I may be missing something from your description of the process but it looks like your versioning the change script, not the artefact that's subject to a change. Mar 2, 2012 at 17:43
  • Our needs call for versioning of the change scripts from base.sql (which is the current production version). If you require more fine grained control, instead of our single base.sql you can dump the definitions of the tables, procedures, and functions into individual files and track the changes in the files. In this case, you will always be able to track the changes at a more granular level. However you will only be able to track the the production versions, since the change script is work in progress until deployed to production. Mar 2, 2012 at 17:59
  • I've always stored per artefact definitions, each in an individual file. If I want to see a production version, I pull the label or branch that's currently in production. If I want to see the UAT version, I pull the label or branch that's in UAT. If I want a change script to go from version X to version Y, I run a differential on the two labels or branches. I don't see how your process would be preferable to this. Not intending to be confrontational, just wondering how you've arrived at this process. Mar 2, 2012 at 18:17
  • We have not yet had the need to separate the scripts into per artifact scripts, especially during development, so we have stayed with it. The artifact per file is the next step in our teams evolution, but is currently overkill for our needs. Mar 2, 2012 at 18:28
1

Being in the database version control space for 5 years (as director of product management at DBmaestro) and having worked as a DBA for over two decades, I can tell you the simple fact that you cannot treat the database objects as you treat your Java, C# or other files.

There are many reasons and I'll name a few:

  • Files are stored locally on the developer’s PC and the change s/he
    makes do not affect other developers. Likewise, the developer is not affected by changes made by her colleague. In database this is
    (usually) not the case and developers share the same database
    environment, so any change that were committed to the database affect others.
  • Publishing code changes is done using the Check-In / Submit Changes / etc. (depending on which source control tool you use). At that point, the code from the local directory of the developer is inserted
    into the source control repository. Developer who wants to get the
    latest code need to request it from the source control tool. In
    database the change already exists and impacts other data even if it was not checked-in into the repository.
  • During the file check-in, the source control tool performs a conflict check to see if the same file was modified and checked-in by another developer during the time you modified your local copy. Again there is no check for this in the database. If you alter a procedure from your local PC and at the same time I modify the same procedure with code form my local PC then we override each other’s changes.
  • The build process of code is done by getting the label / latest version of the code to an empty directory and then perform a build – compile. The output are binaries in which we copy & replace the existing. We don't care what was before. In database we cannot recreate the database as we need to maintain the data! Also the deployment executes SQL scripts which were generated in the build process.
  • When executing the SQL scripts (with the DDL, DCL, DML (for static content) commands) you assume the current structure of the environment match the structure when you create the scripts. If not, then your scripts can fail as you are trying to add new column which already exists.
  • Treating SQL scripts as code and manually generating them will cause syntax errors, database dependencies errors, scripts that are not reusable which complicate the task of developing, maintaining, testing those scripts. In addition, those scripts may run on an environment which is different from the one you though it would run on.
  • Sometimes the script in the version control repository does not match the structure of the object that was tested and then errors will happen in production!

There are many more, but I think you got the picture.

What I found that works is the following:

  1. Use an enforced version control system that enforces check-out/check-in operations on the database objects. This will make sure the version control repository matches the code that was checked-in as it reads the metadata of the object in the check-in operation and not as a separated step done manually
  2. Use an impact analysis that utilize baselines as part of the comparison to identify conflicts and identify if a change (when comparing the object's structure between the source control repository and the database) is a real change that origin from development or a change that was origin from a different path and then it should be skipped, such as different branch or an emergency fix.

An article I wrote on this was published here, you are welcome to read it.

1
  • There's good content in your answer, but I won't be looking into your products any further now that I know I have to subscribe to your spam just to get basic info about it, like looking at the documentation.
    – Brad Mace
    Mar 7, 2016 at 17:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.