阿里云Supabase CLI使用指南

更新时间:
复制为 MD 格式

在开发过程中,您可以通过阿里云Supabase CLI在本地终端中完成云原生数据仓库AnalyticDB PostgreSQLSupabase(简称AnalyticDB Supabase)项目的全生命周期管理,包括项目创建、数据库操作、迁移管理、边缘函数部署等。CLI工具专为AnalyticDB Supabase用户设计,默认启用阿里云模式,无需额外配置即可使用所有功能。

简介

什么是阿里云Supabase CLI

阿里云Supabase CLI是基于开源Supabase CLI扩展的命令行工具,增加了对AnalyticDB Supabase平台的完整支持。除了标准的Supabase功能外,还提供了阿里云专属的基础设施管理和项目运维能力。

核心优势

  • 开箱即用:默认启用阿里云模式,无需--profile参数。

  • 全栈支持:覆盖项目管理、数据库操作、迁移、函数、密钥、存储等全场景。

  • 无需Docker:所有核心命令均通过直连远程数据库实现,无需本地容器环境。

  • 阿里云专属:提供VPC、可用区、IP白名单等阿里云基础设施管理命令。

  • 多平台支持:支持macOS、Linux、Windows等主流操作系统。

适用场景

  • 项目管理:创建、查询、删除AnalyticDB Supabase项目。

  • 本地开发:拉取远程Schema、推送本地迁移、执行SQL查询。

  • CI/CD集成:在流水线中自动执行数据库迁移和函数部署。

  • 运维管理:查看项目状态、管理密钥、监控数据库Schema。

安装方法

下载二进制文件

# 解压并安装,请根据您下载的安装包替换
tar -xzf supabase_v${VERSION}_linux_arm64.tar.gz
sudo mv supabase /usr/local/bin/

# 验证安装
supabase --help

配置访问凭证

使用前需要配置阿里云访问凭证:

# 方式一:环境变量(推荐)
export ALIYUN_ACCESS_KEY_ID="your-access-key-id"
export ALIYUN_ACCESS_KEY_SECRET="your-access-key-secret"

# 方式二:组合令牌
export ALIYUN_ACCESS_TOKEN="AccessKeyId|AccessKeySecret"

# 可选:设置默认区域和数据库密码
export ALIYUN_REGION_ID="cn-hangzhou"
export SUPABASE_DB_PASSWORD="your-db-password"

支持的命令

项目管理(Supabase projects)

管理AnalyticDB Supabase项目的创建、查询和删除。

命令

说明

示例

projects list

列出所有项目。

supabase projects list

projects show [ref]

查看项目详情。

supabase projects show sbp-xxxxxxx

projects api-keys

查看API密钥。

supabase projects api-keys --project-ref sbp-xxxxxxx

projects create [name]

创建新项目。

supabase projects create "MyProject"

projects delete [ref]

删除项目。

supabase projects delete sbp-xxxxxxx

projects ip-whitelist [ref]

修改IP白名单。

supabase projects ip-whitelist sbp-xxxxxxx --ip-list "192.168.1.0/24"

projects reset-password [ref]

重置数据库密码。

supabase projects reset-password sbp-xxxxxxx --password "new-password"

使用示例:

# 列出所有项目
supabase projects list

# 查看项目详情
supabase projects show sbp-3zyrsu6j0w4s****

# 查看API密钥
supabase projects api-keys --project-ref sbp-3zyrsu6j0w4s****

基础设施管理(Supabase infra)

管理阿里云基础设施,包括区域、VPC和交换机。此为阿里云专属命令。

命令

说明

示例

infra regions

列出可用区域和可用区。

supabase infra regions

infra vpcs

列出指定区域的VPC。

supabase infra vpcs --region cn-hangzhou

infra vswitches

列出指定VPC的交换机

supabase infra vswitches --region cn-hangzhou --vpc-id vpc-xxx --zone-id cn-hangzhou-i

使用示例:

# 查看所有可用区域
supabase infra regions

# 查看杭州区域的VPC
supabase infra vpcs --region cn-hangzhou

项目链接(Supabase link)

将本地项目链接到AnalyticDB Supabase项目。

命令

说明

示例

link

链接到远程项目。

supabase link --project-ref sbp-xxxxxxx --password "db-password"

unlink

断开链接。

supabase unlink

使用示例:

# 链接到阿里云项目
supabase link --project-ref sbp-3zyrsu6j0w4s**** --password '<your-db-password>'

数据库管理(Supabase db)

管理Postgres数据库的Schema、迁移和查询。

命令

说明

示例

db tables list

列出数据库表。

supabase db tables list --project-ref sbp-xxxxxxx

db columns list

列出表的列。

supabase db columns list --project-ref sbp-xxxxxxx --table users

db indexes list

列出索引。

supabase db indexes list --project-ref sbp-xxxxxxx

db extensions list

列出扩展。

supabase db extensions list --project-ref sbp-xxxxxxx

db diff

对比Schema差异。

supabase db diff --project-ref sbp-xxxxxxx --password "db-password"

db dump

导出数据库Schema。

supabase db dump --project-ref sbp-xxxxxxx --password "db-password" --file schema.sql

db pull

拉取远程Schema。

supabase db pull --project-ref sbp-xxxxxxx --password "db-password"

db push

推送本地迁移。

supabase db push --project-ref sbp-xxxxxxx --password "db-password"

db lint

检查Schema错误。

supabase db lint --project-ref sbp-xxxxxxx --password "db-password"

db query [sql]

执行SQL查询。

supabase db query "SELECT * FROM users" --linked

使用示例:

# 列出所有表
supabase db tables list --project-ref sbp-3zyrsu6j0w4s****

# 查看表结构
supabase db columns list --project-ref sbp-3zyrsu6j0w4s*** --table inventory

