Configuring Named Environments
Add anenvironments key to your supaschema.config.json. Each entry is a name of your choosing mapped to an object with a databaseUrl field:
local, dev, staging, preview, production, or feature-branch names).
Using Named Environments on the CLI
Pass the--env flag followed by the environment name to target a specific database:
--env flag.
URL Resolution Order
When supaschema needs a database URL, it checks the following sources in order, stopping at the first match:--database-url <url>CLI flag — an explicit connection string passed directly to the command--env <name>CLI flag — looks up the named environment insupaschema.config.jsonSUPASCHEMA_DATABASE_URLenvironment variable — a connection string set in the shell or CI environment- Supabase auto-discovery — reads
supabase/config.tomlto discover the local Supabase stack connection details
--database-url flag always wins, and the automatic Supabase discovery only fires when no other source is available.
Using the SUPASCHEMA_DATABASE_URL Environment Variable
For CI pipelines and scripts where you do not want to store connection strings in config files, set SUPASCHEMA_DATABASE_URL in the environment:
--env or --database-url flag is needed when the variable is set.
Supabase Auto-Discovery
If you are working with a local Supabase stack and have not configured any URL, supaschema reads yoursupabase/config.toml to discover the database connection automatically:
db.port and db.password values from config.toml and constructs the connection string for you. This means a freshly initialized Supabase project works out of the box with zero URL configuration.
Auto-discovery only works with a running local Supabase stack. If the
containers are not running, start them with
supabase start before running
any supaschema commands.Security Considerations
Follow these practices to keep credentials safe:- Local development — the default Supabase local connection string (
postgres:postgres@localhost:54322) carries no sensitive credentials and is safe to commit. - Staging and production — store connection strings in
SUPASCHEMA_DATABASE_URLor your CI secret manager (GitHub Actions secrets, Vault, AWS Secrets Manager, etc.) and inject them at runtime. .envfiles — if you use a.envfile to setSUPASCHEMA_DATABASE_URLlocally, add.envto.gitignoreand provide a.env.examplewith placeholder values for new contributors.- Read-only roles — for commands that only read schema state (like
diffin check mode), consider using a read-only database role to limit the blast radius of an accidentally exposed URL.