SchemaSmith Documentation

Define Your Database With Templates

A template is a metadata representation of a database.

Template JSON

Overview

A template is a metadata representation of a database. Conceptually, in object-oriented terms, a template is a class and a database is an instance. A template defines what a database should look like.

The Test Product has two templates defined for two different database definitions

the main template


{
    "Name": "Main",
    "DatabaseIdentificationScript": "SELECT [name] FROM master.dbo.sysdatabases WHERE [name] = '{{MainDB}}'",
    "VersionStampScript": "PRINT '{{ReleaseVersion}}'"
}
                            

the secondary template


{
    "Name": "Secondary",
    "DatabaseIdentificationScript": "SELECT [name] FROM master.dbo.sysdatabases WHERE [name] = '{{SecondaryDB}}'",
    "VersionStampScript": "PRINT '{{ReleaseVersion}}'"
}
                            

With the proper use of templates, you can enable some powerful patterns like Multi-Tenant Database Registry.

Properties

Setting Value
NameThe name of the template is referenced by the TemplateOrder in the Product definition.
DatabaseIdentificationScriptA result set containing the names of every database that is of this type.
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).
UpdateFillFactorWhether index fill factors should be updated within this template. Defaults to true.
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.

Additional Resources