Enterprise-grade state-based deployments with dependency-aware ordering.
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.
Traditional migration scripts track changes over time but can become cumbersome and error-prone, especially in complex environments. SchemaQuench offers a declarative approach, focusing on the desired final state rather than the sequence of changes. This methodology:
TemplateOrder contains all your templates in the order they need to be
quenched.
template.json to find the
correct database(s) to apply against, along with version validation and stamping scripts.
You can use Command Line Options to specify the log file location or an alternate config file.
See the SchemaQuench Walkthrough to help you get started with the tool.
Start by defining a small subset of your database objects. Gradually expand as you gain confidence, ensuring that each step is manageable and verifiable.
SchemaQuench processes a product in two layers: product-level orchestration and per-database quenching. Understanding this sequence helps you place scripts in the correct slots and troubleshoot failures.
For each database matched by a template, SchemaQuench runs these steps in order:
Use Checkpointing with the --ResumeQuench flag
to resume interrupted deployments from the last successful step, rather than starting over.
The "Kindle the Forge" step deploys helper objects into a [SchemaSmith] schema in each target database. These objects are used internally during the quench process and are safe to leave in place between runs.
fn_StripBracketWrappingfn_StripParenWrappingfn_SafeBracketWrapfn_FormatJsonPrintWithNoWaitMissingTableAndColumnQuenchModifiedTableQuenchMissingIndexesAndConstraintsQuenchIndexOnlyQuenchTableQuenchGenerateTableJson[SchemaSmith].[CompletedMigrationScripts] records which migration scripts have already run, preventing duplicate execution. See Migration Scripts for details on managing this table.
SchemaQuench writes dual-stream log files (Progress + Errors) and diagnostic SQL files when table quench steps fail. These debug files contain the exact SQL that was attempted, making failures easy to reproduce.
Logging & Exit Codes covers log file locations, backup behavior, debug SQL file names, exit codes, and platform-specific logging details including VerboseLogging for SQL Server.
ApplicationIntent is always set to ReadWrite, ensuring connections route to the writable replica in Availability Group configurations.
When SchemaQuench needs to alter a system-versioned (temporal) table, it automatically turns off system versioning before making structural changes and re-enables it afterward. No manual intervention is required.
When a physical column changes, SchemaQuench detects any computed columns that reference it and automatically rebuilds them. This ensures formula-based columns stay in sync without requiring you to track those dependencies manually.
SchemaQuench sets a ProductName extended property on every managed table and index. This property:
When SchemaQuench detects that a table should be dropped (it was once defined in the product but has been removed), it checks for a stored procedure named [SchemaSmith].[CustomTableDrop]. If found, it calls the procedure with the schema and table name as parameters and skips the actual drop.
Similarly, [SchemaSmith].[CustomTableRestore] is called near the beginning of each quench to restore previously custom-dropped tables. These hooks let you delay drops, perform custom backups, or implement whatever your process requires.
Say you are widening a column from VARCHAR(5) to VARCHAR(10).
On the surface, that is a simple alter table script, however, what if that column
participates in a check constraint, an index, a foreign key, or a full text index?
You would have to drop those constructs, make your change, and put them back on. That is a lot of bookkeeping for a simple change. SchemaQuench handles all of that for you. You widen the column in the table's JSON and SchemaQuench handles the dependencies. See Forge Deeper with SchemaQuench for details.
We now support renaming tables and columns. See defining tables for more details.