Skip to content

Graphic preview

100%
Page type: tutorial

Quick start

Apply and verify a first Ptah schema change against a disposable SQLite database.

Edge documents the current development build and may describe unreleased behavior. To use those commands, build Ptah from master. For an installed release, select its version in the header.

Start with an empty directory. You will create one desired-schema file, preview the SQL Ptah plans, apply it to a local SQLite database, and read the live schema back. The result is disposable and needs no database server, Docker, or Go toolchain.

  • A ptah binary on your PATH. Install Ptah if you do not have one.
  • A terminal and about five minutes.

Confirm that the binary runs:

Terminal window
ptah version

The output names the version and platform. Their values depend on how you installed Ptah.

Terminal window
mkdir ptah-quick-start
cd ptah-quick-start
cat > schema.sql <<'SQL'
CREATE TABLE users (
id INTEGER PRIMARY KEY,
email TEXT NOT NULL
);
SQL

schema.sql is the schema you want. app.db does not exist yet.

Terminal window
ptah schema apply --schema-file schema.sql --db-url sqlite://app.db --dry-run

Expected output on standard output:

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

--dry-run opens the target to inspect its current schema but executes no planned statement.

Terminal window
ptah schema apply --schema-file schema.sql --db-url sqlite://app.db --auto-approve

Expected output includes the reviewed plan, on standard output:

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

Expected output also includes the completion result, on standard output:

Auto-approval enabled; applying schema changes.
Schema apply completed successfully.
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
);

This output comes from app.db, not from schema.sql. The database now matches the desired schema you reviewed.

Evolve and gate a direct schema continues from schema.sql and app.db. Skip this step while you are going there, and come back to it afterwards. Create and apply a versioned migration starts from nothing and needs neither.

Otherwise leave the working directory, then remove only the directory this tutorial created.

Terminal window
cd ..
rm -rf ptah-quick-start