How to Generate Database Migration Scripts from DDL Diffs
August 15, 2026 · DevTools
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-onlyexport. - 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
- Paste your current schema (old) — one or more
CREATE TABLEblocks. - Paste your target schema (new).
- Select PostgreSQL, MySQL, or SQLite.
- Read the summary badges: CREATE / ALTER / DROP counts.
- If a destructive warning appears, inspect every DROP line and take a backup before applying.
- 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
| Change | Output |
|---|---|
| Table only in new schema | CREATE TABLE … |
| New column on existing table | ALTER TABLE … ADD COLUMN … |
| Column type/nullability change | ALTER TABLE … ALTER/MODIFY … (dialect-specific) |
| Column removed | ALTER TABLE … DROP COLUMN … (destructive) |
| Table removed | DROP 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 KEYtable 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
- Stored Procedure Formatter — beautify T-SQL, PL/SQL, and PL/pgSQL before committing.
- SQL Query Builder — compose SELECT statements against a schema you already ship.