THE SQL Server Blog Spot on the Web

Welcome to SQLblog.com - The SQL Server blog spot on the web Sign in | |
in Search

SSIS Junkie

This is the blog of Jamie Thomson, a freelance SQL Server developer in London

Deployment of client-specific database code using SSDT

Yesterday I attended SQL Saturday 194 in Exeter for which many people deserve credit but especially the organisers Jonathan Allen & Annette Allen and the sponsors Fusion-IO, Confio Software, Nexus, Big Bang Data Company, Purple Frog Systems, Redgate, idera, Pluralsight, Jurys Inn Exeter & Wrox.

image image

 


I gave a talk entitled Declarative Database Development with SSDT; both during the session and then afterwards on Twitter Leo Pasta asked me

 

image

would you have any extra references on how to handle client-specific changes to the DB schema

I promised Leo an answer, hence this blog post.

If I understand Leo’s question correctly he has an application that is used by multiple clients, he has a separate instance of the application for every client, and the database requires client-specific customisations; luckily for Leo there is a new feature in SSDT that is perfect for this situation. First let’s set up our solution in SSDT:

image

We have three database projects:

  • _core - This contains all the objects that are common to all clients. For demonstration purposes it simply contains a table called [Sales]
  • clientFoo – All the objects that are required only by client “Foo”. In this case there is view which aggregates the data in [Sales] by Customer
    • clientBar – All the objects that are required only by client “Bar”. In this case there is view which aggregates the data in [Sales] by Location

    In order that the reference to table [Sales] in the two views can be resolved both of the client-specific projects have a database reference to _core:

    image

    It is those database references that allows objects in clientFoo/clientBar to refer to objects in _core. Now here’s the important bit. When we set up those two database references we must specify that the objects in the referenced project are intended to be in the same database:

    SNAGHTMLa9aab43

    Having objects from one database split over multiple projects is called composite projects. The effect of this is that (by default) whenever clientFoo or clientBar are deployed the objects in _core will get deployed as well. We can see this in the output when we deploy clientFoo:

    image

    Notice how even though we chose not to deploy _core two objects have been created; table [Sales] (from the _core project) and view [vSalesPerCustomer]. This is the new feature in SSDT that I spoke of above – a deployment of a project will (by default) also deploy all the objects in referenced projects where objects in the referenced database are intended to be in the same database (incidentally this functionality replaces the “partial projects” feature from previous incarnations of SSDT).

    Note that you can change this default behaviour in the advanced publish settings by unchecking the “Include composite objects” box:

    SNAGHTMLaac90d1

    Hence, with the “Include Composite Objects” setting turned on, we can deploy both projects clientFoo & clientBar and both will contain table [Sales] plus their own client-specific view:

    image

    which (I hope) is exactly what Leo was after!

    That’s all there is to it. A very very nice new feature of SSDT!

    @Jamiet

    Published Sunday, March 10, 2013 3:24 PM by jamiet

    Comment Notification

    If you would like to receive an email when updates are made to this post, please register here

    Subscribe to this post's comments using RSS

    Comments

     

    LeoPasta said:

    Great explanation, nice to see that it have been implemented in an intuitive way (which was something I couldn't say a lot for the first versions of the "Data Dude"). :-)

    One additional question, how would it handle different indexes/contraints between clients? E.g. ClientFoo requirements say that a client should have one order per day and we want to implement this as a Unique constraint on Sales. Would we have to take the whole Sales table out of _core and have a different definition for each client?

    March 10, 2013 1:30 PM
     

    jamiet said:

    Hi Leo,

    Exactly the same applies in regard to indexes. They're still database objects, exactly the as views are, so you can still have an index per client. SSDT doesn't stipulate that you have to put an index or constraint definition in the same file as the table that it is defined upon.

    regards

    Jamie

    March 10, 2013 2:59 PM
     

    bruce said:

    Nice feature indeed! Does SSDT also support client-specific changes for SSIS packages or SSAS cubes? That would be icing on the cake!

    March 10, 2013 3:02 PM
     

    jamiet said:

    Bruce,

    No, unfortunately not :(

    I have brought this up privately to the SSIS team, I think maybe I need to make the request more public. To Connect I go!

    Jamie

    March 10, 2013 4:39 PM
     

    jamiet said:

    March 10, 2013 4:53 PM
     

    bruce said:

    Nice write-up on connect. It's exactly the situation we are in and you described it well. By the way, the connect item is picking up some steam.

    March 12, 2013 5:42 PM

    Leave a Comment

    (required) 
    (required) 
    Submit

    This Blog

    Syndication

    Powered by Community Server (Commercial Edition), by Telligent Systems
      Privacy Statement