mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
## I have read the CONTRIBUTING.md file. YES ## What kind of change does this PR introduce? Docs. A new guide for `supabase config diff`, `config pull`, and `config push`, written for CLI v3. Relates to MARKET-1590. ## What is the current behavior? The CLI reference lists the three commands, but no guide explains the workflow. The Select 2026 recap blog tells users to run `config pull` with nothing to link to. ## What is the new behavior? - New guide at `/docs/guides/local-development/config-as-code`, in the nav after "Managing config and secrets". - Covers diff (labels, `--exit-code` for CI), pull (preview, git check, where values go), push (one consent question, `--yes` for CI and agents, the `init` defaults risk), and what push can and cannot write. - Links to `local-and-hosted-projects` and `migrating-to-v3` for the shared v3 target and consent rules. ## Additional context All behavior claims are checked against `supabase/cli` `v3.4.0`. **Related:** #50594 by @Sweta0519 adds a `config push` section to `managing-config.mdx`. This guide includes its `[group-write]` and `init` defaults points, with credit. It might be good to ask if we can shrink #50594 to a short pointer to this guide, so the two do not repeat each other. **Needs review:** one inline `NEEDS REVIEW` comment. "The Dashboard stays editable" is product intent from the PRFAQ, not confirmed in platform code. **Verified:** MDX compiles, internal links and anchors resolve, and the preview page returns 200 and shows in the nav. | Before (net-new page) | [After (PR preview)](https://docs-git-nikrichers-market-1590-launch-config-d-a8be81-supabase.vercel.app/docs/guides/local-development/config-as-code) | | ------------------------------ | --- | | _No production URL, new page._ |  | 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Nik Richers <nik@validmind.ai> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
198 lines
12 KiB
Plaintext
198 lines
12 KiB
Plaintext
---
|
|
id: 'config-as-code'
|
|
title: 'Managing remote config as code'
|
|
description: "Keep a hosted project's settings in your config file and sync them with the CLI using config diff, pull, and push."
|
|
subtitle: "Keep a hosted project's settings in your config file and sync them with the CLI using config diff, pull, and push."
|
|
---
|
|
|
|
Your config file (`supabase/config.toml` or `supabase/config.jsonc`) already defines your local stack. The `supabase config` commands use the same file for a hosted project: `diff` shows what differs, `pull` copies the project's settings into the file, and `push` applies the file to the project. Your project settings then go through review like the rest of your code.
|
|
|
|
For the local stack and `env()` secrets, refer to [Managing config and secrets](/docs/guides/local-development/managing-config). For every key the file supports, refer to the [CLI config reference](/docs/guides/local-development/cli/config).
|
|
|
|
<Admonition type="note" label="What the config commands change">
|
|
|
|
The `config` commands change **project settings**, such as Auth, Storage, the Data API, and database settings. They do not change your schema or data. For schema, use `db diff`, `db pull`, and `db push` with migrations. Refer to [Local development workflow](/docs/guides/local-development/cli-workflows).
|
|
|
|
</Admonition>
|
|
|
|
<Admonition type="note" label="CLI v3">
|
|
|
|
This guide uses CLI v3 syntax. In v2, the `config` commands used `--project-ref` instead of `--remote`, and `config push` asked once for each resource. Refer to [Migrating to CLI v3](/docs/guides/local-development/cli/migrating-to-v3).
|
|
|
|
</Admonition>
|
|
|
|
## Before you begin
|
|
|
|
Install the CLI, log in, and link a project:
|
|
|
|
```bash
|
|
supabase login
|
|
supabase link YOUR_PROJECT_REF
|
|
```
|
|
|
|
Replace `YOUR_PROJECT_REF` with your project ref, from the Dashboard URL: `https://supabase.com/dashboard/project/YOUR_PROJECT_REF`. With no flag, the `config` commands use `SUPABASE_PROJECT_ID` if it is set, and the linked project if it is not. To target another project or a branch, refer to [Targeting a branch](#targeting-a-branch).
|
|
|
|
<Admonition type="note" label="`supabase` vs. `npx supabase`">
|
|
|
|
The examples use `supabase <command>`, which works when you install the CLI with Homebrew or Scoop. If you added the CLI as a project dependency, run it through your package runner, for example `npx supabase <command>`, `pnpm supabase`, `yarn supabase`, or `bunx supabase`.
|
|
|
|
</Admonition>
|
|
|
|
### Secrets and environment variables
|
|
|
|
Do not put secret values in your config file. Reference them with `env()`, as described in [Managing config and secrets](/docs/guides/local-development/managing-config). For branches, refer to [Managing secrets for branches](/docs/guides/deployment/branching/configuration#managing-secrets-for-branches).
|
|
|
|
- `config diff` and `config pull` never read secret values. The platform masks them, and the CLI prints a `Note:` that lists the masked keys.
|
|
- `config pull` skips `env()` references, so it does not replace them with literal values.
|
|
- `config push` resolves each declared secret and sends it only when it differs from the hosted value.
|
|
|
|
### Values from environment variables
|
|
|
|
Environment variables can override values in your file. `config diff` labels each override, for example `(from SUPABASE_AUTH_SITE_URL in supabase/.env.local)`, and `config push` prints `Pushing N values set by environment variables: …` before it asks. The local side of `config diff` is what `config push` sends. Refer to [Seeing where a value came from](/docs/guides/local-development/local-and-hosted-projects#value-origin).
|
|
|
|
## Key commands at a glance
|
|
|
|
Use these commands to compare, pull, and push project settings:
|
|
|
|
| Command | What it does |
|
|
| ----------------------------------------------------- | -------------------------------------------------------------------- |
|
|
| `supabase config diff` | Shows differences between your config file and a project (read-only) |
|
|
| `supabase config diff --exit-code` | Same, but exits `2` when it finds a difference (for CI) |
|
|
| `supabase config pull` | Writes a project's settings into your config file |
|
|
| `supabase config pull --dry-run` | Shows what a pull writes, without writing |
|
|
| `supabase config push` | Applies the settings your file declares to a project |
|
|
| `--remote=YOUR_PROJECT_REF` or `--remote=YOUR_BRANCH` | Targets another project or a branch (all three commands) |
|
|
|
|
## See what differs
|
|
|
|
`supabase config diff` compares your config file with a hosted project. It never changes your file or the project.
|
|
|
|
```bash
|
|
supabase config diff
|
|
supabase config diff --remote=staging
|
|
```
|
|
|
|
The CLI labels each difference:
|
|
|
|
- `[update]`: the setting is in both, with different values.
|
|
- `[remote-only]`: the setting is on the project but not in your file. The label also marks an undeclared setting whose hosted value differs from the default.
|
|
- `[local-only]`: the setting is in your file but not on the project.
|
|
|
|
Local-stack sections, such as `[studio]`, `[analytics]`, `[realtime]`, and ports, never show as differences. `db.major_version` and `[db.pooler]` do show, but `config push` cannot write them. Change those in the Dashboard.
|
|
|
|
### Checking for drift in CI
|
|
|
|
With `--exit-code`, `config diff` exits with status `2` when it finds a difference, and `1` on an error. A CI job can then fail when a project drifts from your repo:
|
|
|
|
```bash
|
|
supabase config diff --remote=YOUR_PROJECT_REF --exit-code
|
|
```
|
|
|
|
For machine-readable output, add `--output-format json` or `--output-format stream-json`.
|
|
|
|
## Pull remote config into your file
|
|
|
|
`supabase config pull` writes a project's current settings into your config file. Use it to start from an existing project, or to bring in a change that someone made in the Dashboard.
|
|
|
|
```bash
|
|
supabase config pull --dry-run
|
|
supabase config pull
|
|
supabase config pull --remote=staging
|
|
```
|
|
|
|
- **Preview.** `--dry-run` lists each difference and whether pull writes or skips it. It writes nothing and asks nothing.
|
|
- **Confirmation.** In a terminal, pull asks first, and the default answer is Yes. With JSON output, pull takes the default without asking. Otherwise, pull reads one line from stdin: `y` or `yes` writes, empty input takes the default, and any other answer declines.
|
|
- **Small edits.** Pull changes only the values that differ, and keeps your comments, ordering, and other keys. Small edits work in `config.toml`, `config.json`, and `config.jsonc`.
|
|
- **Uncommitted changes.** If your config file has uncommitted git changes, pull warns you, and the default answer changes to No. With `--yes`, JSON output, or no terminal, pull fails instead. `--force` skips the check.
|
|
- **Secrets.** Pull never writes secret values.
|
|
|
|
<Admonition type="note" label="Where pulled values go">
|
|
|
|
Pull writes to the first match in this list:
|
|
|
|
1. `[remotes.<name>]`, when you pass `--remote-label <name>`.
|
|
2. A `[remotes.<name>]` block whose `project_id` matches the target.
|
|
3. A new `[remotes.<branch-name>]` block at the end of the file, when you target a branch by name or UUID (not by project ref). A UUID target names the block after the branch's project ref.
|
|
4. The top level of the file.
|
|
|
|
A top-level write also changes `supabase start` settings, such as `auth.site_url` and `db.major_version`, and pull warns when it does. To write to a `[remotes]` block instead, pass `--remote-label`.
|
|
|
|
Refer to [Branch configuration](/docs/guides/deployment/branching/configuration) for how `[remotes]` blocks work.
|
|
|
|
</Admonition>
|
|
|
|
## Push local config to a project
|
|
|
|
`supabase config push` applies the settings your config file declares to the target project.
|
|
|
|
```bash
|
|
supabase config push
|
|
supabase config push --remote=staging
|
|
```
|
|
|
|
Push compares your file with the project and sends only the values that differ. Settings that your file does not declare keep their hosted values. Some settings, such as SMTP or an OAuth provider, must be sent as a group. When one value in a group changes, push sends the group and uses the hosted values for the rest.
|
|
|
|
Push prints the diff for each resource, then asks one question that names the resources and the target. The default answer is No.
|
|
|
|
<Admonition type="caution" label="Preview before you push">
|
|
|
|
`config push` has no `--dry-run` flag. Run `supabase config diff` first and review the output.
|
|
|
|
The file that `supabase init` creates holds local development values, such as `site_url = "http://127.0.0.1:3000"` and OAuth providers with `enabled = false`. If you push that file unchanged, those values replace your hosted settings. For an existing project, run `supabase config pull` before your first push.
|
|
|
|
</Admonition>
|
|
|
|
### Pushing from CI or an agent
|
|
|
|
Push asks only in a terminal with text output, and never when an AI coding agent runs it. In any other run, push fails before it changes anything, unless you pass `--yes`:
|
|
|
|
```bash
|
|
supabase config push --remote=YOUR_PROJECT_REF --yes
|
|
```
|
|
|
|
You can also export `SUPABASE_YES=1` in your shell. `SUPABASE_YES` in a `.env` file does not count, and piped input such as `echo y |` does not confirm anything. Refer to [When the CLI can't ask](/docs/guides/local-development/local-and-hosted-projects#cannot-ask).
|
|
|
|
### What `config push` can write
|
|
|
|
Push writes these sections, in this order:
|
|
|
|
| Area | Config section | Notes |
|
|
| -------------------- | --------------------------- | ----------------------------------------------------------------- |
|
|
| Data API (PostgREST) | `[api]` | |
|
|
| Database settings | `[db.settings]` | |
|
|
| Network restrictions | `[db.network_restrictions]` | Only when `enabled = true` |
|
|
| SSL enforcement | `[db.ssl_enforcement]` | Only when the section is in your file |
|
|
| Auth | `[auth]` | Includes providers, email templates, and `[auth.oauth_server]` |
|
|
| Storage | `[storage]` | Includes S3 protocol, image transformation, analytics, and vector |
|
|
| Database webhooks | `[experimental.webhooks]` | Enable only |
|
|
|
|
Push does **not** write other settings, such as the database major version, `[db.pooler]`, compute size, and custom domains, even when they are valid in the file. Change those settings in the Dashboard. For Storage buckets and Edge Functions, use `supabase seed buckets` and `supabase functions deploy`.
|
|
|
|
When a push enables a paid add-on, such as phone MFA, it prints the cost before it asks.
|
|
|
|
<Admonition type="note" label="The Dashboard stays editable">
|
|
|
|
You can still change settings in the Dashboard. A Dashboard change shows in the next `config diff`, and `config pull` adds it to your file. A `config push` replaces the hosted value with the value in your file, so pull Dashboard changes before you push.
|
|
|
|
</Admonition>
|
|
|
|
## Targeting a branch
|
|
|
|
All three commands accept `--remote=YOUR_TARGET`. `YOUR_TARGET` is a project ref, or the name or UUID of a branch of the linked project. A value of exactly 20 lowercase letters is always a project ref.
|
|
|
|
```bash
|
|
supabase config diff --remote=my-preview-branch
|
|
supabase config pull --remote=my-preview-branch
|
|
supabase config push --remote=my-preview-branch
|
|
```
|
|
|
|
Use `=`. A bare `--remote` means the linked project, and it does not read the next word as its value.
|
|
|
|
To link the CLI to a branch instead, run `supabase link my-preview-branch`.
|
|
|
|
## Deploying config on merge
|
|
|
|
If you use [Branching](/docs/guides/deployment/branching) with the GitHub integration, you do not need `config push` for branches. When you push a config change to git, the integration applies it to the matching Supabase branch. To give a persistent branch its own settings, add a `[remotes.<name>]` block with that branch's project ref as `project_id`. Refer to [Branch configuration](/docs/guides/deployment/branching/configuration) and the [GitHub integration](/docs/guides/deployment/branching/github-integration).
|
|
|
|
For every command and flag, refer to the [CLI reference](/docs/reference/cli).
|