Перейти к содержимому
Логотип Аурабаза
аурабаза

Local development and test databases

Pick where you develop and test your schema, see what changes when the CLI works on a local PostgreSQL instead of a project, and start over from a clean database.

Практическое руководство8 мин читатьУровень средний

Эта страница пока недоступна на вашем языке. Оно показано на английском языке.

Aurabase does not ship a local emulator of a project. You develop against a project (a test project, or a branch of your main one), or against a PostgreSQL on your machine for quick SQL iterations, knowing what it lacks. This page helps you choose, and shows what the CLI does in each case.

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.

The replayed examples write a migration file wf_local_probe and remove it in Clean up; the local PostgreSQL examples are outputs measured on a PostgreSQL 18 container and are not replayed by this page.

Where to develop#

A test projectA branchA local PostgreSQL (DATABASE_URL)
Same behavior as production (RLS by default, auth.uid(), roles, API, Realtime)YesYesNo (what it lacks)
SDK, REST API and Auth workYesYesNo: only SQL
Starts fromEmpty; push migrations and seedA copy of the source, rows included unless --no-dataEmpty
LifetimeUntil you delete it1 hour to 30 days (72 hours by default)Yours
Counts againstProjects of your planBranches of your plan (1 on Free)Nothing
Start overDrop your objects, or delete and create the projectDelete it, create a new oneDrop and create the database

Use a test project or a branch for anything that involves policies, users or the SDK. A local PostgreSQL suits plain SQL work: writing a migration, checking a query plan, running a seed.

A test project per developer#

Each developer, and each CI pipeline, can have its own project. Excerpt of the commands (not replayed here):

aura projects create my-app-alice --json > project.json   # prints the keys once: keep them
aura link <id of the new project>
export AURABASE_SERVICE_ROLE_KEY=aura_sk_…                 # the service_role key from project.json
aura auth settings set email_confirmation_required=false   # test project only
aura db push                                               # your migrations
aura db raw -f aurabase/seed.sql                           # your seed

On a test project, email confirmation can be turned off so that test users sign in at once; a project requires it by default. For a copy of real data, or a short-lived database per pull request, create a branch instead.

How DATABASE_URL changes the CLI#

The CLI loads .env.local and .env from the current folder at start. When DATABASE_URL is set, in the environment or in one of these files, the migration commands work on that database, even when a project is linked:

CommandLinked project, no DATABASE_URLDATABASE_URL set
aura db pushThe project, through the APIThat database, then each file is also sent to the project if one is linked
aura db migration down, aura db migration repairThe project's ledgerA table _aura_cli_migrations in that database
aura db statusThe project's ledgerThe project's ledger if one is linked, _aura_cli_migrations otherwise
aura db seed (your seed.sql)Fails: No database configuredThat database
aura db resetFails (see below)Fails
aura db generateThe project (types.ts)The project; DATABASE_URL is only used without a link
aura db pullThe projectThe project; pg_dump on DATABASE_URL only without a link

Many applications keep a DATABASE_URL in .env for their ORM. In such a folder, aura db push leaves your project alone and tries that database:

mkdir -p aurabase/migrations
echo "select 1;" > aurabase/migrations/20261201000000_wf_local_probe.sql
DATABASE_URL=postgresql://dev@127.0.0.1:1/app aura db push 2>&1 || echo "exit code $?"
» Applying migrations...
Error: PostgreSQL unreachable at postgresql://dev@127.0.0.1:1/app.
  Run aura start first.
exit code 1

Rename the variable of your ORM, or run the CLI from a folder without it, when you mean the project. Without a linked project, the local database is used in its public schema; with one, in a schema named project_<id>, which a plain PostgreSQL does not have (schema "project_…" does not exist).

A local PostgreSQL#

Any PostgreSQL works; use the major version of Aurabase (18) so that pg_dump and SQL behave the same. In a folder that is not linked (aura init writes an aurabase.toml without a project), set DATABASE_URL and use the usual commands. Output measured on a PostgreSQL 18 container (not replayed by this page):

export DATABASE_URL=postgresql://postgres:…@127.0.0.1:55432/postgres
aura db push
» Applying migrations...
  ⚠ No linked project — operations targeting schema 'public'. Use aura link
  • Applying 20261201000000_wf_local_notes.sql...
  • Applying 20261201000100_wf_local_owner.sql...
Error: error returned from database: schema "auth" does not exist

Caused by:
    schema "auth" does not exist

The second migration used default auth.uid(), which exists on a project and not on a plain PostgreSQL. The first file was applied and recorded; locally, too, each file runs in its own transaction. aura db status, aura db migration down (it reads the .down.sql files and reverts the latest migrations, as its help says) and aura db seed then work on that database:

» Migration Status - Database
  Migration                                Status       Date
  ------------------------------------------------------------------------
  20261201000000_wf_local_notes.sql        APPLIED      2026-11-22 23:32
  20261201000100_wf_local_owner.sql        PENDING      -

