Skip to content
PtahPtah

Quick start: versioned migrations

Start with an empty directory. You will write one reversible migration pair, seal the directory with ptah.sum, apply the pending migration to SQLite, and verify both the recorded revision and the live table.

This tutorial does not roll the migration back. Rollback is a separate operational task with its own safety contract.

  • A ptah binary on your PATH. Install Ptah if necessary.
  • A terminal and about seven minutes.

No database server, Docker, or Go toolchain is required.

Migration filenames begin with an integer version. Use the fixed version below so your output matches this page.

Terminal window
mkdir -p ptah-versioned/migrations
cd ptah-versioned
cat > migrations/1700000000_create_users.up.sql <<'SQL'
CREATE TABLE users (
id INTEGER PRIMARY KEY,
email TEXT NOT NULL
);
SQL
cat > migrations/1700000000_create_users.down.sql <<'SQL'
DROP TABLE users;
SQL

The up file changes the database. The down file describes how to reverse that same version.

Terminal window
ptah migrations hash --dir ./migrations

Expected output on standard output:

Wrote ./migrations/ptah.sum
2 migration file(s) hashed

Commit ptah.sum with the migration files. Later commands refuse a migration file whose bytes no longer match the seal.

Terminal window
ptah migrations up --db-url sqlite://app.db --migrations-dir ./migrations

Expected output includes, on standard output:

Current version: 0
Total migrations: 1
Pending migrations: 1
✅ Migrations completed successfully!
Database is now at version: 1700000000

Progress records on standard error include timestamps and correlation IDs, so this page does not copy those volatile fields.

Terminal window
ptah migrations status --db-url sqlite://app.db --migrations-dir ./migrations

Expected output includes, on standard output:

Current Version: 1700000000
Total Migrations: 1
Applied Migrations: 1
Pending Migrations: 0
Out-of-order Migrations: 0
Status: ✅ Database is up to date

This answer comes from Ptah’s revision table inside app.db.

Terminal window
ptah db read --db-url sqlite://app.db

Expected output includes, on standard output:

CREATE TABLE "users" (
"id" INTEGER PRIMARY KEY,
"email" TEXT NOT NULL
);

The migration history and the database shape now agree.

Terminal window
cd ..
rm -rf ptah-versioned