openclaw-skills/supabase-postgres/SKILL.md
用于 Supabase 平台开发与 PostgreSQL 最佳实践,包含 RLS、Edge Functions 和实时订阅。来源:supabase 官方 52.5K installs。
npx skillsauth add seaworld008/commonly-used-high-value-skills supabase-postgresInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
ALTER TABLE ... ENABLE ROW LEVEL SECURITY。auth.uid() 比较数据所属 ID。EXISTS 或 IN 处理基于角色或团队的权限校验。service_role 密钥执行越权操作。INSERT, UPDATE, DELETE 变更。supabase start 在本地启动全套环境。.sql 迁移脚本,使用 supabase db push 或 supabase db remote commit 同步至生产环境。auth.jwt() 在 RLS 中高效访问。# 初始化并启动本地开发环境 (需 Docker)
supabase init
supabase start
# 生成 TypeScript 类型定义 (基于远程 DB Schema)
supabase gen types typescript --project-id your-id > types/supabase.ts
# 创建新的数据库迁移文件
supabase migration new create_profiles_table
# 推送本地迁移至生产环境
supabase db push
# 创建新的边缘函数
supabase functions new my-func
-- 允许用户只读自己的记录
CREATE POLICY "Users can only see their own items"
ON public.items
FOR SELECT
USING (auth.uid() = user_id);
-- 允许用户修改自己的记录
CREATE POLICY "Users can only update their own items"
ON public.items
FOR UPDATE
USING (auth.uid() = user_id)
WITH CHECK (auth.uid() = user_id);
-- 基于角色的策略 (假设有 user_roles 表)
CREATE POLICY "Admins can delete anything"
ON public.items
FOR DELETE
USING (
EXISTS (
SELECT 1 FROM user_roles
WHERE user_id = auth.uid() AND role = 'admin'
)
);
-- 函数:将新注册用户同步到 profiles 表
CREATE OR REPLACE FUNCTION public.handle_new_user()
RETURNS trigger AS $$
BEGIN
INSERT INTO public.profiles (id, full_name, avatar_url)
VALUES (new.id, new.raw_user_meta_data->>'full_name', new.raw_user_meta_data->>'avatar_url');
RETURN new;
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;
-- 触发器:在 auth.users 插入后执行
CREATE TRIGGER on_auth_user_created
AFTER INSERT ON auth.users
FOR EACH ROW EXECUTE FUNCTION public.handle_new_user();
// supabase/functions/my-func/index.ts
import { serve } from "https://deno.land/[email protected]/http/server.ts"
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2'
serve(async (req) => {
const { name } = await req.json()
const supabase = createClient(
Deno.env.get('SUPABASE_URL') ?? '',
Deno.env.get('SUPABASE_ANON_KEY') ?? ''
)
const { data, error } = await supabase
.from('profiles')
.update({ full_name: name })
.eq('id', 'some-id')
return new Response(JSON.stringify({ data, error }), { headers: { "Content-Type": "application/json" } })
})
EXISTS 查询。ALTER TABLE 并结合 CONCURRENTLY(如索引创建)。tools
飞书审批:查询和处理审批待办/已办/实例,搜索可发起审批定义、查看定义详情并发起原生审批实例。当用户要处理审批任务、查看审批实例、搜索或发起审批时使用。审批待办不是飞书任务;非审批类待办走 lark-task。不负责创建审批定义;三方审批定义不走原生提单。
development
Use when a user needs reproducible repository sizing, language composition, file counts, or code-versus-comment ratios with pygount; record exclusions and verify measurement scope before interpreting results.
development
Route a development task to the official Hermes Agent skill, Graphify Codex artifact set, Open GSD Core bundle, or optional GSD Pi bundle without duplicating their installers or state machines.
development
飞书 / Lark 通讯录:按姓名 / 邮箱解析成 open_id,或按 open_id 反查姓名 / 部门 / 邮箱 / 联系方式 / 个人状态 / 签名,以及按关键词搜索当前用户可见的机器人 / 智能体(agent)。当用户提到一个名字要下一步发消息 / 排日程,或拿到 open_id 想查具体信息时使用。不负责部门树遍历、按部门列员工、组织架构图,这类需求走原生 OpenAPI。