Schemorph 0.24.0

There is a newer version of this package available.
See the version list below for details.
dotnet tool install --global Schemorph --version 0.24.0
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local Schemorph --version 0.24.0
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=Schemorph&version=0.24.0
                    
nuke :add-package Schemorph --version 0.24.0
                    

Schemorph

NuGet CI Release .NET License: MIT

Declarative, SQL-first schema management: plain SQL in, a reviewable plan out.

Schemorph is a CLI tool and library for managing database schemas as plain SQL files. You write the desired state of your database — tables, views, procedures — as ordinary CREATE statements. Schemorph computes what needs to change, shows you the plan, and applies exactly that plan.

No ORM. No Visual Studio. No proprietary DSL. Just SQL, a single command, and output that holds up equally in a code review and in a pipeline.

# Inspect a live database into SQL files
schemorph inspect --url "Server=...;Database=app" --out ./schema

# Preview what would change (never applies anything) — prints the plan and its fingerprint
schemorph diff --url "..." --desired ./schema

# Apply exactly the reviewed plan, or refuse if anything changed since the diff
schemorph apply --url "..." --desired ./schema --expect-plan <hash>

# Drift, ledger summary, pending migrations
schemorph status --url "..." --desired ./schema --migrations ./migrations

# Run as an MCP server (read-only tools + gated apply)
schemorph mcp

Status: early (0.x), under active development. Released on NuGet and GitHub releases. Two engines ship — SQL Server, and PostgreSQL up to a declared scope (Database Support). Working today against SQL Server: the full loop (inspect / diff / apply / status) with destructive-change gating and semantic exit codes; programmable-object routing via CREATE OR ALTER; checksummed run-once migrations; a history ledger; brownfield adoption (existing databases and SSDT trees are consumed as-is — matching objects reconcile instead of re-applying); a versioned machine-readable plan format with per-change SQL and explanations, an apply gate (--expect-plan) and safety-lint warnings; and an MCP server (schemorph mcp) with schema/plan resources. The documents in docs/ define the project's anchors — docs/ indexes them by question ("how do I undo an applied change?", "the apply failed at change 17 — now what?"), and Design Principles says what is fixed and what is open.


Why Schemorph

On SQL Server, one combination of properties does not exist today as free, offline, login-free tooling: a declarative diff engine that treats procedures and functions as first-class, plus a versioned data-migration ledger, plus a plan you can review and then apply exactly. Every existing tool gives you some of these; in the documentation we checked, none gives you all of them:

On SQL Server Declarative diff Procedures / functions as first-class Versioned data migrations CLI-first, no login Reviewable plan contract + gated apply Official agent surface (MCP / skill)
SSDT / SqlPackage ✅ ✅ ⚠️ pre/post-deployment scripts that run on every deploy ✅ SqlPackage; SDK-style projects build with dotnet build (the original project format is Visual Studio-bound) ⚠️ deploy script + XML deploy report none found
EF Core Migrations ❌ migration-based ⚠️ raw SQL inside a migration ✅ __EFMigrationsHistory ✅ ⚠️ migrations script / migrations bundle output none found
Flyway ⚠️ schema model and state-based deployments are in the paid editions ⚠️ repeatable scripts ✅ — ⚠️ dry-run script, paid editions ⚠️ MCP server (Enterprise, preview)
Liquibase ❌ changelog-driven (diff compares two databases) ⚠️ procedure / function / trigger diff is in Liquibase Secure ✅ DATABASECHANGELOG — ⚠️ update-sql / status ✅ MCP server (AI Changelog Generator)
Atlas ✅ SQL Server: Pro ⚠️ SQL Server: Pro ⚠️ versioned migration files; SQL Server: Pro ❌ the SQL Server driver is Pro and needs a login for every command ⚠️ atlas schema plan with from/to state fingerprints — Pro, login ✅ agent skills (no MCP server found)
Bytebase ❌ state-based mode covers PostgreSQL and MySQL, not SQL Server ❌ ✅ DDL + DML ⚠️ a server product (self-hosted or cloud) ⚠️ approval workflow (Enterprise) ✅ MCP endpoint
sqldef ✅ ⚠️ views and triggers — no procedures or functions in mssqldef ❌ none documented ✅ ⚠️ --dry-run none found
Schemorph ✅ ✅ ✅ ✅ ✅ ✅ MCP server + agent skill

