SU

supabase-multi-env-setup

Standardizes a multi-environment architecture for Supabase, ensuring safe migration promotion and environment-specific secret management.

Install

mkdir -p .claude/skills/supabase-multi-env-setup && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/6631" && unzip -o skill.zip -d .claude/skills/supabase-multi-env-setup && rm skill.zip

Installs to .claude/skills/supabase-multi-env-setup

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Configure Supabase across development, staging, and production with separate projects, environment-specific secrets, and safe migration promotion. Use when setting up multi-environment deployments, isolating dev from prod data, configuring per-environment Supabase projects, or promoting migrations through environments. Trigger with "supabase environments", "supabase staging", "supabase dev prod", "supabase multi-project", "supabase env config", "database branching".
470 chars✓ has a “when” triggerlonger than Claude Code's old 250-char listing cap (fine on current versions)
Advanced

Key capabilities

  • Configure isolated projects for dev, staging, and production
  • Manage environment-specific secrets and configurations
  • Promote migrations safely across environments
  • Implement production safeguards for destructive operations
  • Create preview environments via database branching

How it works

It establishes a multi-project architecture where each environment is isolated, and schema changes are promoted sequentially using the CLI.

Inputs & outputs

You give it
Environment-specific configuration and migration files
You get back
Isolated, environment-aware deployment pipeline

When to use supabase-multi-env-setup

  • Setting up staging and production environments
  • Configuring per-environment secrets
  • Promoting database migrations safely
  • Implementing preview deployments with database branching

About this skill

Supabase Multi-Environment Setup

Overview

Production Supabase deployments require a separate project per environment — each with its own URL, API keys, database, and RLS policies. This skill configures a three-tier architecture (local dev, staging, production) with safe migration promotion via supabase db push, environment-aware createClient initialization, database branching for preview deployments, and CI/CD that prevents accidental cross-environment operations.

When to use: setting up a new project with multiple environments, migrating from a single-project setup, adding staging to an existing dev/prod split, or configuring preview environments with database branching.

Prerequisites

  • Three separate Supabase projects created at supabase.com/dashboard (dev, staging, production)
  • Supabase CLI installed: npm install -g supabase or npx supabase --version
  • @supabase/supabase-js v2+ installed in your project
  • Node.js 18+ with a framework that supports .env files (Next.js, Nuxt, SvelteKit, etc.)
  • A secret management solution for CI (GitHub Actions Secrets, Vercel env vars, etc.)

Instructions

The workflow is three steps. Each step below gives the shape and the one command that matters; the full implementation walkthrough carries the complete env files, TypeScript client factory, RLS policies, CI/CD workflow, and seed data verbatim.

Step 1: Environment Files and Project Layout

Keep one Supabase CLI project with shared migrations and one .env.* file per environment. Each file points at a different Supabase project; only .env.local is safe to commit.

supabase/migrations/   # shared schema — every env applies the same migrations
.env.local             # supabase start defaults (safe to commit)
.env.staging           # staging project creds  (gitignored)
.env.production        # production project creds (gitignored — NEVER commit)

The CLI links one project at a time. Before any db push or functions deploy, re-link to the target:

npx supabase link --project-ref <target-ref>

See the implementation walkthrough (Step 1) for full .env.* contents, the .gitignore block, and the local-port reference.

Step 2: Environment-Aware Client and Safeguards

Detect the active environment once, then build browser (anon key, respects RLS) and server (service-role key, bypasses RLS) clients from it. Gate every destructive helper behind a production guard so seeds and resets can never fire against prod:

export function requireNonProduction(operation: string): void {
  if (isProduction()) {
    throw new Error(`[BLOCKED] "${operation}" is not allowed in production.`);
  }
}

The implementation walkthrough (Step 2) has the full lib/env.ts detection, the createBrowserClient / createServerClient factory, the seedTestData / resetDatabase guards, and environment-scoped RLS policies.

Step 3: Migration Promotion and Database Branching

Promote schema changes strictly local → staging → production. db reset applies everything plus seed.sql locally; db push applies only new migrations to a linked remote:

npx supabase db reset                              # local: all migrations + seed
npx supabase link --project-ref <staging-ref> && npx supabase db push   # then staging
npx supabase link --project-ref <prod-ref>    && npx supabase db push   # then production

For preview deployments, supabase branches create (Pro plan) gives each feature its own isolated database, URL, and keys. Full migration workflow, branching commands, the GitHub Actions deploy workflow (with a production approval gate), and seed data live in the implementation walkthrough (Step 3).

Output

Completing this skill produces:

  • Three isolated Supabase projects — each with its own URL, API keys, database, and storage
  • Environment-specific .env files.env.local, .env.staging, .env.production with correct credentials
  • Environment-aware createClient — browser and server clients auto-configured from env vars with x-environment header tracking
  • Production safeguardsrequireNonProduction() blocks destructive operations outside local/staging
  • Migration promotion pipelinesupabase db push promotes schema changes local → staging → production
  • Database branching — preview environments get isolated database branches (Pro plan)
  • CI/CD workflows — GitHub Actions deploys migrations and Edge Functions per environment with approval gates for production
  • Generated TypeScript typesdatabase.types.ts generated from local or linked project schema

Error Handling

