local-supabase-setup
npx skills add https://github.com/kacper-hernacki/local-supabase-setup --skill local-supabase-setup
Agent 安装分布
Skill 文档
Local Supabase Setup Skill
This skill provides the definitive set of instructions for setting up, managing, and troubleshooting a local Supabase development environment. As an AI Agent, use these guidelines when instructed to “set up local Supabase” or when diagnosing connection/configuration issues with a local Supabase instance.
1. Prerequisites & Initialization
When setting up a local Supabase environment for a Next.js or React project:
- Verify CLI: Ensure the Supabase CLI is installed. Run
supabase --version. - Initialize: If
supabase/config.tomldoes not exist, runsupabase initin the project root. - Link (optional): If connecting to an existing remote project, run
supabase link --project-ref <your-project-ref>.
2. Managing the Local Environment
Starting Supabase
Always ensure no conflicting Supabase instances are running from other projects:
supabase status– Checks current running instances.- If another project is holding ports (e.g., port 54322 is in use), stop it:
supabase stop --project-id <conflicting-project-name>. - Clear stopped containers if necessary:
docker stop $(docker ps -aq). - Start the instance:
supabase start.
Stopping Supabase
- Normal shutdown:
supabase stop - Wipe local data and instances:
supabase stop --backup(or--no-backupif data loss is acceptable).
3. Database & Migrations
- Create Migration:
supabase migration new <migration_name> - Apply Migrations:
supabase startapplies migrations by default. Alternatively,supabase db push(for linked projects) orsupabase migration up. - Reset Database:
supabase db resetapplies all migrations and seed data. Use this when the schema is out of sync. - Seeding Data: Place initial data in
supabase/seed.sql. This file runs automatically onsupabase db reset.
4. Storage Setup
To configure storage buckets automatically in a local environment, create an SQL migration (e.g., supabase/migrations/000_storage.sql):
insert into storage.buckets (id, name, public)
values ('bucket-name', 'bucket-name', true)
on conflict (id) do nothing;
create policy "Allow public read access"
on storage.objects for select
using ( bucket_id = 'bucket-name' );
create policy "Allow authenticated uploads"
on storage.objects for insert
with check ( bucket_id = 'bucket-name' and auth.role() = 'authenticated' );
5. Local Edge Functions
To run and test Supabase Edge Functions in a local environment:
- Serve all functions: Run
supabase functions serve. - Serve a specific function: Run
supabase functions serve <function-name>. - Environment Variables: If your functions require external secrets (like Stripe keys or OpenAI keys) while running locally, provide them using an env file:
supabase functions serve --env-file ./supabase/.env.local
The function will be accessible locally at: http://127.0.0.1:54321/functions/v1/<function-name>
6. Local Environment Variables
After running supabase start, the CLI outputs API URLs and keys. You must update the project’s .env.local (or equivalent) file:
NEXT_PUBLIC_SUPABASE_URL=http://127.0.0.1:54321(API URL)NEXT_PUBLIC_SUPABASE_ANON_KEY=<anon-key>SUPABASE_SERVICE_ROLE_KEY=<service-role-key>
Note: For Next.js projects, ensure the prefix NEXT_PUBLIC_ is used for keys needed on the client-side.
7. Accessing the Environment
- Studio URL: http://127.0.0.1:54323 (Default port for the UI dashboard)
- API URL: http://127.0.0.1:54321
- DB Password: Usually
postgresfor local access, running on127.0.0.1:54322.
8. Troubleshooting Checklists
“Port is already allocated” / “Bind for 0.0.0.0:54322 failed”
- Another Supabase instance is running. Find it:
docker ps. - Stop the conflicting project:
supabase stop --project-id <other-project-id>.
“Error connecting to database” from App
- Check
config.tomlto ensure the correct PostgreSQL major version is matching your system or remote project. - Verify
.env.localkeys exactly match the output ofsupabase status.
Magic Link / Email Testing
- Local Supabase captures emails in Inbucket.
- Access it via the local Studio at http://127.0.0.1:54323/project/default/auth/emails or via Inbucket directly if exposed.