Understand the terminology behind state-based database migrations
By the SchemaSmith Team · Last reviewed
A database deployment approach where you define the desired end-state of your schema, and the tool automatically calculates and applies the necessary changes.
How it works: You describe what your database should look like (declarative), not how to change it (imperative). SchemaSmith compares your definition to the actual database and generates the required DDL.
What it gives you:
The folder structure that organizes your database metadata: a Product definition at the root, one or more Templates underneath, and tables stored as JSON files with programmable objects as SQL scripts.
Contains:
A collection of templates with validation rules and deployment ordering. Defines how multiple database schemas are deployed together.
Contains:
A reusable metadata definition representing a database schema. One template can be applied to multiple databases.
Use case: You have 50 customer databases with identical structure. Define one template, and SchemaQuench applies it to all 50 databases in parallel.
Think of a template as a "class" and each database as an "instance" of that class.
Learn MoreThe process of extracting an existing database schema into metadata files. SchemaTongs performs casting.
Terminology:
The forge metaphor: Just as a blacksmith casts molten metal into a mold, SchemaTongs "casts" your database structure into structured metadata files.
Learn MoreThe process of applying metadata to target databases, generating and executing required DDL changes. SchemaQuench performs quenching.
Terminology:
The forge metaphor: Just as a blacksmith quenches hot metal to harden it, SchemaQuench "quenches" your metadata into a hardened, production-ready database.
Learn MoreSQL scripts that run before or after template updates. Used for tasks that can't be handled by automatic schema comparison.
Common uses:
When a database's actual state differs from the defined metadata. Drift occurs when changes are made directly to a database outside of the normal deployment process.
SchemaSmith handles drift by:
Variables that are replaced at deployment time, allowing environment-specific configuration without changing the metadata itself.
Example: Use {{DatabaseName}} in scripts, and it gets replaced with the actual database name during quenching.
Token types:
A dry-run mode that performs the full deployment logic — validation, token replacement, DDL generation, dependency resolution — without executing any changes against the database.
Use cases:
An idempotent operation produces the same end result no matter how many times it's run. Applying it once or applying it repeatedly leaves the target system in the same state, so re-running it is never harmful.
Why it matters for schema deployment:
Topological ordering is a way of sequencing a set of items so that every item comes after everything it depends on. It applies wherever a dependency graph has to be resolved into a linear sequence before anything can be built or run.
The hard part:
Fix-forward is the practice of resolving a bad deployment by shipping a corrective change forward, rather than reverting the system to its previous state. Instead of rolling back, the fix itself becomes the next deployment.
The trade-off:
CLI tool that extracts (casts) existing database schemas into metadata files.
CLI tool that deploys (quenches) metadata to databases, generating required DDL.
| Term | Definition | Related |
|---|---|---|
| State-Based Migration | Define desired end-state; tool calculates and applies the diff | Declarative vs Imperative |
| Schema Packages | Folder structure organizing database metadata: Product, Templates, Tables as JSON, SQL scripts | Schema Packages |
| Product | Collection of templates with deployment config and ordering | Products & Templates |
| Template | Reusable database definition applied to multiple databases | Products & Templates |
| Casting | Extracting existing schema into metadata files (SchemaTongs) | SchemaTongs |
| Quenching | Applying metadata to target databases (SchemaQuench) | SchemaQuench |
| Migration Scripts | SQL scripts that run before/after template updates | Migration Scripts |
| Drift | When database state differs from defined metadata | Database Schema Drift |
| Script Tokens | Variables replaced at deployment time for environment config | Script Tokens |
| SchemaTongs | CLI tool that extracts database schemas to metadata | Walkthrough |
| SchemaQuench | CLI tool that deploys metadata to databases | Walkthrough |
| DataTongs | CLI tool that exports seed data as synchronization scripts | Walkthrough |
| WhatIf Mode | Dry-run deployment preview without executing changes | CI/CD Integration |
The course glossary defines these state-based and declarative terms in the context of the hands-on lessons.
Open the course glossaryFree schema-as-code for SQL Server, PostgreSQL, MySQL, and MariaDB.
The source is on GitHub for anyone to read.
Get Started on GitHub