<sup>Competitive claims as of 2026-11-01, checked against each vendor's own documentation; "—" means we could not confirm the cell from that documentation, and "none found" means we searched the vendor's documentation and found none. Re-verified periodically as these tools evolve.</sup>

  • Atlas's SQL Server driver is Pro-only and needs a login for every command, and its reviewable-plan feature (atlas schema plan) is Pro-only too; Bytebase's state-based mode does not cover SQL Server; Flyway's schema model and dry-run script are in the paid editions; sqldef's SQL Server variant cannot manage procedures or functions; SSDT's pre/post-deployment scripts run on every deploy, so a run-once data change needs a guard you write yourself.
  • The last two columns are narrow, checkable bars, not slogans. The plan is a versioned machine contract (plan-format.md) that also renders as a review document, and apply executes only a reviewed plan fingerprint or refuses. Printing a dry-run script is common; binding the apply to the identity of the reviewed plan is rare — in the documentation we read, Atlas does it (plan files with a from-state check), behind a login and a paid plan, on a SQL Server driver that is itself Pro-gated. Several of the others now ship an agent surface too; what Schemorph adds is that it is the same plan and the same gate on every surface (CLI, MCP, skill).

Schemorph is that combination: the declarative diff model (SSDT, Atlas, sqldef) and the versioned migration ledger (Flyway, Liquibase) in one coherent tool, where every change passes through a plan that a person can read and a program can parse — the same plan, not two renderings that can drift apart.

Core Model

Schemorph treats different kinds of database objects with the strategy that actually fits them, instead of forcing everything through one mechanism:

schema/                      ← declarative: desired state, diffed automatically
  tables/
  views/
  procedures/                ← idempotent: CREATE OR ALTER, re-applied on change
  functions/
migrations/                  ← versioned: ordered, checksummed, run once
  V0001__seed_reference_data.sql
  V0002__backfill_legacy_codes.sql
pre/                         ← pre-stage: run once BEFORE the diff is planned (--pre)
  V0001__rename_assets_to_equipment.sql
  • Structural objects (tables, indexes, constraints) are diffed: Schemorph compares your SQL files against the live database and generates the CREATE / ALTER / DROP plan.
  • Programmable objects (procedures, functions, views, triggers) are re-applied idempotently via CREATE OR ALTER. Text-based diffing of procedure bodies is unreliable by nature; re-definition is not. This sidesteps an entire class of bugs that diff-only tools struggle with. A re-defined view is read once over the rows already there before it commits, so a definition the data breaks (an overflowing cast, a division by zero) fails the apply instead of every query after it.
  • Data changes (seeds, backfills, one-off transformations) are versioned migrations tracked in a checksummed history ledger, Flyway-style. State diffing cannot express these; a ledger can.
  • Renames cannot be expressed as desired state either — the files carry no identity across a name change. A pre-stage script (--pre) states it with the engine's own statement, runs once before the declarative stage, and the plan is computed as of after it — so a renamed table keeps its rows instead of becoming a drop beside an empty create. See limitations.md.

See Architecture for the full model.

The Review Loop

One change goes through the same four steps whether you type them or a pipeline runs them:

  1. Edit the .sql files. git diff already tells the story.
  2. schemorph diff — always a dry run, never touches the database. It prints what would change and the plan's fingerprint (planHash).
  3. schemorph diff --format sql — the whole plan as one review document, in execution order, with the planHash in its header. This is the artifact to read, paste into a pull request, and sign off on.
  4. schemorph apply --expect-plan <hash> — executes exactly that plan, or refuses with plan_mismatch if anything drifted since the review.

The DDL a person approves is the DDL that runs, and nothing else — that is the whole point of the fingerprint (human approval gate). Destructive operations — anything that loses data nothing can recompute, whether that is dropping an object that holds rows or altering a table to remove a column your files no longer declare — stay out of plans entirely unless you enable them, and are marked prominently when you do. Every apply is recorded in a history ledger inside the database: what ran, when, its checksum, its outcome.

There is a ready-made GitHub Actions recipe that posts the review document as a comment on every schema pull request.

Structured Output and Automation

