home / skills / openclaw / skills / supabase-gen
This skill generates Supabase RLS policies from a Prisma schema, delivering secure defaults and SQL ready for deployment.
npx playbooks add skill openclaw/skills --skill supabase-genReview the files below or copy the command above to add this skill to your agents.
---
name: supabase-gen
description: Generate Supabase RLS policies from Prisma schema. Use when setting up row-level security for your tables.
---
# Supabase Gen
Row-level security is a pain to write. This tool reads your Prisma schema and generates proper RLS policies for Supabase. You get secure defaults that actually make sense for your data model.
**One command. Zero config. Just works.**
## Quick Start
```bash
npx ai-supabase-gen prisma/schema.prisma
```
## What It Does
- Reads your Prisma schema and understands the data model
- Generates RLS policies for SELECT, INSERT, UPDATE, DELETE
- Creates auth.uid() checks for user-owned resources
- Handles multi-tenant patterns with organization scoping
- Outputs SQL ready to run in Supabase SQL editor
## Usage Examples
```bash
# Generate RLS from your schema
npx ai-supabase-gen prisma/schema.prisma
# Save to migration file
npx ai-supabase-gen prisma/schema.prisma > supabase/migrations/001_rls.sql
# Specify output format
npx ai-supabase-gen prisma/schema.prisma --format sql
```
## Best Practices
- **Review every policy** - AI gets close but you know your access patterns best
- **Test with different users** - RLS bugs are sneaky. Test reads and writes as different roles.
- **Start restrictive** - Better to block legitimate access than leak data. Loosen later.
- **Use service role sparingly** - Service role bypasses RLS. That's powerful and dangerous.
## When to Use This
- Setting up a new Supabase project with existing Prisma schema
- Adding RLS to tables that currently have none
- Auditing your security and want a fresh set of policies to compare
- Learning RLS patterns and want to see how they should look
## Part of the LXGIC Dev Toolkit
This is one of 110+ free developer tools built by LXGIC Studios. No paywalls, no sign-ups, no API keys on free tiers. Just tools that work.
**Find more:**
- GitHub: https://github.com/LXGIC-Studios
- Twitter: https://x.com/lxgicstudios
- Substack: https://lxgicstudios.substack.com
- Website: https://lxgic.dev
## Requirements
No install needed. Just run with npx. Node.js 18+ recommended. Requires OPENAI_API_KEY environment variable.
```bash
export OPENAI_API_KEY=sk-...
npx ai-supabase-gen --help
```
## How It Works
Parses your Prisma schema to understand models, relations, and field types. Then generates appropriate RLS policies based on common patterns like user ownership, org membership, and public/private access. Uses GPT to handle edge cases intelligently.
## License
MIT. Free forever. Use it however you want.
This skill generates Supabase row-level security (RLS) policies from a Prisma schema so you can secure tables quickly and consistently. It produces SQL policies for SELECT, INSERT, UPDATE, and DELETE with sensible defaults like auth.uid() checks and organization scoping. One command, no config required — output is ready to paste into Supabase SQL editor or save as a migration file.
The tool parses your Prisma schema to detect models, fields, relations, and common ownership patterns. It maps those patterns to RLS rules (user-owned rows, org-scoped rows, public/private) and emits SQL for each CRUD operation, including auth.uid() checks where appropriate. GPT-based heuristics handle edge cases and produce readable, editable policies you should review and test.
Do I need an API key to run the tool?
Yes. Node.js runs the tool via npx and an OPENAI_API_KEY environment variable is required for the GPT-based heuristics.
Is the generated SQL ready to run as-is?
The SQL is ready to run, but you should review and test every policy against your app scenarios before deploying to production.
Can it detect multi-tenant or org-scoped models?
Yes. The parser looks for common organization or tenant fields and generates appropriate scoping checks, but confirm the exact field names and semantics.