To run migrations that call auth.uid() locally, create a stand-in once in the local database (with psql, not part of your migrations). It reads the same setting as on a project, so set local request.jwt.claims = '{"sub": "…"}' lets you test a policy by hand:

create schema if not exists auth;
create or replace function auth.uid() returns uuid language sql stable as
  $$ select nullif(nullif(current_setting('request.jwt.claims', true), '')::json->>'sub', '')::uuid $$;

With it, the second migration applied. Policies to aura_authenticated also need the roles: create role aura_anon nologin; create role aura_authenticated nologin;.

aura db generate without a link reads the local database and writes types.ts and AuraClient.js. That generator is simpler than the project's: identity columns are required in Insert, and views, functions and enums are not described. Generate the types you ship from a project (Generate TypeScript types).

What a local database does not have#

On a projectOn a local PostgreSQL
auth.uid(), auth.jwt() and the other auth.* helpersMissing unless you create stand-ins
Roles aura_anon, aura_authenticated, aura_service_roleMissing
Row level security turned on and forced on every new tableOff unless your migration turns it on: a migration that relies on the default gives a table without RLS locally
Migration SQL checked before it runs (no do blocks, no security definer, no begin/commit…)Not checked: a migration can pass locally and be refused by the project
A ledger with checksums: an edited file is detectedA ledger of names only, in _aura_cli_migrations
The REST API, the SDK, Auth, Realtime, the extensions the platform installsNone

Before merging, push your migrations to a test project or a branch: that is where they must pass.

Start over: aura db reset does not work#

aura db reset is meant to drop the schema, recreate it and push the migrations again. With CLI 0.3.4 it fails in every case. On a linked project, without DATABASE_URL, it does not use the API:

aura db reset --force 2>&1 || echo "exit code $?"
» Resetting local database...
Error: No database configured. Link a project with 'aura link' (commands will use the API), or set DATABASE_URL (environment variable or .env) for a local database.
exit code 1

With DATABASE_URL, measured on the local PostgreSQL 18 container (not replayed here), it fails before changing anything:

» Resetting local database...
Error: error returned from database: cannot insert multiple commands into a prepared statement

Start over this way instead:

  • Local PostgreSQL: drop and create the database (dropdb and createdb, or a new container), then aura db push and aura db seed.
  • Test project: drop the objects your migrations created (aura db table drop <table> --force, aura db raw "drop view …"), remove their versions from the ledger (aura db migration repair <file> --reverted), then push and seed again. Or delete the project (aura projects delete <id> --force) and create a new one.
  • Branch: delete it and create a new one, with --no-data for an empty schema.

aura start runs the Aurabase stack#

aura start, aura stop, aura restart and aura dev start the services of Aurabase itself, from a checkout of the Aurabase repository (they run its start.sh); they are for self-hosting and for contributors. In an application folder they stop at once:

aura start 2>&1 || echo "exit code $?"
» Starting Aurabase stack...
Error: Error: Unable to find Aurabase repository root.
Please run this command from the project directory
OR set the environment variable: export AURABASE_PATH=/path/to/aurabase
exit code 1

The hint Run aura start first. printed when a DATABASE_URL is unreachable refers to that stack, not to your local PostgreSQL.

Result#

The linked project was never touched by the commands above:

aura db status
» Migration Status - Project 11111111-2222-4333-8444-555555555555
  Migration                                Status       Date
  ------------------------------------------------------------------------
  20261201000000_wf_local_probe.sql        PENDING      -

The probe file is pending: neither the push redirected to DATABASE_URL nor the reset reached the project.

Common errors#

MessageCauseFix
PostgreSQL unreachable at postgresql://…DATABASE_URL is set (environment, .env or .env.local) and its database does not answer.Start that database, or unset DATABASE_URL to work on the linked project.
schema "project_…" does not existDATABASE_URL points to a plain PostgreSQL while a project is linked.Unset DATABASE_URL, or work in a folder that is not linked.
schema "auth" does not existA migration uses auth.uid() on a local database.Create the stand-in above, or push to a test project.
No database configured. Link a project with 'aura link' …aura db seed or aura db reset on a linked project without DATABASE_URL.Seed with aura db raw -f aurabase/seed.sql; start over as described above.
cannot insert multiple commands into a prepared statementaura db reset with DATABASE_URL.Drop and create the database yourself.
No linked project. Reset the 'public' schema? (DESTRUCTIVE) then Not a terminalaura db reset without --force in a script.It would fail anyway: see Start over.
Unable to find Aurabase repository root.aura start or aura dev outside the Aurabase repository.Use a project, a branch or your own PostgreSQL.

Clean up#

rm -rf aurabase/migrations
aura db status
» 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↗ Сообщить о проблеме