The same commands speak a stable machine contract, so scripts, CI jobs, and AI coding agents drive the loop above without screen-scraping output meant for a terminal:

  • Versioned plan format (docs/plan-format.md) — plans as machine contracts, with --format json on every command; JSON is the default whenever stdout is redirected (pipelines get JSON, terminals get text)
  • Exit codes distinguish "no changes", "changes pending", and "error", and failures carry a typed {kind, code, message, hint} envelope — see Errors and exit codes
  • schemorph schema prints a JSON manifest of the whole CLI surface (verbs, options, exit codes), so a caller discovers it without parsing help text
  • Credentials come from the SCHEMORPH_URL environment variable (preferred over --url), and password material is redacted from every output channel — safe to pipe into logs and PR comments
  • schemorph mcp runs the same operations as an MCP server over stdio — read-only tools (schemorph_diff, schemorph_inspect, schemorph_status) plus schemorph_apply gated behind a required plan fingerprint; the connection string stays in the server's environment, never in the conversation
  • Schema as context — the MCP server also exposes resources: schemorph://schema (the live database as desired-state SQL, or one object via schemorph://schema/{kind}/{name}) and schemorph://plan (the current plan with its planHash, ready for the apply gate; set SCHEMORPH_DESIRED_DIR in the server environment), so hosts attach schema state directly instead of round-tripping tool calls
  • Agent Skill — skills/schemorph/SKILL.md packages the procedural knowledge (the edit → diff → review → gated apply → converge loop, error-contract branching, migration immutability) in the Agent Skills format; drop it into your agent's skills directory

Nothing here is a separate mode: the JSON, the review document, and the MCP tools are renderings of one plan, so an automated run and a human review never disagree about what will happen.

Database Support

Schemorph is multi-target by design: one command set, one plan format, one ledger model and one set of safety rules across engines — only the dialect underneath changes (provider boundary). The boundary exists so further engines can follow.

  • SQL Server — initial target. The diff engine builds on DacFx (Microsoft's schema comparison framework, the same engine behind SSDT), giving full-fidelity handling of T-SQL objects from day one.
  • PostgreSQL — released, at full capability parity with SQL Server's declared surface: tables, columns, constraints, indexes, the target schema, views, functions, procedures, triggers, and versioned migrations. Set SCHEMORPH_PROVIDER=postgres and Schemorph inspects, diffs and applies all of it. The four programmable-object kinds are re-applied idempotently via CREATE OR REPLACE, PostgreSQL's own native idempotent form for all four (a view whose new column list OR REPLACE cannot accept is dropped and re-created instead — refused only when other objects depend on it; see limitations.md). The whole apply — declarative changes, redefines and migrations — runs in one session and lands entirely or not at all (atomicity: "transactional"; a failure in any stage rolls back everything the apply had done, and the error envelope says so — see failure-semantics.md). SQL Server declares atomicity: "partial": its declarative stage is one transaction, but redefines and migrations commit independently. Comparison is native pg_catalog with shadow normalization (ADR-0007); a database-owner role with CREATE SCHEMA suffices — no superuser, no CREATEDB, no extensions. What remains outside the declared capability list — non-transactional DDL such as CREATE INDEX CONCURRENTLY — is refused with an explicit error rather than half-planned (ADR-0003). Parity means equal capability range, deliberately not equal limitations — see limitations.md for where the two engines' behavior genuinely differs.

Which PostgreSQL schema is the target comes from the connection string's Search Path, and defaults to public when it is absent. Everything the run touches lands there — the compared objects, the DDL, and the history ledger alike — so several schemas can live on one server and be managed independently, one connection string each:

schemorph diff --url "Host=...;Database=app;Search Path=tenant_a" --desired ./schema
schemorph diff --url "Host=...;Database=app;Search Path=tenant_b" --desired ./schema

--desired is the directory of desired-state .sql files; the database namespace is chosen by the connection string alone. (Earlier versions called this option --schema, which was read as the namespace more than once — it is --desired now, and --schema is refused with a pointer to the new name.)

Installation

dotnet tool install -g Schemorph

Standalone self-contained binaries (win-x64, linux-x64, osx-arm64) are attached to each GitHub release — no .NET runtime required.

Documentation

Contributing

See CONTRIBUTING.md. The project follows ADR-driven governance: significant design decisions are proposed and recorded as ADRs before implementation.

License

MIT. The core tool is and will remain free and fully functional offline — no accounts, no feature gates, no telemetry required for any local operation.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last Updated
0.26.0 94 11/28/2026
0.25.1 91 11/28/2026
0.25.0 109 11/25/2026
0.24.0 113 11/22/2026
0.23.0 128 11/15/2026
0.22.0 120 11/9/2026
0.21.0 196 10/18/2026
0.20.0 194 10/15/2026
0.19.1 139 10/15/2026
0.19.0 170 10/11/2026
0.18.0 236 10/4/2026
0.17.0 132 10/3/2026
0.16.0 122 10/1/2026
0.15.1 123 9/28/2026
0.15.0 121 9/27/2026
0.14.4 131 9/24/2026
0.14.3 134 9/13/2026
0.14.2 144 9/10/2026
0.14.1 130 9/9/2026
0.14.0 140 8/31/2026
Loading failed