SchemaQuench turns fragile, step-by-step scripts into safe, declarative releases-so every deployment is boring, predictable, and fast.
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 MySQL 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:
JSON_TABLEUnlike SQL Server and PostgreSQL, MySQL applies foreign keys after data delivery (step 16). This avoids circular FK constraint violations during initial data population.
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 each target database. MySQL does not support schemas as a namespace, so all infrastructure objects use a SchemaSmith_ prefix.
SchemaSmith_QuoteIdentifierSchemaSmith_StripBacktickWrappingSchemaSmith_SafeBacktickWrapSchemaSmith_NormalizeIndexColumnsSchemaSmith_MissingTableAndColumnQuenchSchemaSmith_ModifiedTableQuenchSchemaSmith_MissingIndexesAndConstraintsQuenchSchemaSmith_ForeignKeyQuenchSchemaSmith_IndexOnlyQuenchSchemaSmith_TableQuenchSchemaSmith_GenerateTableJsonSchemaSmith_ParseTableJsonSchemaSmith_CompletedMigrationScripts — Prevents duplicate migration script executionSchemaSmith_ProductOwnership — Records which product owns each table and indexSchemaSmith_StatusMessages — Real-time progress reporting (see Platform Notes)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 MySQL status message polling and WhatIf mode.
MySQL stored procedures cannot send real-time messages to the client the way SQL Server (RAISERROR WITH NOWAIT) and PostgreSQL (RAISE NOTICE) can. Instead, SchemaSmith procedures write progress messages to the SchemaSmith_StatusMessages table. SchemaQuench polls this table every 200ms on a separate connection, captures new messages, and includes them in the progress log. The table is cleaned up when the connection closes.
Foreign keys are applied as a dedicated step (step 16) after data delivery, not alongside other indexes and constraints. This avoids circular FK constraint violations during initial data population and is handled by the dedicated SchemaSmith_ForeignKeyQuench procedure.
MySQL scripts use DELIMITER commands (not GO) to define statement boundaries. SchemaQuench splits scripts on each DELIMITER change and removes the DELIMITER lines before execution.
SchemaQuench tracks object ownership through the SchemaSmith_ProductOwnership table. This table:
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 database 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 INT to BIGINT.
On the surface, that is a simple alter table script, however, what if that column
participates in a generated column, a trigger, or a view?
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 change the type 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.