DevTools Logo
All posts

How to Generate Database Migration Scripts from DDL Diffs

August 15, 2026 · DevTools

sql
migration
ddl
postgresql
mysql
sqlite
database

When you evolve a relational schema, the gap between "what production has" and "what the next release needs" is usually a handful of ALTER TABLE, CREATE TABLE, and sometimes DROP statements. Writing those by hand from two .sql dumps is slow — and missing a destructive DROP COLUMN is expensive.

The DB Migration Script Generator compares two CREATE TABLE snapshots and drafts the migration SQL for PostgreSQL, MySQL, or SQLite. Parsing runs entirely in your browser.

When to use it

  • You have before/after DDL from a design doc, ORM migration, or pg_dump --schema-only export.
  • You want a first-pass script to paste into Flyway, Liquibase, or a manual migration folder.
  • You need to spot destructive changes (dropped tables or columns) before they reach production.

For line-by-line query review, use SQL Compare. For readable formatting first, run both sides through the SQL Formatter.

Workflow

  1. Paste your current schema (old) — one or more CREATE TABLE blocks.
  2. Paste your target schema (new).
  3. Select PostgreSQL, MySQL, or SQLite.
  4. Read the summary badges: CREATE / ALTER / DROP counts.
  5. If a destructive warning appears, inspect every DROP line and take a backup before applying.
  6. Copy the script.

Click Load sample schemas to see a users/posts example that adds columns, creates a comments table, and widens a varchar.

What the diff detects

ChangeOutput
Table only in new schemaCREATE TABLE …
New column on existing tableALTER TABLE … ADD COLUMN …
Column type/nullability changeALTER TABLE … ALTER/MODIFY … (dialect-specific)
Column removedALTER TABLE … DROP COLUMN … (destructive)
Table removedDROP TABLE IF EXISTS … (destructive)

Dialect notes

PostgreSQL uses double-quoted identifiers and ALTER COLUMN … TYPE for modifications.

MySQL uses backticks and MODIFY COLUMN for type changes.

SQLite supports ADD COLUMN natively. Dropping or rewriting columns requires a table rebuild — the generator emits a comment reminder instead of invalid SQL.

Limitations

This is a pragmatic CREATE TABLE parser, not a full SQL compiler:

  • Indexes, views, triggers, sequences, and grants are out of scope.
  • Inline PRIMARY KEY / FOREIGN KEY table constraints are recognized but not diffed independently.
  • Complex refactors (column renames vs add+drop) may need human judgment.

Always validate the output against a staging database and your team's migration tooling.

Related tools