Gain a deeper understanding of SchemaQuench.
SchemaQuench is a state-based, opinionated database migration tool inspired by the principles of infrastructure-as-code tools like HashiCorp's Terraform. It enables you to define the desired end state of your SQL Server databases using metadata and applies these definitions to target servers, ensuring consistency and repeatability across environments. We refer to this process as quenching.
Quenching a product happens as a series of ordered events. Each slot must complete
successfully before we move to the next except as noted below.
Before product scripts. See Configurable Script FoldersTemplateOrder defined in the Product.
Object scripts without query tokens. Object scripts located in folders configured at the Template level with the Object quench slot. Object scripts will loop to resolve dependencies each time they are applied.SchemaSmith.MissingTableAndColumnQuench.Object scripts without query tokens.Before quench slot.SchemaSmith.ModifiedTableQuench.BetweenTablesAndKeys quench slot.SchemaSmith.MissingIndexesAndConstraintsQuench.AfterTablesScripts quench slot.AfterTablesObjects quench slot. This is the final chance to resolve script dependencies, and any remaining scripts that fail to apply in this pass will be reported as errors.TableData quench slot.After quench slot.After product scripts.Object scripts are always applied and Quench will loop through them to resolve dependencies if possible. We lean heavily on deferred name resolution and only fail if we cannot resolve a dependency multiple times after tables have been updated.
The process of quenching tables is broken into three separate slots in the Enterprise SchemaQuench to allow more robust and granular control over the entire process.
SchemaSmith.CustomTableRestore exists in the databaseProductNameSchemaSmith.CustomTableDrop when it exists, otherwise DROP TABLEProductName property so that we can drop the indexes that have been removed from the product even if the product is configured with DropUnknownIndexes set to false.DropUnknownIndexes is set to true at the product level OR when the unknown index is impacted by a column changeUpdateFillFactor to true at the template, table, or index level. The highest level wins when the values are mixed. This is intended to allow rolling out fill factor changes in a controlled manner for large tables to manage the update time, especially when resolving drift in the initial rollout of these tools.
When SchemaQuench detects that a table should be dropped, i.e., it was once defined in the product
but has been removed, it looks to see if there is a stored procedure named SchemaSmith.CustomTableDrop.
If there is such a procedure, it calls it passing the schema and name
of the table as the first and second parameters respectively and skips actually dropping the table.
Similarly, near the beginning of the quench process, an attempt is made to restore tables that had
been custom dropped previously. This hook expects a stored procedure named SchemaSmith.CustomTableRestore
passing the same schema and name parameters.
These hooks allow you to time delay dropping tables or to perform some custom backup procedure or whatever else your process may require.