Files
supabase/apps/docs/content/guides/deployment/branching/configuration.mdx
Colum Ferry 95cf9a78a7 docs(cli): show config examples in TOML and JSONC (#53449)
## Problem

The CLI reads `supabase/config.jsonc` (and `config.json`) since v3.1.0,
but every docs page still shows `config.toml` only. There's also no page
explaining the formats, how to switch, the `$schema` / `#:schema`
declaration, or editor setup, and no reference pages for the new
`supabase config convert` and `supabase config validate` commands.

Linear: CLI-2871

## Solution

- **Dual-format examples from one source.** A new directive
(`features/directives/ConfigFormats.ts`) picks up any ```` ```toml ````
fence with `name=supabase/config.toml` and renders it as
`supabase/config.toml` / `supabase/config.jsonc` tabs. The JSONC is
generated at build time with `convertCliConfigTomlToJsonc` from
`@supabase/config`, the same converter `supabase config convert` uses,
so authors only write TOML and the JSONC matches what the CLI would
produce (comments included). Inside `<$CodeTabs>` the JSONC is added as
an extra tab.
- **The format choice sticks.** `ConfigCodeTabs` keeps the selected
format in `localStorage`, so choosing JSONC switches every config
example on the page and on later pages.
- **Config reference.** The `usage` examples on
`/guides/local-development/cli/config` use the same tabs (they were
highlighted as Python before), and the intro mentions `config.jsonc`.
The `remotes.<branch_name>` example now uses `[remotes.staging]`, since
`<branch_name>` isn't a valid TOML key.
- **New guide, "Config file formats"**
(`/guides/local-development/cli/config-formats`): which file wins,
minimum CLI version, `convert` and `validate`, schema declaration and
versioning, and editor setup (VS Code trusted domains, Even Better TOML,
Tombi, SchemaStore).
- **CLI reference.** Adds `supabase-config-convert` and
`supabase-config-validate` to the CLI reference nav.
`cli_v1_commands.yaml` is the generated v3.2.0 reference, identical to
the release bot's update in #53463, so the two PRs don't conflict.
- **Content.** About 60 existing config examples across the guides,
including the Branching configuration page, are tagged
`name=supabase/config.toml`. Branching reads `config.json` and
`config.jsonc` as well, and the Branching configuration page now says
so. Non-Supabase TOML (`pyproject.toml`, `bunfig.toml`) and the v2-era
`[inbucket]` before/after snippet stay TOML-only.
- **Format-neutral prose.** Sentences that described the config as
`config.toml` now say "your config file", naming `supabase/config.toml`
and `supabase/config.jsonc` once per page. TOML section syntax in prose
(`max_frequency` under `[auth.email]`) is written as key paths
(`auth.email.max_frequency`), which read the same in both formats.
Headings that named `config.toml` keep their old anchors. Sentences
about what `supabase init` creates still say `config.toml`.
- **Markdown export for agents.**
`internals/generate-guides-markdown.ts` runs the same transform, so the
`.md` pages served to AI agents include the JSONC example after each
TOML one.
- A test converts every tagged example under `content/`, so a broken
TOML example fails tests instead of the build.

New dependencies for `apps/docs`: `@supabase/config` (^1.8.0) and
`effect` (the same `effect` version Studio pins).

`config convert` and `config validate` ship in CLI v3.2.0, which is now
stable.

## Review instructions

1. Open `/docs/guides/local-development/seeding-your-database` on the
preview. Switch an example to `supabase/config.jsonc` and check the
other examples on the page switch too.
2. Open `/docs/guides/local-development/cli/config` and check the usage
examples open on JSONC.
3. Read `/docs/guides/local-development/cli/config-formats`.
4. Open `/docs/reference/cli/supabase-config-convert` and
`/docs/reference/cli/supabase-config-validate`.

## Self-review

Ran the `review-the-docs` local self-review (content, pipeline, and
component checks) over the 54 changed pages.

- No blockers. Fixed the nits it found: leftover TOML section syntax in
prose (diff engines, declarative schemas, Branching, the common settings
table on Local and hosted projects), a few long or ungrammatical
sentences, and the conversion follow-up steps on Config file formats,
now a list.
- Links, custom anchors, nav wiring, and frontmatter check out.
- The `.md` export on the preview shows each TOML example followed by
its JSONC version.
- `test-the-docs` deferred: the changed fences are config snippets, and
`ConfigFormats.test.ts` already converts every tagged example. No
procedural steps changed apart from the `config convert` and `config
validate` commands on the new page.

## Checklist

Check all before review:

- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [x] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs
[style
guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
2026-11-20 14:34:59 +00:00

300 lines
9.0 KiB
Plaintext

---
title: 'Configuration'
subtitle: 'Configure your Supabase branches using configuration as code'
---
This guide covers how to configure your Supabase branches, using your config file (`supabase/config.toml` or `supabase/config.jsonc`). In one single file, you can configure all your branches, including branch settings and secrets.
To switch formats, see [Config file formats](/docs/guides/local-development/cli/config-formats).
## Branch configuration with remotes
When Branching is enabled, your config settings automatically sync to all ephemeral branches through a one-to-one mapping between your Git and Supabase branches.
### Basic configuration
To update configuration for a Supabase branch, modify your config file and push to git. The Supabase integration will detect the changes and apply them to the corresponding branch.
### Remote-specific configuration
For persistent branches that need specific settings, you can use a `remotes` entry in your config file. Each remote configuration must reference an existing project ID.
Here's an example of configuring a separate seed script for a staging environment:
```toml supabase/config.toml
[remotes.staging]
project_id = "your-project-ref"
[remotes.staging.db.seed]
enabled = true
sql_paths = ["./seeds/staging.sql"]
```
Since the `project_id` field must reference an existing branch, you need to create the persistent branch before adding its configuration. Use the CLI to create a persistent branch first:
```bash
supabase --experimental branches create --persistent
# Do you want to create a branch named develop? [Y/n]
```
<Admonition type="note">
To retrieve the project ID for an existing branch, use the `branches list` command:
```bash
supabase --experimental branches list
```
This will display a table showing all your branches with their corresponding project ID.
Use the value from the `BRANCH PROJECT ID` column as your `project_id` in the remote configuration.
</Admonition>
### Configuration merging
When merging a PR into a persistent branch, the Supabase integration:
1. Checks for configuration changes
2. Logs the changes
3. Applies them to the target remote
If no remote is declared or the project ID is incorrect, the configuration step is skipped.
### Available configuration options
All standard configuration options are available in a `remotes` entry. This includes:
- Database settings
- API configurations
- [Authentication](/docs/guides/auth) settings
- [Edge Functions](/docs/guides/functions) configuration
- And more
You can use this to maintain different configurations for different environments while keeping them all in version control.
## Managing secrets for branches
For sensitive configuration like SMTP credentials or API keys, you can use the [Supabase CLI](/docs/guides/local-development/cli/getting-started) to manage secrets for your branches. This is especially useful for [custom SMTP](/docs/guides/auth/auth-smtp) setup or other services that require secure credentials.
To set secrets for a persistent branch:
```bash
# Set secrets from a .env file
supabase secrets set --env-file ./supabase/.env
# Or set individual secrets
supabase secrets set SMTP_HOST=smtp.example.com
supabase secrets set SMTP_USER=your-username
supabase secrets set SMTP_PASSWORD=your-password
```
These secrets will be available to your branch's services and can be used in your configuration. For example, in your config file:
```toml supabase/config.toml
[auth.smtp]
host = "env(SMTP_HOST)"
user = "env(SMTP_USER)"
password = "env(SMTP_PASSWORD)"
```
<Admonition type="note" title="Secrets are branch-specific">
Secrets set for one branch are not automatically available in other branches. You'll need to set them separately for each branch that needs them.
</Admonition>
### Using dotenvx for git-based workflow
For managing environment variables across different branches, you can use [dotenvx](https://dotenvx.com/) to securely manage your configurations. This approach is particularly useful for teams working with Git branches and preview deployments.
#### Environment file structure
Following the conventions used in the [example repository](https://github.com/supabase/supabase/blob/master/examples/slack-clone/nextjs-slack-clone-dotenvx/README.md), environments are configured using dotenv files in the `supabase` directory:
| File | Environment | `.gitignore` it? | Encrypted |
| --------------- | ----------- | ---------------- | --------- |
| .env.keys | All | Yes | No |
| .env.local | Local | Yes | No |
| .env.production | Production | No | Yes |
| .env.preview | Branches | No | Yes |
| .env | Any | Maybe | Yes |
#### Setting up encrypted secrets
1. Generate key pair and encrypt your secrets:
```bash
npx @dotenvx/dotenvx set SUPABASE_AUTH_EXTERNAL_GITHUB_SECRET "<your-secret>" -f supabase/.env.preview
```
This creates a new encryption key in `supabase/.env.preview` and a new decryption key in `supabase/.env.keys`.
2. Update project secrets:
```bash
npx supabase secrets set --env-file supabase/.env.keys
```
3. Choose your configuration approach in your config file:
Option A: Use encrypted values directly:
```toml supabase/config.toml
[auth.external.github]
enabled = true
secret = "encrypted:<encrypted-value>"
```
Option B: Use environment variables:
```toml supabase/config.toml
[auth.external.github]
enabled = true
client_id = "env(SUPABASE_AUTH_EXTERNAL_GITHUB_CLIENT_ID)"
secret = "env(SUPABASE_AUTH_EXTERNAL_GITHUB_SECRET)"
```
<Admonition type="note" title="Secret fields">
The `encrypted:` syntax only works for designated "secret" fields in the configuration. Using encrypted values in other fields will not be automatically decrypted and may cause issues. For non-secret fields, use environment variables with the `env()` syntax instead.
The following fields support the `encrypted:` syntax:
**Studio**
- `studio.openai_api_key`
**Database**
- `db.root_key`
- `db.vault.*` (any key in the vault map)
**Auth - Core Keys**
- `auth.publishable_key`
- `auth.secret_key`
- `auth.jwt_secret`
**Auth - Email (SMTP)**
- `auth.email.smtp.pass`
**Auth - Captcha**
- `auth.captcha.secret`
**Auth - Hooks**
- `auth.hook.mfa_verification_attempt.secrets`
- `auth.hook.password_verification_attempt.secrets`
- `auth.hook.custom_access_token.secrets`
- `auth.hook.send_sms.secrets`
- `auth.hook.send_email.secrets`
- `auth.hook.before_user_created.secrets`
**Auth - SMS Providers**
- `auth.sms.twilio.auth_token`
- `auth.sms.twilio_verify.auth_token`
- `auth.sms.messagebird.access_key`
- `auth.sms.textlocal.api_key`
- `auth.sms.vonage.api_secret`
**Auth - External OAuth Providers**
- `auth.external.*.secret`
**Edge Runtime**
- `edge_runtime.secrets.*` (any key in the secrets map)
</Admonition>
#### Using with preview branches
When you commit your `.env.preview` file with encrypted values, the branching executor will automatically retrieve and use these values when deploying your branch. This allows you to maintain different configurations for different branches while keeping sensitive information secure.
## Configuration examples
### Multi-environment setup
Here's an example of a complete multi-environment configuration:
```toml supabase/config.toml
# Default configuration for all branches
[api]
enabled = true
port = 54321
schemas = ["public", "storage", "graphql_public"]
[db]
port = 54322
pool_size = 10
# Staging-specific configuration
[remotes.staging]
project_id = "staging-project-ref"
[remotes.staging.api]
max_rows = 1000
[remotes.staging.db.seed]
sql_paths = ["./seeds/staging.sql"]
# Production-specific configuration
[remotes.production]
project_id = "prod-project-ref"
[remotes.production.api]
max_rows = 500
[remotes.production.db]
pool_size = 25
```
<Admonition type="note">
To retrieve the project ID for an existing branch, use the `branches list` command:
```bash
supabase --experimental branches list
```
This will display a table showing all your branches with their corresponding project ID.
Use the value from the `BRANCH PROJECT ID` column as your `project_id` in the remote configuration.
</Admonition>
### Feature branch configuration
For feature branches that need specific settings:
```toml supabase/config.toml
[remotes.feature-oauth]
project_id = "feature-branch-ref"
[remotes.feature-oauth.auth.external.google]
enabled = true
client_id = "env(GOOGLE_CLIENT_ID)"
secret = "env(GOOGLE_CLIENT_SECRET)"
```
<Admonition type="note">
To retrieve the project ID for an existing branch, use the `branches list` command:
```bash
supabase --experimental branches list
```
This will display a table showing all your branches with their corresponding project ID.
Use the value from the `BRANCH PROJECT ID` column as your `project_id` in the remote configuration.
</Admonition>
## Next steps
- Explore [branching integrations](/docs/guides/deployment/branching/integrations)
- Learn about [troubleshooting branches](/docs/guides/deployment/branching/troubleshooting)
- Review [branching pricing](/docs/guides/platform/manage-your-usage/branching#pricing)