← All tools
Free tool

SQL schema diff tool

Paste two versions of a PostgreSQL schema and get the structural diff plus the ALTER statements to migrate, added tables, dropped columns, type changes, and key changes, each flagged.

old.sql (current production schema) · 11 lines
new.sql (proposed schema) · 18 lines
migration.sql · 3 changes
+ table comments (3 columns)~ users: +1 col (created_at), -1 col (name), ~1 col~ posts: +1 col (published)
-- New table: comments
-- Generated by dbdiagramr (https://www.dbdiagramr.space)
-- PostgreSQL DDL exported from the interactive ER diagram below.

CREATE TABLE comments (
  id uuid PRIMARY KEY,
  post_id uuid,
  body text NOT NULL
);

ALTER TABLE comments ADD CONSTRAINT fk_comments_post_id FOREIGN KEY (post_id) REFERENCES posts (id);
-- Changes to users
ALTER TABLE users ADD COLUMN created_at timestamptz NOT NULL DEFAULT now();
ALTER TABLE users DROP COLUMN name;
ALTER TABLE users ALTER COLUMN email TYPE varchar(320) USING email::varchar(320);
-- Changes to posts
ALTER TABLE posts ADD COLUMN published boolean DEFAULT false;

Review before running on production. Test on a copy first.

Frequently asked questions

Related tools

Turn it into an ER diagram

Paste your PostgreSQL connection string and get an interactive ER diagram of your own schema in under 10 seconds. No signup required.