mcpField
S
supabase

supabase

github.com/heyvhuang数据与数据库33853 次安装30 周前更新
代码仓库

关于 supabase

用于执行 Supabase 数据库操作的技能,面向需要查询、写入、迁移或诊断数据库的工作流。它内置 SQL 安全步骤与 Postgres 最佳实践,并可通过 MCP、Supabase CLI、psql 或 Dashboard 操作。

主要功能

  1. 01查询、写入与数据导出
  2. 02迁移和类型生成
  3. 03查询日志与性能诊断
  4. 04写入前确认及行数核验
  5. 05敏感字段默认脱敏

适用场景

  1. 01统计并导出数据库数据
  2. 02在确认后创建或更新记录
  3. 03通过迁移修改数据库结构
  4. 04排查查询性能或 RLS 问题

MCP 相关

可选使用 MCP 执行 Supabase 数据库操作,也可使用 Supabase CLI、psql 或 Dashboard。

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/heyvhuang/ship-faster --skill supabase

安装后在 Claude Code 中输入/supabase确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

BACKENDS.md
schema.md
SETUP.md

详细介绍

Supabase 数据库操作

在 Supabase 上执行数据库操作:查询、写入、迁移和诊断。

MCP 是可选的。 此技能可通过 MCP(自动)、Supabase CLI、psql 或 Dashboard 运行。执行选项请参阅 BACKENDS.md。

范围

适用于:

  • Supabase 数据库操作:查询/统计/导出、写入(需确认后执行)、迁移(DDL)、类型生成、查询日志/顾问工具

不适用于:

  • 项目侧集成(环境变量/客户端代码/数据访问层)
    → 项目设置请使用 workflow-ship-faster(步骤 6);此技能仅处理数据库侧操作

调用方:

  • workflow-ship-faster 将此技能用作数据库操作基础

Postgres 最佳实践(内置)

Ship Faster 在 references/postgres-best-practices/ 下集成了 Supabase 的 Postgres 最佳实践。

以下情况请参阅:

  • 编写/审查/优化 SQL 查询
  • 设计索引、架构变更或 RLS 策略
  • 诊断性能、锁定或连接问题

权威来源:

  • 完整指南:references/postgres-best-practices/AGENTS.md
  • 单项规则:references/postgres-best-practices/rules/*.md

提出变更时,请引用相关规则文件路径(例如:references/postgres-best-practices/rules/query-missing-indexes.md),并尽量减少变更。

安全规则(必须遵循)

  1. 先读取:任何操作前始终检查架构
  2. 默认 LIMIT 50:所有 SELECT 查询默认使用 LIMIT 50,除非用户明确要求更多
  3. 写入操作确认:执行 INSERT/UPDATE/DELETE 前必须:
    • 显示将要执行的 SQL
    • 说明预计影响的行数
    • 等待用户明确确认
  4. 禁止无条件写入:没有 WHERE 条件的 UPDATE/DELETE → 直接拒绝,不执行
  5. 批量操作阈值:影响超过 100 行 → 必须二次确认,并建议先执行 SELECT count(*)
  6. 通过迁移执行 DDL:架构变更必须使用迁移,不得直接执行 DDL
  7. 生产环境:默认禁用写入;仅当用户明确说“execute on prod”并二次确认时才允许
  8. 敏感字段:默认屏蔽或不返回 email/phone/token/password,除非用户明确要求

操作流程

1. Parse requirements → restate objective
2. Unsure about tables/fields → first query schema (information_schema or list_tables)
3. Plan SQL → present to user
4. Read-only → execute directly
5. Write operation → confirm before execution → verify affected rows → report result

基于文件的流水线

集成到多步骤工作流时,将产物保存到磁盘:

runs/<workflow>/active/<run_id>/
├── proposal.md                # Requirements / objective
├── context.json               # Known tables/fields/IDs
├── tasks.md                   # Checklist + approval gate
├── evidence/sql.md            # SQL to execute (write ops written here first)
├── evidence/result.md         # Conclusion + SQL + results
└── logs/events.jsonl          # Optional tool call summary (no sensitive data)

输出格式

  • 语言:英文
  • 结构:结论 → 关键数字 → 已执行的 SQL → 结果表(最多 50 行)
  • 超出处理:截断 + 显示总数 + 可选导出/分页

示例:

✅ Query complete: 142 new users in the last 7 days

Executed SQL:
SELECT DATE(created_at) as date, COUNT(*) as count 
FROM user_profiles 
WHERE created_at > NOW() - INTERVAL '7 days'
GROUP BY DATE(created_at) ORDER BY date DESC;

| date       | count |
|------------|-------|
| 2025-01-09 | 23    |
| 2025-01-08 | 31    |
| ...        | ...   |

错误处理

情况操作
SQL 语法错误返回错误摘要 + 修复建议
权限不足说明所需权限 + 替代方案
未返回数据说明可能的原因(条件是否过于严格?数据是否不存在?)
RLS 阻止建议检查 RLS 策略或使用 service_role

示例工作流

读取:简单查询
User: Get registered user count for the last 7 days, by day

1. Confirm table user_profiles, field created_at
2. Execute aggregation SQL
3. Return: conclusion + numbers + SQL + table
读取:复杂查询
User: Find projects that have runs but all failed

1. Confirm projects, runs tables and status field
2. Present JOIN + aggregation SQL
3. Execute and return results (mask email)
写入:插入
User: Create a new run for project xxx

1. First check if project exists
2. Present INSERT SQL + expected impact: 1 row
3. Await confirmation → execute → return new record id
写入:更新
User: Change run abc's status to completed

1. First SELECT to verify current state
2. Present UPDATE SQL + WHERE id = 'abc'
3. Confirm → execute → SELECT again to verify
危险操作:删除
User: Delete all runs where status = 'failed'

1. First SELECT count(*) WHERE status = 'failed'
2. Present count + DELETE SQL
3. If > 100 rows, force double confirmation
4. After confirmation execute → report deleted row count
危险操作:不带 WHERE 的 DELETE
User: Clear the runs table

❌ Refuse to execute
→ Prompt: DELETE without WHERE condition, this will delete all data
→ Suggest: Use TRUNCATE (requires migration) or add explicit condition

架构发现

运行时获取最新架构:

-- List all tables
SELECT table_name FROM information_schema.tables 
WHERE table_schema = 'public';

-- View table structure
SELECT column_name, data_type, is_nullable 
FROM information_schema.columns 
WHERE table_name = '<table_name>';

项目专属架构(可能已过时)请参阅 schema.md。

相关文件

评论

支持 Markdown