Evolve and gate a direct schema
Change an applied desired schema, review the ALTER plan, and gate CI on schema drift.
Use this page after the default quick start. It continues
from that tutorial’s schema.sql and app.db, and rebuilds them below if you
have already cleaned up. You will add a column, inspect the ALTER TABLE Ptah
derives, apply it, and prove the database has not drifted from the file.
Prerequisites
Section titled “Prerequisites”- Your terminal is in
ptah-quick-start. app.dbcontains theuserstable from the default quick start.schema.sqlstill describes that table.
If you already removed the directory, rebuild that state here rather than working through the quick start again. The commands are its first and third steps:
mkdir ptah-quick-startcd ptah-quick-startcat > schema.sql <<'SQL'CREATE TABLE users ( id INTEGER PRIMARY KEY, email TEXT NOT NULL);SQLptah schema apply --schema-file schema.sql --db-url sqlite://app.db --auto-approveNew-Item -ItemType Directory ptah-quick-start | Out-NullSet-Location ptah-quick-start@'CREATE TABLE users ( id INTEGER PRIMARY KEY, email TEXT NOT NULL);'@ | Set-Content schema.sqlptah schema apply --schema-file schema.sql --db-url sqlite://app.db --auto-approve1. Change the desired schema
Section titled “1. Change the desired schema”Replace schema.sql with this version:
cat > schema.sql <<'SQL'CREATE TABLE users ( id INTEGER PRIMARY KEY, email TEXT NOT NULL, created_at TEXT);SQL@'CREATE TABLE users ( id INTEGER PRIMARY KEY, email TEXT NOT NULL, created_at TEXT);'@ | Set-Content schema.sqlYou changed the destination shape. Ptah derives the SQL needed to reach it from the live database.
2. Review the evolution plan
Section titled “2. Review the evolution plan”ptah schema apply --schema-file schema.sql --db-url sqlite://app.db --dry-runExpected output on standard output:
Planned schema changes:ALTER TABLE "users" ADD COLUMN "created_at" TEXT;The plan alters the existing table; it does not create another table or replay the original statement.
3. Apply and verify the change
Section titled “3. Apply and verify the change”ptah schema apply --schema-file schema.sql --db-url sqlite://app.db --auto-approveptah schema drift --schema-file schema.sql --db-url sqlite://app.dbExpected output on standard output:
Schema apply completed successfully.No schema drift detected.4. Read the column back from the database
Section titled “4. Read the column back from the database”The apply reported success and drift reported none. Both are Ptah’s own verdicts; this reads the table itself:
ptah db read --db-url sqlite://app.dbExpected output includes, on standard output:
CREATE TABLE "users" ( "id" INTEGER PRIMARY KEY, "email" TEXT NOT NULL, "created_at" TEXT);The column is there, in app.db rather than in schema.sql.
5. Use drift as a CI gate
Section titled “5. Use drift as a CI gate”The same check belongs in automation, with the URL coming from the
environment: ptah schema drift --schema-file schema.sql --db-url "$DATABASE_URL".
Branch on the exit status, not on captured prose:
| Exit | Meaning |
|---|---|
0 |
The live database matches the desired schema. |
1 |
Drift exists. The report includes the highest severity and findings. |
2 |
Ptah could not decide because the invocation, source, or connection failed. |
CI shows the GitHub Action and shell forms. Compare and detect drift covers severities, formats, and remediation paths.
Clean up
Section titled “Clean up”cd ..rm -rf ptah-quick-startSet-Location ..Remove-Item -Recurse -Force ptah-quick-startNext steps
Section titled “Next steps”- Save, sign, and verify a plan.
- Adopt an existing database.
- Generate versioned migration files from the same desired schema.