Skip to content

CLI

The potalab base CLI covers migrations, type generation, RLS tests and linting. It needs Node 22 or later.

Global options: --json (one JSON document on stdout, progress on stderr), -q, --quiet, --workdir <dir>. The project root is the nearest parent directory that contains potalab/config.toml.

Command What it does
potalab base init [--project-id id] Creates potalab/ (config.toml, migrations/, seed.sql, an example RLS test). Never overwrites an existing file.
potalab base link --project-ref r | --db-url u [--api-url a] Links the folder to a project. The database password is never stored: pass it with POTALAB_BASE_DB_PASSWORD or PGPASSWORD.
potalab base migration new <name> Creates potalab/migrations/<YYYYMMDDHHMMSS>_<name>.sql (UTC).
potalab base migration list Shows the apply order.
potalab base db reset [--yes --confirm <project_id>] / db restore <file> [--yes --confirm <project_id>] Destructive. In a terminal it asks you to type the project id; scripts, CI and coding agents must pass --yes --confirm <project_id> (--yes alone is refused). functions delete <name> works the same way with --confirm <name>.
potalab base db push [--db-url u] [--dry-run] [--include-all] [--policy-gate off|warn|error] [--accept-policy-changes codes] [--policy-file f] Reports the permission changes of the pending migrations (see below), then applies them, one transaction each, tracked in base.schema_migrations. Refuses migrations older than the newest applied one unless --include-all, and warns about edited or missing ones.
potalab base db diff [--name n] [--schema s...] [--allow-destructive] [--dry-run] [--policy-file f] Compares potalab/schemas/*.sql (the state you want) with your migrations on two throw-away databases of the local stack and writes the difference as a new migration. It also prints the permission changes of that migration (see below) and notes them in the file as -- POLICY: lines. Needs potalab base start.
potalab base db pull [--db-url u] [--name n] [--no-record] Dumps the schema of the exposed schemas as a baseline migration.

Migration files must not contain BEGIN or COMMIT (each file already runs in one transaction), and CREATE INDEX CONCURRENTLY is not allowed.

Command What it does
potalab base gen types [--lang ts|python|kotlin] [--package p] [--db-url u] [--schema s ...] [-o file] [--annotate [summary|full]] [--policy-detail none|summary|full] [--check] Prints the Database interface used by createClient<Database>(). The output is identical for the same schema. --annotate adds JSDoc with RLS state, policies, grants for anon/authenticated/service_role, function Callable by and COMMENT ON text (policy expressions only with --policy-detail full). --check -o file exits 1 when the file is out of date.
potalab base gen client [--lang ts|python|kotlin] [--package p] [--db-url u] [--schema s ...] [-o file] [--no-annotate] [--policy-detail none|summary|full] [--check] Writes the annotated Database interface plus createRpc(client) (typed rpc.<function>(args)) and an access constant with RLS, grants and function permissions as data.
potalab base gen schema --format json [--db-url u] [--schema s ...] [-o file] [--policy-detail none|summary|full] Prints the schema intermediate representation (JSON) shared by the generators.
potalab base lint [--db-url u] [--schema s ...] [--level info|warn|error] [--fail-on error|warn|info|none] [--json] Runs the security and performance advisor, with the same rules as the dashboard Advisors page. Exits 1 on a finding at or above --fail-on (default error).
potalab base tenancy status, potalab base tenancy enable <table>, potalab base tenancy disable <table> (options: [--db-url u] [--mode m] [--owner-column c] [--entitlement k] [--backfill-tenant uuid] [--drop-column]) Tenant isolation through base.enable_tenancy: status lists the tenant-scoped tables and exits 1 on drift, enable is idempotent (omitted options keep the current setting), disable drops the tenancy policies (RLS stays on). See Multi-tenancy.
potalab base migrate supabase [--dry-run|--yes] [--db-url u] [--owner-role r] [--only parts] Moves a Supabase project (schema, users with bcrypt passwords, data, storage) into a Base project. Start with --dry-run. See Migrate from Supabase.
potalab base test db [files...] Runs pgTAP tests from potalab/tests against the local development database.

gen client writes one file for your app: the Database types with comments about RLS, policies, grants and functions, a createRpc(client) helper so rpc.add_todo({ title }) is typed, and an access constant your tests or an AI agent can read. Policy expressions are left out unless you pass --policy-detail full. Add --check in CI to fail when the file is out of date.

For the Python and Kotlin SDKs use --lang python or --lang kotlin (Kotlin also takes --package). gen types writes the models (Python TypedDict, Kotlin @Serializable data class), and gen client adds the typed RPC wrappers (create_rpc(client) in Python, Rpc(client) in Kotlin). RLS and grant notes go into docstrings or KDoc. In Kotlin, numeric becomes Double, which can lose precision for very large values.

gen types marks nullable columns | null, makes columns with defaults optional on insert, types identity ALWAYS and generated columns as never, and maps SETOF <table> functions to that table’s rows.

Inside pgTAP tests (use begin ... rollback), these helpers switch role and claims like a real request:

select tests.authenticate_as('11111111-1111-1111-1111-111111111111', '{"app_role":"admin"}');
select tests.authenticate_as_anon();
select tests.authenticate_as_service_role();
select tests.clear_authentication();

potalab base start, stop, status and db reset run a local development stack. It needs Docker and has gaps compared to the hosted platform (for example no dashboard, Management API, webhooks, realtime or storage API), so prefer testing against a development project.

- run: potalab base lint --db-url "$DATABASE_URL" --fail-on warn
- run: potalab base gen types --db-url "$DATABASE_URL" -o src/database.types.ts --check
Code Meaning
0 ok
1 unexpected error, or lint findings at or above --fail-on
2 usage error, invalid config, or project not initialized
3 Docker missing, or the local stack is not running
4 database error (connect, migration, seed)
5 pgTAP tests failed
6 not implemented

Errors print error: ... and a hint: ...; with --json they print {"error":{code,message,hint}}.