SQL Schema Diff & Migration Generator
Paste the CREATE TABLE statements you have now and the ones you want, and this tool writes the migration between them: ADD COLUMN, DROP COLUMN, type changes, NOT NULL and DEFAULT changes, plus new and removed tables. You get an up script and a matching down script for rollback, and a warning list that flags the statements that rewrite a table, take a heavy lock, or fail on non-empty tables — the things a schema diff usually only teaches you in production. Everything is parsed in your browser; no schema is uploaded.
Do more than sql schema diff & migration generator — meet Chat2DB
Chat2DB is an AI-powered SQL client for Windows, macOS and Linux. Write SQL in natural language, format and optimize queries automatically, and manage MySQL, PostgreSQL, Oracle and 20+ other databases in one workspace.
How to use
- Paste your current schema (the CREATE TABLE statements from pg_dump --schema-only or SHOW CREATE TABLE) into the left box.
- Paste the target schema — the version you want after the migration — into the right box, and pick PostgreSQL or MySQL.
- Copy the generated up migration into your migration tool, keep the down script for rollback, and read the warnings before running it on production.
Frequently asked questions
How do I generate an ALTER TABLE script from two schemas?
Compare the two schemas column by column and emit one statement per difference: ALTER TABLE t ADD COLUMN c type for new columns, DROP COLUMN for removed ones, ALTER COLUMN c TYPE new_type USING c::new_type for type changes, and SET/DROP NOT NULL or SET/DROP DEFAULT for constraint changes. This tool does that automatically from pasted CREATE TABLE DDL, and also produces the reverse script so you can roll back.
Which schema changes lock the table in PostgreSQL?
ADD COLUMN with a non-volatile DEFAULT, DROP COLUMN, SET/DROP DEFAULT and renames are metadata-only and fast, but still need a brief ACCESS EXCLUSIVE lock — set lock_timeout so they queue behind long queries instead of blocking the table. ALTER COLUMN TYPE rewrites the whole table unless the change is binary-coercible (varchar(50) → varchar(100) or → text), and SET NOT NULL scans the table to validate existing rows. The warnings box lists which of these your diff triggers.
Does this replace a schema migration tool like Flyway or Liquibase?
No — it generates the SQL, you still version and run it with your migration tool. Use the output as the body of a Flyway V__ file, a Liquibase changeset with a rollback block, or a hand-written migration in Django, Rails or Prisma. Constraints, indexes and triggers are only tracked for brand-new tables, so review the script before applying it. To browse both schemas side by side and run the migration, Chat2DB works across PostgreSQL, MySQL and 20+ other databases — download it at https://chat2db.ai/download or use it in the browser at https://app.chat2db.ai.