# 执行SQL查询(需要先link)
supabase db query "SELECT * FROM public.inventory LIMIT 10" --linked

迁移管理(Supabase migration)

管理数据库迁移脚本和历史记录。

命令

说明

示例

migration list

列出迁移记录。

supabase migration list --project-ref sbp-xxxxxxx --password "db-password"

migration up

应用待执行的迁移。

supabase migration up --project-ref sbp-xxxxxxx --password "db-password"

migration down

回滚迁移版本。

supabase migration down --linked --last 1

migration repair

修复迁移历史。

supabase migration repair [version] --status reverted

migration new [name]

创建新的迁移文件。

supabase migration new add_users_table

migration fetch

获取迁移文件。

supabase migration fetch --db-url "postgresql://..."

使用示例:

# 查看迁移历史
supabase migration list --project-ref sbp-3zyrsu6j0w4s**** --password '<your-db-password>'

# 修复迁移状态
supabase migration repair 20260416111028 --status reverted --project-ref sbp-3zyrsu6j0w4s****

边缘函数(Supabase functions)

管理AnalyticDB Supabase Edge Functions的部署和调用。

命令

说明

示例

functions list

列出所有函数。

supabase functions list --project-ref sbp-xxxxxxx

functions deploy [slug]

部署函数。

supabase functions deploy hello-world

functions download [slug]

下载函数。

supabase functions download hello-world

functions delete [slug]

删除函数。

supabase functions delete hello-world

functions invoke [slug]

调用函数。

supabase functions invoke hello-world --data '{"name":"world"}'

使用示例:

# 列出所有函数
supabase functions list --project-ref sbp-3zyrsu6j0w4s****

# 部署函数
supabase functions deploy hello-world --project-ref sbp-3zyrsu6j0w4s****

密钥管理(Supabase secrets)

管理AnalyticDB Supabase项目的环境变量和密钥。

命令

说明

示例

secrets list

列出所有密钥。

supabase secrets list --project-ref sbp-xxxxxxx

secrets set [NAME=VALUE]

设置密钥。

supabase secrets set MY_KEY=my-value

secrets unset [NAME]

删除密钥。

supabase secrets unset MY_KEY

使用示例:

# 查看密钥列表
supabase secrets list --project-ref sbp-3zyrsu6j0w4s****

# 设置密钥
supabase secrets set DATABASE_URL=postgresql://... --project-ref sbp-3zyrsu6j0w4s****

用户管理 (Supabase auth)

管理 Supabase Auth 用户。阿里云Supabase CLI专属命令。

命令

说明

示例

auth users list

列出所有用户。

supabase auth users list --project-ref sbp-xxxxxxx

auth users get <id>

获取用户详情。

supabase auth users get <user-id> --project-ref sbp-xxxxxxx

auth users create

创建用户。

supabase auth users create --email user@example.com

auth users update <id>

更新用户。

supabase auth users update <user-id> --email new@example.com

auth users delete <id>

删除用户。

supabase auth users delete <user-id>

创建用户参数:

参数

说明

--email

用户邮箱

--phone

用户手机号

--password

用户密码

--email-confirm

自动确认邮箱

--phone-confirm

自动确认手机号

使用示例:

# 列出所有用户
supabase auth users list --project-ref sbp-xxxxxxx

# 创建用户
supabase auth users create --email user@example.com --password 'SecurePass123' --project-ref sbp-xxxxxxx

# 更新用户邮箱
supabase auth users update <user-id> --email new@example.com --project-ref sbp-xxxxxxx

# 删除用户
supabase auth users delete <user-id> --project-ref sbp-xxxxxxx

存储管理(Supabase storage)

管理AnalyticDB Supabase Storage的存储桶和文件。

命令

说明

示例

storage buckets list

列出存储桶。

supabase storage buckets list --project-ref sbp-xxxxxxx

storage buckets create [name]

创建存储桶。

supabase storage buckets create my-bucket

storage buckets delete [name]

删除存储桶。

supabase storage buckets delete my-bucket

storage ls [path]

列出文件。

supabase storage ls s3://my-bucket/

storage cp [src] [dst]

复制文件。

supabase storage cp local.txt s3://my-bucket/

storage mv [src] [dst]

移动文件。

supabase storage mv s3://bucket/a.txt s3://bucket/b.txt

storage rm [path]

删除文件。

supabase storage rm s3://my-bucket/file.txt

代码生成(Supabase gen)

根据数据库Schema生成类型定义。

命令

说明

示例

gen bearer-jwt

生成JWT令牌。

supabase gen bearer-jwt

gen signing-key

生成签名密钥。

supabase gen signing-key

支持生成以下语言的类型定义:TypeScript、Go、Swift、Python。

使用示例:

# 生成TypeScript类型
supabase gen types typescript --project-ref sbp-3zyrsu6j0w4s**** --password '<your-db-password>'

快速开始

步骤一:配置环境

export ALIYUN_ACCESS_KEY_ID="your-access-key-id"
export ALIYUN_ACCESS_KEY_SECRET="your-access-key-secret"
export SUPABASE_DB_PASSWORD="your-db-password"

步骤二:查看所有项目

supabase projects list

步骤三:连接项目

supabase link --project-ref sbp-3zyrsu6j0w4s**** --password '<your-db-password>'

步骤四:查看项目详情

supabase projects show sbp-3zyrsu6j0w4s****

步骤五:查询数据库

# 列出所有表
supabase db tables list --project-ref sbp-3zyrsu6j0w4s****

# 执行SQL查询
supabase db query "SELECT * FROM public.inventory LIMIT 10" --linked

步骤六:拉取Schema

# 拉取远程Schema到本地
supabase db pull --project-ref sbp-3zyrsu6j0w4s**** --password '<your-db-password>'