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(如索引创建)。development
Enumerating failure modes via pre-mortem analysis. Systematically identifies failure scenarios for plans, designs, and features, scoring them with RPN/AP. Does not write code.
testing
Orchestrating specialist AI agent teams as a meta-coordinator. Decomposes requests into minimum viable chains, spawns each as an independent session in AUTORUN modes, and drives to final output. Use when a task spans multiple specialist domains, requires parallel agent execution, or needs hub-and-spoke routing across the skill ecosystem.
development
Converting document formats (Markdown/Word/Excel/PDF/HTML). Converts specs from Scribe and reports from Harvest into distributable formats; generates reusable conversion scripts. Use when converting documents, building accessibility-compliant PDFs, or creating Pandoc/LibreOffice pipelines.
testing
Curating cross-agent knowledge and guarding institutional memory. Extracts patterns from agent journals into METAPATTERNS.md, detects knowledge decay, propagates best practices, prevents organizational forgetting. Use when consolidating cross-agent insights, curating memory, or auditing knowledge decay.