Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

sqldiff

The sqldiff program comes with the installation of SQLite. It can help creating migration scripts by showing the differences between two databases.

We have a before and after schema:

CREATE TABLE person (
    id INTEGER PRIMARY KEY,
    name TEXT
);

CREATE TABLE person (
    id INTEGER PRIMARY KEY,
    name TEXT UNIQUE NOT NULL,
    phone TEXT NOT NULL
);

We create two db files and run the sqldiff command on these files.

rm -f /tmp/before.db /tmp/after.db
~/bin/sqlite3 /tmp/before.db < examples/before.sql
~/bin/sqlite3 /tmp/after.db < examples/after.sql
~/bin/sqldiff /tmp/before.db /tmp/after.db

This is the output we get:

ALTER TABLE person ADD COLUMN phone;