Skip to content
Aurabase Logo
aurabase

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.

How-to guide9 min readLevel intermediate

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 docs

    It creates profiles, orgs, org_members, posts, todos, the view open_todos and the function todo_count(p_user uuid). See Example schema.

  • No DATABASE_URL in your environment, .env or .env.local: with it, push and 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#

CommandReadsWritesRoute
aura db pushaurabase/migrations/*.sqlThe project: runs the files the ledger does not holdPOST /v1/db/{project_id}/migrations/run
aura db pullThe projectaurabase/schema.sql (overwritten)GET /v1/db/{project_id}/schema/dump
aura db diff [--name <name>]The project and your migration filesA new file aurabase/migrations/<timestamp>_<name>.sql (schema_diff by default)GET …/schema and GET …/schema/dump
aura db watchaurabase/migrationsRuns push, then aura db generate (types.ts), at start and on each changeBoth 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:

  • push never reads the project's schema: it trusts the ledger. A table created in Studio is unknown to your files until you capture it with diff.
  • 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_events

This 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:

DetectedNot 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 mentionsA changed type, default or policy body
An enum type that no local file createsGrants

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 || true
Error: 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 allowed

Record 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 applied

Read 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 applied

Each 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#

  1. Make schema changes in migration files, and apply them with aura db push (or watch on a test project).
  2. When someone changes the schema in Studio or with SQL, run aura db diff --name <what>, read the file, keep it, and record it with aura db migration repair <file> --applied.
  3. Commit the files. In CI, aura db push applies them to each environment (Apply migrations from CI).
  4. Run aura db pull when 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+00

Common errors#

MessageCauseFix
multiple primary keys for table "…" are not allowed after diffThe 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 mismatchpull 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 outputA 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>.

See also#

@aurabase/aurabase-js@0.7.5 · aura@0.3.4↗ Report a problem