Configuration
better-supabase.config.ts options and defaults.
The CLI looks for better-supabase.config.{ts,mts,js,mjs,json} in the
working directory, then in each parent directory up to the one that holds
.git, and loads the first it finds. Paths in the file (output, database.sql.dir
and the rest) are relative to the directory that holds it, so a config at the
repository root works when the CLI runs from a package. --config overrides
the search. TypeScript configs load natively on Node 24.
import { defineConfig } from "better-supabase/config";
import { zod } from "better-supabase/generators/zod";
import { CustomerMetadata } from "./src/types.ts";
export default defineConfig({
database: {
source: { projectRef: "abcdefghijklmnopqrst" },
schemas: ["public"],
realtime: { tables: ["customers", "notes"] },
},
gen: {
casing: "camel",
file: "src/lib/supabase/generated.ts",
codecs: { int8: "bigint", numeric: "string", timestamptz: "instant" },
json: {
"customers.metadata": {
import: "./src/types.ts#CustomerMetadata",
schema: CustomerMetadata,
},
"notes.attachments": {
type: "{ files: { name: string; size: number }[] }",
},
},
sensitive: ["contacts.email", "contacts.phone"],
tables: {
customers: { relations: { primaryContact: "contact" } },
internal_jobs: { exclude: true },
},
generators: [zod()],
},
blocks: {
"updated-at": {},
"created-by": {},
trash: { options: { deletedAt: "archived_at" } },
},
auth: { tenant: { column: "organization_id" } },
});Options
| Option | Default | Notes |
|---|---|---|
database.source | local stack | dbUrl, projectRef (+ accessToken, default $SUPABASE_ACCESS_TOKEN), snapshot or lite. See gen |
database.schemas | ['public'] | Tables in other schemas get prefixed keys |
gen.casing | 'snake' | 'camel' maps columns in queries; see casing |
gen.tables | {} | Per-table casing, exclude, serviceRole, relation renames and insertOptional, keyed by table name or schema.table. serviceRole keeps the models but tells doctor the table is for service_role only; insertOptional lists not-null columns the database fills on insert, for fillers gen can't read from a before insert trigger's body |
gen.file | src/lib/supabase/generated.ts | database.types.ts and generated.meta.js are written next to it |
gen.postgrestVersion | '13' | Written to __InternalSupabase in database.types.ts |
gen.codecs | JSON types | int8: 'bigint' | 'string', numeric: 'string', timestamptz: 'instant' read values exactly; timestamptz: 'utc' keeps strings, always in UTC with a Z. See Temporal |
gen.relations | { nullableUnderRls: false } | nullableUnderRls: true types to-one includes of tables with RLS as | null; see includes |
gen.json | {} | jsonb types, keyed by table.column or schema.table.column (database names). schema adds a database check |
gen.sensitive | [] | Columns the noSensitiveSelect guard checks (table.column) |
gen.generators | [] | zod(), valibot(), jsonSchema(), standardSchema() or your own |
auth.tenant | { claim: 'tenant_id', column: 'organization_id' } | claim is the active-organization claim the memberships extension, current_tenant_id() and the storage and realtime policies read; column is the column the memberships extension filters on |
auth.claims | { scope: 'tenant', features: 'features', memberships: 'memberships', permissions: 'permissions' } | JWT claim names. scope is the scope of the module's memberships entries; features is the plan-features claim. See Claims |
database.buckets | {} | Typed storage buckets; doctor compares them with the database and config.toml |
gen.storagePaths | {} | Text columns that hold object paths, keyed by table.column, with a buckets key or bucket id as the value. They're typed as StoragePath<'bucket-id'> |
gen.functions | {} | Function results that are never null, keyed by function name or schema.name: { notNull: true } or the returns table columns. An entry wins over an @notNull tag in the function's comment. See gen |
database.topics | {} | Realtime topic templates |
database.realtime | { tables: [], global: [], users: {}, triggers: [] } | Tables for live queries; global lists the ones without a tenant column, users maps per-user tables to their user column. policies and triggers make upgrade write topic policies and broadcast triggers |
auth.entitlements | { key: 'id' }; customer defaults to the organizations module's stripe_customer_id | Where the entitlements SQL module finds each tenant's Stripe customer, or source ({ plans } or "custom") for entitlements without the Stripe Sync Engine. memberships ("tenant" or "provider") picks where it reads memberships from |
auth.authorization | none | An authorization provider the provider access model, the entitlements module, bucket and topic policies and doctor delegate to |
database.vectorSearch | {} | Embedding columns ({ chunks: 'embedding' }) the vector-search SQL module writes search_<table> for |
recordTypes | {} | The app's subject registry: each subject type's table, id, tenant, title, URL template, permission keys, scope, rank and search columns. Modules that take subjects fall back to it, and gen emits a SubjectType union |
gen.readSets | [] | Modules exporting read sets; gen compiles them into the read-sets SQL module |
gen.records | true | Writes a record type to records/<type>.ts next to gen.file for each type in config.recordTypes that a block binds to; false writes none |
gen.contentMapper | false | Serves the schema types to TypeScript 7.1 through the content mapper: gen writes schema.bsb and no database.types.ts, and tsconfig.json lists the mapper in contentMappers |
gen.tableModules | true | Writes one module per table, tables/<table>.ts, and generated-schema.ts for the server; the generated module adds clientSchema for a browser client that registers the tables it uses. See Table modules |
gen.types.tables.only | every relation | Names (customers or public.customers) that database.types.ts includes. Other tables, views and foreign tables are omitted, with their columns and relationships. |
gen.types.also | none | More files, relative to the project root, that get a copy of database.types.ts, for apps in a monorepo that read the same types. gen --check fails when a copy is stale. |
gen.blockModules | true | Writes blocks/slices.ts with one config slice per block instance and blocks/permissions.ts; records import the slices of the blocks they bind. See Block modules |
gen.hooks | "react" with the next, react or expo adapter, otherwise false | Writes hooks.ts next to output with a list and a record data hook per table for "react", "vue", "svelte", "solid", "sveltekit", "tanstack-start" or "react-router"; false writes none; { framework, select: { module, export } } wraps each select in that export |
gen.clientBlocks | none | Block instances the browser client uses. gen writes blocks.client.ts with clientBlocks, defineBlocks over only those instances; without the key the browser client carries no block code |
gen.permissionCatalog | false | Writes the permission catalog of the installed blocks as a migration, with the default grants of the owner, admin and member roles, and permission-scopes.ts with apiKeyScopes and oauthScopes. Needs blocks.permissions.model: "catalog". See Permission catalog |
gen.entityPages | none | Entity page descriptors (defineEntityPage) and where the output goes. gen writes each page's list query, its /api/<name>/list route, a migration with the indexes of its sorts and facets and a scale_list_<name>.test.sql file. See Entity pages |
gen.serverBlocks | none | Named subsets of the installed instances for the server. gen writes blocks.<name>.ts with <name>Instances and <name>Blocks, defineBlocks over only those instances, and fails when a listed block requires a port no listed block provides. A route that builds its server from the set bundles those blocks and not the rest of blocks.generated.ts |
preset | unset | A named preset, a code from Create or its URL. defineConfig expands it into blocks, with the blocks they require, and its conventions (casing, database.sql.api, integrations); the keys you set win |
blocks | [] | The blocks to install and keep in sync, foundation blocks such as memberships and access included: a list of names, or an object keyed by block name whose values set its ownership, schema, table and column names, id type, permission keys, ownTablePolicies and options (existing tables). access also picks the access model |
database.sql | supabase/schemas, 900_better_supabase, supabase/tests | Where generated SQL and pgTAP files go, the schema and api every block inherits, the scope of blocks that set none. ownTablePolicies ('block' or 'app') sets whether blocks add their bsb_ policies on your own tables (keeping your own policies). tenantColumn (default tenant_id) names the tenant column of every block table (one tenant column name). workflow ('pg-delta', 'migra' or 'migrations', detected from config.toml when unset) picks how blocks reach a migration (Workflows) |
database.seed | supabase/seed.ts, supabase/seeds/000_better_supabase.sql | Entry module and output of seed |
api.specs | src/lib/openapi.ts, one OpenAPI 3.1 output at openapi.json, failOn: 'error' | Entry module, outputs (format, version, output, overlays, serialize, ui) failure level and manifest file of spec |
api.openapi | src/lib/openapi.ts, openapi.json | Deprecated alias of specs. Entry module and output of the OpenAPI document; spec reads them when specs is unset |
tooling.doctor | format: 'text' | ignore finding codes, strict mode, claimsLimit, policyHelperLimit, policies.max (the BS641 count), parallelReads (the BS609 count), sealTriggers (the functions that seal secrets, for BS352), migrationSafety.since (the last migration BS229 to BS235 skip offline), a baseline file of accepted findings, and the defaults of --only, --format and --out (only, format, output) |
gen | every configured task, watchInterval: 2000 | tasks gen runs (types, sql, spec, seed, env) and the watch interval, which dev and spec --watch read |
tooling.env | output: '.env.local', prefix from the framework | Defaults of env --out and --prefix (output, prefix; '' for no prefix) |
adapters | [] | The integrations init set up. add with no argument sets up the ones that have no files yet |
tooling.skills | detected agent folders | agents: the folders skills install writes to (cursor, claude, agents) |
tooling.keys | supabase/signing_keys.json | output: where keys writes the signing key |
$env, $ci, ... | none | Overrides per environment |
Flags and the config
Every option a command takes on each run has a config key, so the command line stays short and a fresh checkout behaves the same as yours. A value is picked in this order:
- the flag, for one run;
- the active environment block;
- the config;
- the default.
| Command | Config key |
|---|---|
gen | gen.tasks, gen.watchInterval |
dev env | tooling.env.file, .prefix, .map |
doctor | tooling.doctor.only, .format, .output |
spec | api.specs.manifest, gen.watchInterval |
add | adapters |
skills install | tooling.skills.agents |
dev keys | tooling.keys.file |
tooling.doctor.file applies when the report uses tooling.doctor.format, so
doctor --json prints to stdout even when the config writes SARIF to a
file. add prints the config entry for the flags you passed, so you can
paste it once instead of repeating them.
Environments
An environment block overrides part of the config for one environment. Name
blocks under $env, or use the $development, $production, $test and
$ci shorthands:
export default defineConfig({
gen: { casing: "camel" },
tooling: { doctor: { ignore: ["BS204"] } },
$ci: {
gen: { tasks: ["types", "sql", "spec"] },
tooling: {
doctor: { format: "sarif", file: "doctor.sarif", strict: true },
},
},
$env: {
staging: { database: { source: { projectRef: "abcdefghijklmnopqrst" } } },
},
});The CLI applies the block named by --env, then by $BETTER_SUPABASE_ENV,
and in CI ($CI is set) the ci block. When both $env.<name> and a
shorthand exist for the same name, the shorthand applies last. Objects merge
key by key, while lists and other values replace the base value: above, ci
keeps tooling.doctor.ignore and replaces gen.tasks. An environment without a
block uses the config as it is. A block can't hold another block.
Claims
The claims block names the claims every part of better-supabase reads, so a
rename happens in one place. The defaults are:
export default defineConfig({
auth: {
tenant: { claim: "tenant_id" },
claims: {
scope: "tenant", // memberships[].scope written by the tenant SQL module
features: "features", // plan features per tenant, from the entitlements module
memberships: "memberships", // the caller's memberships, from the tenant module or a provider's hook
permissions: "permissions", // permission keys per tenant, from permission_claims()
},
},
});gen writes the names that differ from the defaults into the generated
schema, and add and upgrade render them into the SQL modules. Run
both after changing the block.
An adapter that reads these claims itself takes the paths from claimPaths
in better-supabase/config instead of hardcoding them. DEFAULT_CLAIMS holds
the defaults:
import { claimPaths } from "better-supabase/config";
const paths = claimPaths(config.claims);
// { tenant: ["tenant_id", "app_metadata.tenant_id"], features: "features",
// memberships: "memberships", scope: "tenant", permissions: "permissions",
// permissionsTruncated: "permissions_truncated" }permissionsOf(session, tenant?) from better-supabase/next and
better-supabase/server reads the permissions claim for the active tenant.
It returns undefined when the claim is missing, has no entry for the tenant,
or the hook set permissions_truncated because the keys didn't fit; ask the
database (my_permissions) then. Pass { claim } when you renamed it.
supabase/config.toml
The CLI reads supabase/config.toml for the local database port, the auth
settings doctor checks, bucket drift, and the diff
engine when database.sql.workflow is unset ([experimental.pgdelta] and
[db.migrations] schema_paths). When
@supabase/config is
installed, it parses the file, with env() values filled in the same way the
Supabase CLI does. It's an optional peer (it needs effect and
@effect/platform-node). Without it, a built-in parser reads the subset of
TOML that supabase init wrote before CLI 3.4, which writes config.jsonc.
JSON configs
{
"$schema": "https://unpkg.com/better-supabase/schemas/config-v1.json",
"casing": "camel",
"plugins": { "timestamps": true }
}The JSON Schema gives editor completion and validation. It types each
block's options from the block's manifest, the same source that types
blocks.<name>.options in a TypeScript config, so an unknown block, an
unknown option or a value of the wrong kind is an error in both. Generators and
Standard Schema values in json[...].schema need a TypeScript or JavaScript
config; a JSON config can use plain JSON Schema objects.
Print the resolved config
pnpm better-supabase configconfig prints the file it loaded and the active environment, then the
config with every default filled in and that environment's block merged in,
as JSON (--json wraps them in one document, with environment set to the
name or null). better-supabase config --env ci shows what CI will see. Generators show as
their name and apiVersion, and the password in database.source.dbUrl is redacted.
Use it to check which file the CLI found and what an option resolved to.
config --preset prints the preset the config names instead, what it
resolves to, and how the config differs from it
(Reading a preset).
gen warns about tables and json keys that match nothing in the
configured schemas, such as a misspelled table name, instead of ignoring them.
Side effects: None.
List the actions
pnpm better-supabase config actions --jsonconfig actions lists every action better-supabase checks: each block
instance, record type, bucket and topic, with the permission key the action
resolves to and where the key came from. source is config when the config
names the key, provider when authorization.actionKeys does, and default
when the block derives it. key is null when nothing names a key for the
action, such as a topic's send that the provider doesn't list. The JSON has
version: 1 and a schema in
config-actions-v1.json.
Use it to check a provider's actionKeys against what the app asks for.
From code, listActions(config) in better-supabase/sql returns the same rows.
Side effects: None.
List the access policies
pnpm better-supabase config policies --jsonconfig policies lists one row per row level security policy that a
@bsb access tag in supabase/schemas renders: the table, the operation, the
policy name, the permission key, the tenant column and whether the policy
carries the actor guard. The tag's SQL is rendered from the same rows, so the
list and the SQL can't differ. The JSON has version: 1 and a schema in
config-policies-v1.json.
From code, listAccessPolicies(config, comments) in better-supabase/sql
returns the same rows for the table comments you pass.
Side effects: None.
List the functions
pnpm better-supabase config functions --allconfig functions gives every function of the read schemas one caller class,
checked in this order: policy (a policy expression calls it), trigger (it
returns trigger or a trigger runs it), app RPC (anon or authenticated
may execute it), service only (only service_role may) and unreferenced.
Without --all it prints the counts per schema:
better_supabase: 52 policy, 197 trigger, 2285 app RPC, 669 service only, 266 unreferenced
public: 0 policy, 1 trigger, 17 app RPC, 3 service only, 0 unreferencedA function that only other functions call shows as service only or
unreferenced, so read the list before you drop anything; the command changes
nothing. It reads the database (--db-url-stdin reads the connection string
from stdin, --project-ref a hosted project), or a snapshot saved by this
release or later with --snapshot. Doctor BS643 prints the same counts.
The JSON has version: 1 and a schema in
config-functions-v1.json.
From code, listFunctions(snapshot.extras.functionInventory) in
better-supabase/sql returns the same rows.
Side effects: Reads the database, calls the Supabase Management API with --project-ref.
Check functions before you share them
pnpm better-supabase config functions --shareable 'public.*_payload'--shareable <glob> runs doctor's BS430 check on
every function whose schema.name matches the glob (* matches any run of
characters; a name without a schema means public), whether or not the
provider's sharedFunctions lists it yet. It prints every reason a function
fails, then the functions it calls, checked the same way:
public.order_payload: shareable once sharedFunctions lists it (reads public.orders, public.order_lines)
public.page_payload: can't be shared (reads public.pages)
- it reads public.page_views, which the provider's tables don't share per tenant
public.visible_pages: shareable once sharedFunctions lists it (reads public.pages; filters by page.read)
1 of 2 can be shared.Each JSON entry has name, listed, reasons, reads, outside (the reads
that the entry or the provider doesn't allow), permissions (the literal keys
passed to the provider's permissionFilters) and calls. It needs an
authorization provider and changes nothing.
Custom generators
A generator is a plugin at apiVersion: 2. Build it with defineGenerator from
better-supabase/generators:
import { defineGenerator } from "better-supabase/generators";
export const tableList = defineGenerator({
name: "table-list",
version: "1.0.0",
pure: true,
generate: ({ model }) => [
{
path: "src/lib/tables.json",
contents: JSON.stringify(
model.tables.map((table) => ({
key: table.key,
columns: table.columns.map((column) => [column.app, column.tsType]),
})),
),
},
],
});A generator receives the schema metadata (meta), the typegen introspection,
config (the output paths, the casing and the json overrides, as plain data),
imports.runtime and model: the tables and enums gen emitted, with the
TypeScript type it wrote for each column after json overrides, codecs and enum
unions. Everything in the input is frozen data that structuredClone copies. The
generator returns files, and gen --check covers them too.
gen refuses a generator that targets another apiVersion, and the message
names what changed from version 1: config is a view instead of the resolved
config, imports.runtime replaces runtimeImport, relativeImport replaces
importPath, and provides: ["validators"] replaces the validators flag on a
file. A pure generator's files are cached in
node_modules/.cache/better-supabase/generators under its name, version, options
and input, so a second gen with the same schema doesn't run it again.
gen records the files it wrote in
node_modules/.cache/better-supabase/gen-manifest.json. When a later run no
longer writes one of them (you removed a generator or changed output), it
deletes the file and lists it as removed, and gen --check reports it as no
longer generated. Files that no earlier run wrote are never touched. Prove a
generator with testGeneratorPlugin.
Last updated on