Push, pull, diff and watch
Know which way each schema command copies, what it reads and writes, and how to bring changes made in Studio or with SQL back into your migration files.
Your schema lives in two places: the migration files of your repository and the database of your project. Four commands of the CLI copy between them, each in one direction. None of them merges: knowing which way each one goes is what keeps the two in line.
Prerequisites#
-
A linked project:
aura link <project-id>. -
The example schema, installed with the service role key of the project:
export AURABASE_SERVICE_ROLE_KEY=aura_sk_… aura db seed --example docsIt creates
profiles,orgs,org_members,posts,todos, the viewopen_todosand the functiontodo_count(p_user uuid). See Example schema. -
No
DATABASE_URLin your environment,.envor.env.local: with it,pushand the migration commands work on that database instead of the project (Local development).
The examples create the tables wf_sync_events and wf_sync_watch, files under aurabase/ and types.ts; the Clean up block removes them. sed replaces the timestamp of migration file names with YYYYMMDDHHMMSS.
Four commands, four directions#
| Command | Reads | Writes | Route |
|---|---|---|---|
aura db push | aurabase/migrations/*.sql | The project: runs the files the ledger does not hold | POST /v1/db/{project_id}/migrations/run |
aura db pull | The project | aurabase/schema.sql (overwritten) | GET /v1/db/{project_id}/schema/dump |
aura db diff [--name <name>] | The project and your migration files | A new file aurabase/migrations/<timestamp>_<name>.sql (schema_diff by default) | GET …/schema and GET …/schema/dump |
aura db watch | aurabase/migrations | Runs push, then aura db generate (types.ts), at start and on each change | Both of the above |
All four use the service_role key of the project and the project of aurabase.toml.
push: files to the project#
aura db push sends each migration file the ledger does not hold, in the order of the file names, and stops at the first failure. Everything about files, order, transactions and failures is in SQL migrations. Two points matter for syncing:
pushnever reads the project's schema: it trusts the ledger. A table created in Studio is unknown to your files until you capture it withdiff.- A file edited after it ran is reported
(already applied)and its change is not applied (Changing a migration that already ran).
pull: the project to one file#
aura db pull | tail -n 1 | sed -E 's/\([0-9]+ bytes\)/(<size> bytes)/'
grep -E '^(-- Table|CREATE OR REPLACE FUNCTION)' aurabase/schema.sql✔ Schema exported to aurabase/schema.sql (<size> bytes)
-- Table: org_members
-- Table: orgs
-- Table: posts
-- Table: profiles
-- Table: todos
CREATE OR REPLACE FUNCTION todo_count(p_user uuid)The file holds enum types, tables, constraints, indexes, row level security, policies, functions and triggers. It leaves out views and materialized views, partitioned tables, grant and revoke: the view open_todos and the grant execute on todo_count are not in it. Read and export your schema lists what the export contains. Use the file as a snapshot to read, review or diff in your repository, not as a migration: pull overwrites it each time and push does not read it.
Without a linked project, pull runs pg_dump --schema-only on DATABASE_URL instead. Your pg_dump must match the major version of the server (PostgreSQL 18 on Aurabase); otherwise it prints pg_dump failed. with the error of pg_dump, and still exits with code 0.
diff: capture changes made outside the files#
A table created in Studio, with aura db raw or over the direct connection is in the project but in no file. aura db diff writes the SQL of what the project has and your files do not:
aura db raw "create table wf_sync_events (id bigint generated always as identity primary key, kind text not null)"
aura db diff --name wf_sync_capture | sed -E 's/[0-9]{14}_/YYYYMMDDHHMMSS_/'
grep '^-- TABLE' aurabase/migrations/*_wf_sync_capture.sql ℹ No results (0 rows).
» Schema diff (remote → local)
• Fetching remote schema...
✔ Migration generated: aurabase/migrations/YYYYMMDDHHMMSS_wf_sync_capture.sql
ℹ Review the file, then apply with aura db push
-- TABLE: org_members
-- TABLE: orgs
-- TABLE: posts
-- TABLE: profiles
-- TABLE: todos
-- TABLE: wf_sync_eventsThis project had no migration files yet, so every table is in the file, with its constraints, indexes, row level security and policies. What diff detects:
| Detected | Not detected |
|---|---|
| A table that no local file creates (its whole DDL) | Functions, triggers and views |
A column of the project that no local file mentions (add column if not exists) | Tables and columns dropped in the project |
| An index, constraint or policy whose name no local file mentions | A changed type, default or policy body |
| An enum type that no local file creates | Grants |
The detection reads names in your files as text: a name mentioned anywhere, even in a comment, counts as known.
The message says to apply the file with aura db push, but on the project it came from, the file re-creates what already exists and fails:
aura db push 2>&1 | sed -E 's/[0-9]{14}_/YYYYMMDDHHMMSS_/' | grep Error || trueError: Migration 'YYYYMMDDHHMMSS_wf_sync_capture.sql' failed: [400] BAD_REQUEST: Invalid request: Migration failed: Invalid request: multiple primary keys for table "org_members" are not allowedRecord it as applied instead, without running it: the project already has its content, and a new project will run it from your files.
aura db migration repair "$(basename "$(ls aurabase/migrations/*_wf_sync_capture.sql)")" --applied > /dev/null
aura db diff» Schema diff (remote → local)
• Fetching remote schema...
✔ No differences detected — local schema is up to date.A column added later gives a statement that can run on any project, the source included, since it only adds what is missing:
aura db raw "alter table wf_sync_events add column source text"
aura db diff --name wf_sync_source > /dev/null
grep -v '^--' aurabase/migrations/*_wf_sync_source.sql | grep .
aura db push 2>&1 | sed -E 's/[0-9]{14}_/YYYYMMDDHHMMSS_/' | grep wf_sync_source ℹ No results (0 rows).
ALTER TABLE "wf_sync_events" ADD COLUMN IF NOT EXISTS "source" TEXT;
✔ YYYYMMDDHHMMSS_wf_sync_source.sql appliedRead every generated file before you keep it: it is a starting point, not a verified migration.
watch: apply on save#
aura db watch runs aura db push and aura db generate once, then again each time a file is created or changed in aurabase/migrations, until you stop it with Ctrl+C. An error is printed and the watch goes on. Here it runs in the background while a new migration is written:
aura db watch > watch.log 2>&1 &
watcher=$!
for i in $(seq 1 60); do grep -q 'Waiting for changes' watch.log && break; sleep 1; done
aura db migration new wf_sync_watch > /dev/null
echo "create table wf_sync_watch (id bigint generated always as identity primary key);" > "$(ls aurabase/migrations/*_wf_sync_watch.sql)"
for i in $(seq 1 60); do grep -q 'wf_sync_watch.sql applied' watch.log && break; sleep 1; done
{ kill "$watcher" && wait "$watcher"; } 2>/dev/null || true
grep -E 'Watcher mode|types.ts generated|Waiting for changes|Change detected|wf_sync_watch.sql applied' watch.log \
| sed -E 's/[0-9]{14}_/YYYYMMDDHHMMSS_/' | awk '!seen[$0]++'» Watcher mode enabled: watching migrations...
✔ types.ts generated from API!
ℹ Waiting for changes in 'aurabase/migrations' (Ctrl+C to stop)...
Change detected, updating...
✔ YYYYMMDDHHMMSS_wf_sync_watch.sql appliedEach save is a push. A file saved half written is applied as it is; if you then complete it, the new content is skipped as (already applied) (Changing a migration that already ran). Write the whole file before saving it, or keep watch for a test project or a branch. A single save often triggers several pushes; the ones after the first find nothing new. watch writes types.ts in the current folder; Generate TypeScript types writes it where you choose.
A workflow that keeps them in line#
- Make schema changes in migration files, and apply them with
aura db push(orwatchon a test project). - When someone changes the schema in Studio or with SQL, run
aura db diff --name <what>, read the file, keep it, and record it withaura db migration repair <file> --applied. - Commit the files. In CI,
aura db pushapplies them to each environment (Apply migrations from CI). - Run
aura db pullwhen you want a readable snapshot of the whole schema, then regenerate types.
Result#
aura db status | sed -E 's/[0-9]{14}_/YYYYMMDDHHMMSS_/'» Migration Status - Project 11111111-2222-4333-8444-555555555555
Migration Status Date
------------------------------------------------------------------------
YYYYMMDDHHMMSS_wf_sync_capture.sql APPLIED 2026-11-23 10:00:00.000000+00
YYYYMMDDHHMMSS_wf_sync_source.sql APPLIED 2026-11-23 10:00:00.000000+00
YYYYMMDDHHMMSS_wf_sync_watch.sql APPLIED 2026-11-23 10:00:00.000000+00Common errors#
| Message | Cause | Fix |
|---|---|---|
multiple primary keys for table "…" are not allowed after diff | The generated file was pushed to the project it was generated from. | aura db migration repair <file> --applied, then delete what you do not want to keep. |
No remote tables found. | diff on a project without tables. | Nothing to capture. |
pg_dump failed. with a version mismatch | pull without a linked project, with an older pg_dump. | Install the client of the server's major version, or link the project. |
API failed to export schema (…) | pull was refused by the project, for example with an anon key. | Use the service_role key. |
Push error: … in the watch output | A file failed while watching; the watch goes on. | Fix the file and save it again. |
No project linked. Run 'aura link' first (or 'aura init'). | diff outside a linked folder. | aura link <project-id>. |
Clean up#
aura db raw "drop table if exists wf_sync_events; drop table if exists wf_sync_watch"
for f in aurabase/migrations/*_wf_sync_*.sql; do aura db migration repair "$(basename "$f")" --reverted > /dev/null; done
rm -rf aurabase watch.log types.ts
aura db status ℹ No results (0 rows).
» Migration Status - Project 11111111-2222-4333-8444-555555555555
ℹ No migrations found, local or applied. Create one with aura db migration new <name>.