Declarative vs Imperative Migrations

Two fundamentally different ways to manage database schema — declare the end state and let the tool generate changes, or write each change as an explicit migration script.

Chaos vs Precision: Product Comparisons

Quick Summary

Declarative (state-based): you describe what the schema should look like, and the tool figures out how to get there. Imperative (migration-based): you write explicit scripts for each change, and they apply in sequence. Both approaches work; they trade off in different places — team workflows, CI/CD shape, drift handling, rollback authoring, and how new environments come up.

Core Comparison

The fundamental difference between the two approaches.

Aspect Declarative (State-Based) Imperative (Migration-Based)
What you define Desired end state Steps to get there
Change generation Tool computes the diff automatically Developer writes every change
Drift handling Compare and sync anytime — same state, same result Track applied migrations and reconcile by hand
Environment parity Natural — declared state defines all environments Requires migration-history discipline
Merge conflicts Minimal — state files merge cleanly in source control Common — numbered scripts collide on parallel branches
New environment setup Apply current state directly Replay every migration from baseline
Rollback approach Re-deploy previous state* Write reverse migrations for every change
CI/CD model Idempotent — same pipeline produces the same result whether run once or ten times Order-dependent — the migration history table tracks what has been applied

*Schema rollbacks happen by re-applying the prior release’s declared state. Data preservation (e.g., retaining values from a dropped column) is handled with user-written migration scripts inside the same package.

Declarative (state-based)

“Here’s what the database should look like.”

You declare the desired end state:

{
  "table": "Users",
  "columns": [
    { "name": "Id",        "type": "int" },
    { "name": "Email",     "type": "nvarchar(255)" },
    { "name": "CreatedAt", "type": "datetime2" }
  ]
}

The tool compares this to the live database and generates the required ALTER / CREATE statements automatically.

Examples: SchemaSmith, DACPAC / SSDT, Redgate SQL Compare, Atlas.

Imperative (migration-based)

“Here’s how to change the database.”

You write explicit migration scripts:

-- V001_CreateUsers.sql
CREATE TABLE Users (
  Id int PRIMARY KEY,
  Email nvarchar(255)
);

-- V002_AddCreatedAt.sql
ALTER TABLE Users
ADD CreatedAt datetime2;

Scripts apply in sequence; a history table tracks what has run.

Examples: Flyway, Liquibase, DbUp, Entity Framework Migrations.

When to Use Each Approach

Declarative works best when...

  • Teams work in parallel — multiple developers edit schema without colliding on numbered script files
  • Environments drift — dev, staging, and production all converge to the same declared state
  • CI/CD is critical — idempotent deployments make pipelines simpler and more reliable
  • New environments are common — apply current state directly instead of replaying years of migrations
  • Schema reviews matter — JSON / metadata diffs read more like the change you made than long ALTER scripts

Imperative works best when...

  • Explicit control is required — you need to know exactly what SQL runs and in what order
  • Data migrations are complex — some changes require careful data transformation alongside the schema change
  • You prefer inline SQL as the audit artifact — the migration script set is the change log; declarative tools deliver the same audit trail through source-control history of the state files plus the DDL each deployment generates, but some teams want the SQL itself committed verbatim
  • Team prefers raw SQL — developers are comfortable writing every ALTER / CREATE by hand
  • Rollback is planned per change — every migration has a corresponding hand-written down script

Common Challenges

Declarative challenges

  • Destructive changes — the tool may drop and recreate objects; review generated scripts before deploy
  • Data transformations — complex data moves still need companion migration scripts
  • Tool trust — requires confidence that the tool generates correct SQL for your platform

Imperative challenges

  • Script ordering — parallel branches conflict on numbered or stamped script names
  • Environment drift — manual reconciliation when production diverges from the declared history
  • New environment setup — replay every migration from baseline (or seed the journal table at a point in time)
  • Rollback maintenance — down scripts get forgotten, drift, or fail when run against the wrong state

Tools by Approach

Declarative (state-based)

  • SchemaSmith — JSON metadata, CLI-first, cross-platform (SQL Server, PostgreSQL, MySQL); vs Flyway
  • DACPAC / SSDT — XML model, Visual Studio-centric, SQL Server only; vs DACPAC
  • Redgate SQL Compare — GUI-first, Windows-centric, SQL Server only; vs SQL Compare
  • Atlas — HCL / Terraform-style, ORM-integrated, broad database support; vs Atlas

Imperative (migration-based)

  • Flyway — numbered SQL migration scripts; vs Flyway
  • Liquibase — XML / YAML / JSON changelogs; vs Liquibase
  • DbUp — .NET library, embedded migration runner; vs DbUp
  • Entity Framework Migrations — code-first, derived from C# model classes; vs EF Migrations

Why SchemaSmith Picks Declarative

SchemaSmith is built around a declarative state-based core because that approach matches how most teams actually want to work in CI/CD. The benefits we ship for free:

  • No merge conflicts from script ordering
  • Drift detection on every deployment
  • New environments deploy in one step
  • Idempotent CI/CD pipelines
  • Readable JSON template diffs in PRs
  • DataTongs for declarative reference data

SchemaSmith also supports user-written migration scripts inside the same package — so the rare cases where imperative is the right answer (data transformations, careful column moves, complex backfills) live alongside the declarative state without forcing the whole workflow onto migration scripts.

Pricing and feature data last verified May 2026. Competitor information may change.