Category: Blog

  • Version Control for Databases

    This is based on my Team Based Development with Version Control talk, which has evolved a bit.

    Abstract

    Getting your database under version control is ultimately a way of communicating changes and collaborating with team members, maintaining an audit trail and ensuring you always have a version to roll back to.

    In this session, we’ll cover why this gives you and your team a crucial advantage in reducing the risk in your development processes. We’ll also discuss another door that your team opens by adopting solid version control: setting up the fundamentals of continuous integration. You will learn what build automation means as a first step towards continuous integration and the value it brings as part of your evolving deployment process. We’ll also discuss branching strategies, and how to manage this for databases as part of your evolving deployment process.

    Goals

    • Understand the value of version/source control for databases
    • Learn the tools, standards, patterns and best practices needed to manage a database from source control
    • Identify the necessary flow within a team needed to develop a database with source control

    This talk includes the following demos:

    • Move database DDL into VCS manually
    • Link database DDL and lookup data with SQL Source Control
    • Make development changes and check into VCS
    • Setup a new developer DB linked to VCS
    • Changes flowing back and forth between developers
    • Resolving conflicts between development changes made by two people
    • Basic branching of code for bug fixes and linking a database for development work to an old branch

    Length: 45-75 minutes. Shorter lengths with fewer demos.

    Slides: Get Database Under Source Control.pptx (Slideshare)

  • Making Better Presentations–Practice

    This is part of a series of tips for speakers on how to make your presentations better.

    There’s one thing that makes a big difference for many speakers.

    Practice

    Practice makes perfect, but more importantly, practice develops familiarity. Everyone gets a little nervous on stage, everyone struggled to memorize their entire talk. The best presenters learn to minimize the amount of thinking they need to do on stage, and build a smooth flow of topics.

    It’s important for you to practice your talks so that you become comfortable with the flow and ordering of your slides. I have typically done the following when I build a new presentation

    • Practice sections as I create them – Actually run through the words in my head.
    • Practice the entire talk of slides out loud – I may do this a few times in my office.
    • Record myself giving the talk and watch for the flow – I rarely do this anymore, but I have done it quite a few times when I was beginning speaking. Even now I’ll see recordings of myself at times and see things I want to improve or remove in my style.
    • Run through the talk the night before, often in my head, quickly, but covering each slide and demo.

    Above all, practice with your demos and code. Learn to move around the system easily and smoothly. Being able to select icons, hit shortcuts, select code, etc. makes your presentations smoother, but it’s also handy in your work. Having these tools quickly move in and out of your way make you a more efficient worker.

    The big things I’d tell people to understand is how to switch to and from Powerpoint. Note that you don’t need to stop the presentation to switch. ALT+Tab to your other application and ALT+TAB back to Powerpoint. The presentation itself will be an app separate from Powerpoint. It will take you 30 seconds to figure it out, but practice.

    Practice, practice, practice.

    Remember, amateurs practice until they get it right. Professionals practice until they don’t get it wrong.

  • Testing your API

    I think learning to better test our software, including the database objects, is one of the ways in which we’ll build better software applications in the future. Testing is a complex subject, but this is part of a series that looks at ways in which you can use tSQLt.

    Checking Table Metadata

    One of the easy tests you can write is to compare the meta data of an object to a known quantity. The easy way to do that in tSQLt is to use the AssertResultSetsHaveSameMetaData function. This function compares the structure of two result sets, covering names, ordering, and data types, to determine if they are the same.

    Here’s a quick example of how that’s done.

    Let’s assume I have this table:

     create table Articles  (
        [ArticlesID] [int] identity(1,1) not null,
        [AuthorID] [int] null,
        [Title] [char](142) null,
        [Description] [varchar](max) null,
        [Article] [varchar](max) null,
        [PublishDate] [datetime] null,
        [ModifiedDate] [datetime] null,
        [URL] [char](200) null,
        [Comments] [int] null
      );

    If I wanted to write a test in tSQLt to check this table for changes or alterations, here’s what I’d do in code:

    create procedure Articles.[test Articles_Check_metadata]

    as

    begin

      –Assemble

    create table Articles.Expected

      (

        [ArticlesID] [int] identity(1,1) not null,

        [AuthorID] [int] null,

        [Title] [char](142) null,

        [Description] [varchar](max) null,

        [Article] [varchar](max) null,

        [PublishDate] [datetime] null,

        [ModifiedDate] [datetime] null,

        [URL] [char](200) null,

        [Comments] [int] null

      );

     
      –Act

     
      –Assert

    exec tsqlt.AssertResultSetsHaveSameMetaData

      @expectedCommand = N’select * from Articles.Expected’,

      @actualCommand = N’select * from articles’

      ;

    end

    ;

    go

    Note that I don’t have an ACT section in this test.

    The Assemble section is easy. I record the size and shape of my table. This will be what I compare the actual table to in the database.

    The Assert section is a call to AssertResultSetsHaveSameMetaData, with a SELECT * from the real table being compared to the same SELECT from the expected result table I created. If these match, I pass the test. If they don’t, the test fails.

    Why?

    This seems silly, I know. What does it matter if the table changes, and it certainly will need to change. I definitely questioned the value of a test like this when I first saw the example. However when I thought about it, and thought about the places in which I’ve developed databases, this makes some sense.

    Imagine that I have 3 or 4 (or more) developers. As we get new requirements, we’ll change the schema over time. Imagine that I actually have views built on this table, and other procedures and functions, all of which have some tests on them. If I change this schema, and run a test suite, I could see multiple failures. If I did that, one would hope I realized that the addition of a column here (or a rename) would cause those issues. However if I changed a couple things before running a test, which is something I might do at times, having this test fail tells me quickly that the schema was altered. If someone else changed the schema, I also quickly see that this change was to the schema.

    It’s not a big change, but it does allow me to determine that I need to refactor all the objects (potentially) that depend on this table. I can go do that work now, or add it to the list of tasks for this particular development task, and also fix the tests, which should go quickly.

    If the work doesn’t go quickly because I have a lot of objects, then I’m really glad that I learned now this is an issue.

    This becomes even more valuable with views and procedures returning result sets. If I add a column, then I may or may not want views to change, but certainly a check of view meta data will tell me if they do.

  • A Mini Break

    I’m feeling pressure. As I get this post ready, I feel a bit of a buzz from the stress of prepping a number of different presentations for the next month. Quite a few are new, and that always has me worried.

    I know that’s not good, and I’ve over committed myself a bit. Actually, my employer and I together have over committed me. There’s a lesson in here for next year, and I’ve already spoken to my boss on things we need to watch out for next year.

    However I also need to fit in a few breaks here for my own sanity, and today is one of them. So everyone enjoy have a good day, and remember to take your vacation. That’s a lesson I’m trying to work on today.