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 PostgreSQL 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. SchemaQuench will 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 databaseSchemaSmith.CustomTableDrop when it exists, otherwise DROP TABLEDropUnknownIndexes is set to true at the product level.
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.