ErrorCauseSolution
Cannot find project refCLI not linked to a projectRun npx supabase link --project-ref <ref> before db push
Migration has already been appliedRe-running an existing migrationCheck supabase_migrations.schema_migrations table; migrations are idempotent by ref
Permission denied for schema publicWrong database passwordVerify SUPABASE_DB_PASSWORD matches the project's database password in dashboard
Seed data appeared in productionRan supabase db reset on prodseed.sql only runs on db reset — never reset production; use db push instead
Wrong environment keys in client.env file mismatchCheck SUPABASE_ENV var and verify URL matches expected project ref
Branch creation failedFree plan or branching not enabledDatabase branching requires Supabase Pro plan; enable in project settings
Migration drift between envsSkipped staging promotionAlways promote through staging first; compare with supabase migration list per project
Type generation mismatchTypes generated from wrong envRegenerate from local (--local) or re-link to the canonical environment

Examples

Three worked examples live in references/examples.md. The fastest path — a full three-env bootstrap from supabase init to a production db push — is:

npx supabase init && npx supabase start        # local, copy keys to .env.local
npx supabase migration new create_users        # author schema, then:
npx supabase db reset                           # verify locally
npx supabase link --project-ref "<staging-ref>" && npx supabase db push
npx supabase link --project-ref "<prod-ref>"    && npx supabase db push

Examples 2 and 3 (full file) show a Next.js middleware that stamps and gates on x-supabase-env, and an admin handler that calls requireNonProduction before a destructive RPC.

Resources

Next Steps

  • For authentication patterns across environments, see supabase-auth-storage-realtime-core
  • For RLS policy testing and validation, see supabase-policy-guardrails
  • For local development workflow optimization, see supabase-local-dev-loop
  • For monitoring and observability across environments, see supabase-observability

When not to use it

  • When a single project is sufficient for the application lifecycle
  • When budget constraints prevent multiple project instances

Prerequisites

Three separate Supabase projectsSupabase CLINode.js 18+Secret management solution

Limitations

  • Database branching requires a Pro plan
  • Requires manual re-linking of the CLI to target projects

How it compares

It replaces manual configuration with a standardized, environment-aware pipeline that prevents cross-environment data contamination.

Compared to similar skills

supabase-multi-env-setup side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
supabase-multi-env-setup (this skill)126dReviewAdvanced
manage-infra05moReviewBeginner
fly-io-deployer03moCautionAdvanced
railway-new17moReviewBeginner

Try saying

Example prompts that trigger this skill in your AI assistant.

More by jeremylongshore

View all by jeremylongshore

analyzing-logs

jeremylongshore

Analyze application logs to detect performance issues, identify error patterns, and improve stability by extracting key insights.

14123

ollama-setup

jeremylongshore

Configure auto-configure Ollama when user needs local LLM deployment, free AI alternatives, or wants to eliminate hosted API costs. Trigger phrases: "install ollama", "local AI", "free LLM", "self-hosted AI", "replace OpenAI", "no API costs". Use when appropriate context detected. Trigger with relevant phrases based on skill purpose.

1167

backtesting-trading-strategies

jeremylongshore

Backtest crypto and traditional trading strategies against historical data. Calculates performance metrics (Sharpe, Sortino, max drawdown), generates equity curves, and optimizes strategy parameters. Use when user wants to test a trading strategy, validate signals, or compare approaches. Trigger with phrases like "backtest strategy", "test trading strategy", "historical performance", "simulate trades", "optimize parameters", or "validate signals".

1071

generating-database-seed-data

jeremylongshore

Process this skill enables AI assistant to generate realistic test data and database seed scripts for development and testing environments. it uses faker libraries to create realistic data, maintains relational integrity, and allows configurable data volumes. u... Use when working with databases or data models. Trigger with phrases like 'database', 'query', or 'schema'.

1033

cursor-codebase-indexing

jeremylongshore

Execute set up and optimize Cursor codebase indexing. Triggers on "cursor index setup", "codebase indexing", "index codebase", "cursor semantic search". Use when working with cursor codebase indexing functionality. Trigger with phrases like "cursor codebase indexing", "cursor indexing", "cursor".

885

testing-mobile-apps

jeremylongshore

Execute mobile app testing on iOS and Android devices/simulators. Use when performing specialized testing. Trigger with phrases like "test mobile app", "run iOS tests", or "validate Android functionality".

810

You might also like

manage-infra

jpmolinamatute

Starts or stops the Docker Compose infrastructure (Postgres 17).

00

fly-io-deployer

LeoYeAI

Deploy and operate Node, Python, Go, Rust, Elixir, and Docker apps on Fly.io with production-grade fly.toml authoring, Machines API orchestration, region selection (latency vs sovereignty vs egress), Fly Postgres clustering, LiteFS for SQLite replication, Upstash Redis bindings, Tigris object storag

00

railway-new

davila7

Create Railway projects, services, and databases with proper configuration. Use when user says "setup", "deploy to railway", "initialize", "create project", "create service", or wants to deploy from GitHub. Handles initial setup AND adding services to existing projects. For databases, use railway-railway-database skill instead.

11

test-with-postgres

storj

Run unit tests that require PostgreSQL. Use this skill when the user wants to run tests with PostgreSQL database backend. Automatically handles checking for and configuring a PostgreSQL Docker container.

13

local-env

dailydotdev

Local environment management - run SQL queries, set up fake payments, reset test data. Use when the user needs help with local database operations or test data setup.

12

supabase-local-dev-loop

jeremylongshore

Configure Supabase local development with hot reload and testing. Use when setting up a development environment, configuring test workflows, or establishing a fast iteration cycle with Supabase. Trigger with phrases like "supabase dev setup", "supabase local development", "supabase dev environment", "develop with supabase".

01

Search skills

Search the agent skills registry