A product defines the entry point for updating your server.
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"
],
"ScriptTokens": {
"SecondaryDB": "TestSecondary",
"MainDB": "TestMain",
"ReleaseVersion": "1.0.0"
}
}
| Setting | Value |
|---|---|
| Name | This is used for tracking whether Migration Scripts have been run or not and also which product owns a given table. |
| ValidationScript | This 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). |
| TemplateOrder | Defines the order of template processing. The tool will ignore any template not named in this list. |
| ScriptTokens | You 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. |
| DropUnknownIndexes | Defaults to false. Any indexes not defined on a table are not dropped unless they have to be because of a structure change requiring it. |
| VersionStampScript | This 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). |
| BaselineValidationScript | Optional 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. |
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.