SchemaSmith Enterprise Documentation

Define Your Product

A product defines the entry point for updating your server.

Product JSON

Overview

A product is the entry point for describing if the server you are targeting is valid to apply against. It also allows you to define the order in which each template should be updated.

An example from the test product .


{
    "Name": "ValidProduct",
    "ValidationScript": "SELECT CAST(CASE WHEN EXISTS(SELECT * FROM master.dbo.sysdatabases WHERE [name] = '{{MainDB}}') THEN 1 ELSE 0 END AS BIT)",
    "TemplateOrder": [
        "Main",
        "Secondary",
        "Bogus"
     ],
     "ScriptFolders": [
        {
            "FolderPath" : "Jobs",
            "QuenchSlot" : "After",
            "ServerToQuench" : "Both"
        }
    ],
    "ScriptTokens": {
        "SecondaryDB": "TestSecondary",
        "MainDB": "TestMain",
        "ReleaseVersion": "1.0.1.14",
        "TestQueryToken": "<*Query*>SELECT STRING_AGG([Name], ',') FROM master.dbo.sysdatabases WHERE [name] = '{{MainDB}}'"
    }
}
                            

Properties

Setting Value
NameThis is used for tracking whether Migration Scripts have been run or not and also which product owns a given table.
ValidationScriptThis prevents a user from accidentally applying a product against the wrong server. It can be any sql that defines what makes up your product as long as the result is a scalar true or false result (BIT).
TemplateOrderDefines the order of template processing. The tool will ignore any template not named in this list.
ScriptTokensYou can define as many script tokens as you require. In the example above, you can see the MainDB script token is being used in the ValidationScript to find the database named TestMain.
DropUnknownIndexesDefaults to false. Any indexes not defined on a table are not dropped unless they have to be because of a structure change requiring it.
VersionStampScriptThis script is run last when updating a database of this type. Whatever is in this script block will be executed as a non-query (ie, like an insert/update script).
BaselineValidationScriptOptional script to ensure that the current state of the database being updated is the expected version. It can be any sql needed to validate the version as long as the result is a scalar true or false result (BIT). This can help prevent accidentally applying an old version and creating an outage.
ScriptFoldersThe configurable folder list for the product level script folders. See Configurable Script Folders.
BranchNameFileThe location of a file to find the branch name for your source control system. By default, we expect the standard location for a git repository.
BeforeBranchNameMaskThe string to be stripped from the front of the branch file content before the branch name. By default, we expect a git branch file format.
AfterBranchNameMaskThe string to be stripped from the end of the branch file content after the branch name. By default, we expect a git branch file format.

Tip

The real power of products comes into play when you have multiple code bases targeting the same databases. You can define multiple products and divide the ownership of objects just as you do with any other application code.

Additional Resources