supabase-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSupabase CLI Skill
Supabase CLI 命令参考大全
Complete CLI command reference for Supabase development.
Supabase开发的完整CLI命令参考。
Quick Reference
快速参考
| Task | Command |
|---|---|
| Install CLI | |
| Login | |
| Init project | |
| Link to remote | |
| Start local stack | |
| Stop local stack | |
| Check status | |
| Create migration | |
| Push to remote | |
| Pull from remote | |
| Reset local DB | |
| Generate types | |
| 任务 | 命令 |
|---|---|
| 安装CLI | |
| 登录 | |
| 初始化项目 | |
| 关联远程项目 | |
| 启动本地服务栈 | |
| 停止本地服务栈 | |
| 查看状态 | |
| 创建迁移文件 | |
| 推送至远程 | |
| 从远程拉取 | |
| 重置本地数据库 | |
| 生成类型定义 | |
Installation
安装
bash
undefinedbash
undefinedNPM (recommended for projects)
NPM(推荐用于项目)
npm install supabase --save-dev
npx supabase [command]
npm install supabase --save-dev
npx supabase [command]
Homebrew (macOS/Linux)
Homebrew(适用于macOS/Linux)
brew install supabase/tap/supabase
brew install supabase/tap/supabase
Scoop (Windows)
Scoop(适用于Windows)
scoop bucket add supabase https://github.com/supabase/scoop-bucket.git
scoop install supabase
**Prerequisites**: Docker (required for local development)scoop bucket add supabase https://github.com/supabase/scoop-bucket.git
scoop install supabase
**前置要求**:Docker(本地开发必需)Project Setup
项目设置
Initialize Project
初始化项目
bash
supabase initCreates:
- - Configuration file
supabase/config.toml - - Migration files
supabase/migrations/ - - Seed data
supabase/seed.sql
bash
supabase init创建以下文件/目录:
- - 配置文件
supabase/config.toml - - 迁移文件目录
supabase/migrations/ - - 初始数据文件
supabase/seed.sql
Link to Remote Project
关联远程项目
bash
supabase link --project-ref <project-ref>Get project ref from: Dashboard → Project Settings → General
bash
supabase link --project-ref <project-ref>项目参考ID获取路径:控制台 → 项目设置 → 常规设置
Local Development
本地开发
Start Local Stack
启动本地服务栈
bash
supabase startStarts:
- PostgreSQL database
- PostgREST API
- GoTrue Auth
- Realtime server
- Storage service
- Studio dashboard
- Inbucket (email testing)
Output URLs:
API URL: http://localhost:54321
DB URL: postgresql://postgres:postgres@localhost:54322/postgres
Studio URL: http://localhost:54323
Inbucket URL: http://localhost:54324bash
supabase start启动以下服务:
- PostgreSQL数据库
- PostgREST API
- GoTrue 认证服务
- Realtime 服务器
- 存储服务
- Studio 控制台
- Inbucket(邮件测试工具)
输出URL:
API URL: http://localhost:54321
DB URL: postgresql://postgres:postgres@localhost:54322/postgres
Studio URL: http://localhost:54323
Inbucket URL: http://localhost:54324Stop Local Stack
停止本地服务栈
bash
undefinedbash
undefinedStop and save data
停止并保存数据
supabase stop
supabase stop
Stop and delete all data
停止并删除所有数据
supabase stop --no-backup
undefinedsupabase stop --no-backup
undefinedCheck Status
查看状态
bash
supabase statusShows URLs, API keys, and service status.
bash
supabase status显示服务URL、API密钥和服务状态。
Database Commands
数据库命令
Create Migration
创建迁移文件
bash
supabase migration new create_users_tableCreates:
supabase/migrations/<timestamp>_create_users_table.sqlbash
supabase migration new create_users_table创建文件:
supabase/migrations/<timestamp>_create_users_table.sqlGenerate Migration from Changes
根据变更生成迁移文件
bash
undefinedbash
undefinedMake changes locally, then generate migration
在本地修改后,生成迁移文件
supabase db diff -f my_schema_changes
supabase db diff -f my_schema_changes
Diff against specific schemas
对比指定模式
supabase db diff -f changes --schema public,extensions
undefinedsupabase db diff -f changes --schema public,extensions
undefinedApply Migrations
应用迁移
bash
undefinedbash
undefinedApply pending migrations locally
在本地应用待处理的迁移
supabase migration up
supabase migration up
Push to remote
推送至远程
supabase db push
supabase db push
Preview what would be pushed
预览将要推送的内容
supabase db push --dry-run
undefinedsupabase db push --dry-run
undefinedPull Remote Changes
拉取远程变更
bash
supabase db pullCreates migration from Dashboard changes.
bash
supabase db pull根据控制台的变更创建迁移文件。
Reset Local Database
重置本地数据库
bash
supabase db resetRecreates database and applies all migrations.
bash
supabase db reset重新创建数据库并应用所有迁移文件。
List Migrations
列出迁移文件
bash
supabase migration listShows local vs remote migration status.
bash
supabase migration list显示本地与远程的迁移状态对比。
Rollback Migrations
回滚迁移
bash
undefinedbash
undefinedRollback last n migrations
回滚最近n个迁移
supabase migration down --count 1
supabase migration down --count 1
Rollback specific number
回滚指定数量的迁移
supabase migration down --count 3
undefinedsupabase migration down --count 3
undefinedSquash Migrations
合并迁移文件
bash
undefinedbash
undefinedCombine multiple migrations into one
将多个迁移文件合并为一个
supabase migration squash --version 20240101000000
supabase migration squash --version 20240101000000
Squash all migrations up to version
合并指定版本之前的所有迁移文件
supabase migration squash --version <target_version>
Useful for cleaning up migration history before release.supabase migration squash --version <target_version>
适用于发布前清理迁移历史。Type Generation
类型生成
Generate TypeScript Types
生成TypeScript类型定义
bash
undefinedbash
undefinedFrom local database
从本地数据库生成
supabase gen types typescript --local > database.types.ts
supabase gen types typescript --local > database.types.ts
From linked remote
从关联的远程项目生成
supabase gen types typescript --linked > database.types.ts
supabase gen types typescript --linked > database.types.ts
From specific project
从指定项目生成
supabase gen types typescript --project-id "your-id" > database.types.ts
undefinedsupabase gen types typescript --project-id "your-id" > database.types.ts
undefinedEdge Functions
Edge Functions
Create Function
创建函数
bash
supabase functions new hello-worldCreates:
supabase/functions/hello-world/index.tsbash
supabase functions new hello-world创建文件:
supabase/functions/hello-world/index.tsServe Locally
本地运行
bash
undefinedbash
undefinedServe all functions
运行所有函数
supabase functions serve
supabase functions serve
Serve specific function
运行指定函数
supabase functions serve hello-world
supabase functions serve hello-world
With env file and no JWT
使用环境变量文件且不验证JWT
supabase functions serve --env-file .env --no-verify-jwt
undefinedsupabase functions serve --env-file .env --no-verify-jwt
undefinedDeploy
部署
bash
undefinedbash
undefinedDeploy all functions
部署所有函数
supabase functions deploy
supabase functions deploy
Deploy specific function
部署指定函数
supabase functions deploy hello-world
supabase functions deploy hello-world
Deploy without JWT verification (for webhooks)
部署时关闭JWT验证(适用于Webhook)
supabase functions deploy webhook-handler --no-verify-jwt
undefinedsupabase functions deploy webhook-handler --no-verify-jwt
undefinedTest Function
测试函数
bash
curl -i --request POST \
'http://localhost:54321/functions/v1/hello-world' \
--header 'Authorization: Bearer <ANON_KEY>' \
--header 'Content-Type: application/json' \
--data '{"name":"Functions"}'bash
curl -i --request POST \
'http://localhost:54321/functions/v1/hello-world' \
--header 'Authorization: Bearer <ANON_KEY>' \
--header 'Content-Type: application/json' \
--data '{"name":"Functions"}'Secrets Management
密钥管理
bash
undefinedbash
undefinedSet secret
设置密钥
supabase secrets set API_KEY=abc123
supabase secrets set API_KEY=abc123
Set multiple secrets
设置多个密钥
supabase secrets set API_KEY=abc123 DB_PASSWORD=secret
supabase secrets set API_KEY=abc123 DB_PASSWORD=secret
Set from .env file
从.env文件导入密钥
supabase secrets set --env-file .env
supabase secrets set --env-file .env
List secrets
列出密钥
supabase secrets list
supabase secrets list
Remove secret
删除密钥
supabase secrets unset API_KEY
undefinedsupabase secrets unset API_KEY
undefinedProject Management
项目管理
bash
undefinedbash
undefinedList organizations
列出组织
supabase orgs list
supabase orgs list
List projects
列出项目
supabase projects list
supabase projects list
Create project
创建项目
supabase projects create <name> --org-id <id> --region <region>
supabase projects create <name> --org-id <id> --region <region>
Delete project
删除项目
supabase projects delete --project-ref <ref>
supabase projects delete --project-ref <ref>
Update remote config from local
从本地更新远程配置
supabase projects update-config
undefinedsupabase projects update-config
undefinedDatabase Inspection
数据库检查
bash
undefinedbash
undefinedCache hit ratio
缓存命中率
supabase inspect db cache-hit --linked
supabase inspect db cache-hit --linked
Unused indexes
未使用的索引
supabase inspect db unused-indexes --local
supabase inspect db unused-indexes --local
Table bloat
表膨胀情况
supabase inspect db bloat --linked
supabase inspect db bloat --linked
Long running queries
长时间运行的查询
supabase inspect db long-running-queries --linked
supabase inspect db long-running-queries --linked
Active connections
活跃连接数
supabase inspect db role-connections --linked
undefinedsupabase inspect db role-connections --linked
undefinedBackup & Restore
备份与恢复
Backup
备份
bash
undefinedbash
undefinedDump roles
导出角色
supabase db dump --linked -f roles.sql --role-only
supabase db dump --linked -f roles.sql --role-only
Dump schema
导出模式
supabase db dump --linked -f schema.sql
supabase db dump --linked -f schema.sql
Dump data
导出数据
supabase db dump --linked -f data.sql --use-copy --data-only
undefinedsupabase db dump --linked -f data.sql --use-copy --data-only
undefinedRestore
恢复
bash
psql --single-transaction \
--file roles.sql \
--file schema.sql \
--command 'SET session_replication_role = replica' \
--file data.sql \
--dbname [CONNECTION_STRING]bash
psql --single-transaction \
--file roles.sql \
--file schema.sql \
--command 'SET session_replication_role = replica' \
--file data.sql \
--dbname [CONNECTION_STRING]Common Flags
通用参数
| Flag | Description |
|---|---|
| Verbose output |
| Use local database |
| Use linked remote |
| Specific project |
| Connection string |
| Preview without executing |
| Output to file |
| 参数 | 描述 |
|---|---|
| 详细输出 |
| 使用本地数据库 |
| 使用关联的远程项目 |
| 指定项目参考ID |
| 数据库连接字符串 |
| 预览操作不实际执行 |
| 输出至指定文件 |
References
参考资料
- local-development.md - Local stack setup
- migrations.md - Migration workflow
- config-toml.md - Configuration options
- local-development.md - 本地服务栈设置文档
- migrations.md - 迁移工作流文档
- config-toml.md - 配置选项文档