deploy-supabase
npx skills add https://github.com/kacper-hernacki/local-supabase-setup --skill deploy-supabase
Agent 安装分布
Skill 文档
Deploy Supabase Skill
This skill provides the definitive set of instructions for taking a local Supabase development environment and deploying it to a remote Supabase project (e.g., staging or production). As an AI Agent, use these guidelines when instructed to “deploy Supabase”, “sync local Supabase to production”, or “link to a remote Supabase project”.
1. Prerequisites & Authentication
Before deploying, ensure the CLI is authenticated and the user has a remote project ready.
- Login: Ensure the CLI is authenticated. Run
supabase login. This will require the user to provide a Personal Access Token from https://supabase.com/dashboard/account/tokens. - Get Project Ref: Ask the user for the Reference ID of their remote project (a 20-character string found in the project’s dashboard URL:
https://supabase.com/dashboard/project/<project-ref>).
2. Linking the Local Project to Remote
To ensure migrations and deployments target the correct remote database:
- Link Project: Run
supabase link --project-ref <project-ref>. - Database Password: The CLI will prompt for the remote database password (not the user’s account password). Ask the user to enter this when prompted, or pass it via the
SUPABASE_DB_PASSWORDenvironment variable.
3. Database Migrations
You must push the local schema changes to the remote database securely.
Step 3.1: Verify Remote Status
Run supabase db remote commit to capture any changes made directly in the remote dashboard (like auth settings or manual table changes) that aren’t in the local migrations yet.
- Alternatively, if the remote database is a completely fresh instance, you can skip to pushing.
Step 3.2: Push Migrations
If the local migrations represent the desired state:
- Run
supabase db push. - This will apply all pending local migrations in
supabase/migrations/*to the remote database.
Note: Never use supabase db reset on a production remote database unless explicitly requested by the user, as this drops all data.
4. Deploying Configuration
If the project uses supabase/config.toml for settings like Auth, Storage limits, or Webhooks (supported in recent CLI versions):
- Push Config: Run
supabase config push. - This applies local Auth and Storage configurations to the remote project.
5. Deploying Edge Functions
If the project uses Supabase Edge Functions (supabase/functions/*):
- Deploy all functions: Run
supabase functions deploy. - Deploy a specific function: Run
supabase functions deploy <function-name>.
Managing Secrets for Functions
Functions often require secrets (like Stripe keys or OpenAI keys) that shouldn’t be committed to source control.
- Push Secrets: Create a
.env.productionor.envfile locally with the required secrets, then run:supabase secrets set --env-file ./path/to/.env.production. - List Secrets: Run
supabase secrets listto verify.
6. Remote Environment Variables Update
Remind the user to update their web application’s (e.g., Next.js) remote hosting environment variables (like on Vercel or Netlify) with the new remote project credentials:
NEXT_PUBLIC_SUPABASE_URL-> The remote project URL (e.g.,https://<project-ref>.supabase.co)NEXT_PUBLIC_SUPABASE_ANON_KEY-> The remote project’s Anon API keySUPABASE_SERVICE_ROLE_KEY-> The remote project’s Service Role key
7. Troubleshooting Deployment Iterations
“Migration name conflicts”
If supabase db push fails because a migration has already been applied remotely but with different contents:
- Run
supabase migration listto see the sync status. - If the remote has drifted, you may need to use
supabase db pullorsupabase db remote committo reconcile changes before generating a new migration withsupabase migration new.
Edge Functions failing
Ensure all necessary environment variables have been pushed via supabase secrets set before deploying the functions. Functions will fail to start if required keys are missing remotely.