Presets and blocks
Apply a preset to an existing project, map blocks onto tables it already has, read a preset or design, and find the blocks to add.
add --preset applies a preset to
the project you have, add --adopt maps a block onto tables you already
have, and blocks reads the block catalog. To start a new project from a
preset, use init --preset.
Applying a preset
pnpm better-supabase add --preset crm
pnpm better-supabase add --preset 1pWEF3d578B1iGt16 --dry-run
pnpm better-supabase add --preset crm --only blocksadd --preset edits the config file you have. By default it sets preset to the
named preset or the code, replacing the one the config has, so
defineConfig expands it into blocks and the conventions while your own
keys keep winning. It prints the diff of the config file, then loads the
config again and writes the module files of every block it now holds, as
better-supabase upgrade does. --dry-run prints the diff and writes
nothing, and --check exits 1 with the diff when the config doesn't hold the
preset yet.
Value of --only | What add --preset changes |
|---|---|
| unset | preset: the preset's blocks and its conventions |
blocks | blocks: the preset's blocks and what they require, listed by name; preset stays as it is |
conventions | preset: a code with the preset's conventions and no blocks |
With a Create URL that holds a design (&design=), add --preset also merges the
design into the config: each table in tables, replacing a table of the
same name and keeping the others, and each block's extra columns over the
Quote the URL. --only conventions
leaves the design out. A design too large for a URL comes as a design file
from Create; pass its path instead of the URL:
pnpm better-supabase add --preset ./better-supabase.design.jsonSee init for what a design holds.
The convention flags (--casing, --scope,
--tenant-name, --access, --id-type and --api) override that
convention of the preset, and add --preset writes the changed code. --only blocks takes none of them.
In a workspace, --package <dir> edits the config of that package instead
of the one at --cwd; a Create URL with &package= sets it too. A URL with
&authz= makes add --preset print a note: the authorization library you picked on
Create isn't part of the preset, so set it up from Get code.
pnpm better-supabase add --preset crm --scope user --api apiTables in a design
A design's tables are SQL files you own (ADR 0102). init --preset and
add --preset write each table as supabase/schemas/public/tables/<name>.sql,
with its features as @bsb tags in the table comment, and leave the config
without a tables key. A file that exists stays as it is, so a table you edited
is never overwritten, and a table the design leaves out is never dropped. To
change a table the design already created, edit its SQL and run db diff:
renames, retypes and dropped columns are planned as migrations there, with
their data loss reported.
diffAppTables and diffDesigns from better-supabase/preset still compare two
designs, and Create shows the result on the Changes tab of Get code.
Doctor's BS228 reports a column whose type or
nullability in the database has drifted from the table's SQL.
Adopting existing tables
pnpm better-supabase add --preset crm --only blocks --adopt --dry-runWith --adopt, add --preset reads the tables in the database and looks for each
block's tables under their default names (teams and team_members for
teams). For every block it finds there, it writes the tables and
columns of blocks.<block>, so the block
runs over your tables: tables
names the existing tables, columns the columns that differ from the
defaults, and an optional column the table lacks maps to null. It writes
no ownership. The proposed mapping of each block is printed before the
diff, so --dry-run shows both. Blocks with no existing table are left as
they are, and so is a block in custom ownership.
When a block has a table under a default name that the block can't run
over, for example because a value it writes doesn't fit a column,
add --preset writes nothing and prints why. Change the column, map the
block with better-supabase add --adopt, or leave the block out of the
preset. A required column the table lacks is a warning, because the block's
migration adds it.
--adopt reads the tables where gen does: the config's source,
$DATABASE_URL, $SUPABASE_DB_URL or the local stack, or --snapshot,
--db-url-stdin and --project-ref.
A preset that can't install stops add --preset with the reason. When the config
isn't an object literal add --preset can follow, it changes nothing and prints the
preset entry to set yourself. Without a config file, add --preset points to
init --preset.
Adopting tables
pnpm better-supabase add --adopt teams --tables public.squads --dry-run
pnpm better-supabase add --adopt audit --tables public.audit_logs
pnpm better-supabase add --adopt tags --tables app.labels,app.label_links --jsonadd --adopt <block> maps one block onto tables the app already has and writes the
proposed tables and columns of blocks.<block>; it writes no
ownership, because a managed block
runs over every table your schema already has.
Each table in --tables
(table or schema.table, comma-separated or repeated) goes to the block's
logical table whose columns it matches best; the block's other tables are
looked up by their default names, and the ones the app doesn't have are left
for the block to create. Each logical column then takes the column
of the same name, or a likely rename: organization_id for tenant,
position for rank, recipient_user_id for user. Those guesses are
marked in the output, so check them before you keep the entry. When the
tenant column is a bigint, text or integer, the entry sets idType
too.
The output lists every logical table and column with what it maps to, then
a report like doctor's: errors for what can't map (none of the block's
tables found, a value the module refuses) and warnings for a required column
the table lacks, which the block's migration adds, and for the
migration-only options the entry keeps. With an error add --adopt exits
1 and writes nothing. Otherwise it prints the diff of the config and writes
it; --dry-run writes nothing, and --check exits 1 when the config doesn't
hold the mapping yet. Run better-supabase upgrade afterwards to
write the block's module over your tables; Your own schemas
describes what it writes there. --json prints the entry,
the mapping and the report as data. The tables are read like gen
reads them, with --snapshot, --db-url-stdin and --project-ref.
A block that creates all its tables can't be mapped; the error lists the blocks that can run over yours.
Without a block, add --adopt writes the data migration instead: the rows
and settings of the installed blocks that a schema diff skips
(SQL modules).
Reading a preset
pnpm better-supabase blocks list --preset crm
pnpm better-supabase blocks list --preset "https://app.bettersupabase.com/create?design=0..."
pnpm better-supabase config --presetblocks list --preset takes a name, a design code or a /create URL and
prints the preset's name (or custom), its conventions, every block it
installs with the reason it is there, and anything that can't install, which
exits 1. A 0.14 preset code stops with the reason and names
better-supabase codemod 0.15.
config --preset reads the preset of the config and prints the same, then
how the config differs from it: the blocks it adds (+), a casing that
differs, and the preset blocks it gives settings of its own (~).
Neither command changes anything.
blocks
pnpm better-supabase blocks list
pnpm better-supabase blocks list --category crm
pnpm better-supabase blocks view comments
pnpm better-supabase blocks search invoiceblocks list prints every block by category, and --category keeps one
(identity, tenancy, collaboration, messaging, growth, crm,
work, people, commerce, scheduling, content, ai, automation,
developer, admin or database). blocks view prints one
block: what it requires, what it works with, its modes, its client
subpath, the better-supabase add command and its registry glue.
blocks search matches the name, the title and the description. Each one
reads the same catalog as /blocks and
--json prints it as data.
pnpm better-supabase blocks list --installed
pnpm better-supabase blocks view audit --sqlblocks list --installed lists the blocks in your config with the version
each one has in the database files and whether upgrade has steps for it.
--tests-dir <dir> reads the pgTAP files from another folder than
database.sql.testsDir. blocks view --sql prints the SQL add would write
for the block with your config, and writes nothing. blocks list --preset
reads a preset, as above.
| Command | Side effects |
|---|---|
blocks list | None. |
blocks view | None. |
blocks search | None. |
Last updated on