-- Example schema for testingCREATE TABLE users ( id UUID DEFAULT gen_random_uuid() PRIMARY KEY, email TEXT UNIQUE NOT NULL, created_at TIMESTAMPTZ DEFAULT NOW());CREATE TABLE posts ( id UUID DEFAULT gen_random_uuid() PRIMARY KEY, user_id UUID REFERENCES users(id), title TEXT NOT NULL, content TEXT, published BOOLEAN DEFAULT false, created_at TIMESTAMPTZ DEFAULT NOW());
Analyze my Supabase database:- List all tables with row counts- Identify tables without indexes- Find potential N+1 query patterns- Suggest missing foreign key constraints- Recommend index optimizations based on table structure- Generate SQL migrations for suggested improvements- Check for security issues (missing RLS policies)
Analyze my Supabase database schema and provide:- Complete table structure with data types- Relationships between tables- Missing indexes that could improve performance- Unused or redundant columns- Suggestions for normalization improvements
提示
复制
Perform a comprehensive RLS (Row Level Security) audit on my Supabase database:For each table:- Check if RLS is enabled- List all existing RLS policies- Identify tables without any RLS policies (security risk)- Find overly permissive policies (e.g., allowing all operations)- Suggest missing policies based on common patterns- Generate SQL to fix identified security issuesPrioritize findings by risk level:1. Critical: Tables with sensitive data but no RLS2. High: Overly permissive policies3. Medium: Missing common policies (e.g., users can only see own data)4. Low: Policy optimization opportunities
提示
复制
Based on the RLS audit, generate SQL migrations to fix all security issues:1. Enable RLS on all tables that don't have it: - Include ALTER TABLE statements - Add comment explaining why RLS is needed2. Create secure default policies for common patterns: - Users can only read/update their own records - Admins have full access (with role checking) - Public read-only access where appropriate - Proper INSERT policies for new records3. Fix overly permissive policies: - Replace 'true' conditions with proper checks - Add user_id or role-based restrictions - Include USING clauses for read operations - Include WITH CHECK clauses for write operations4. For each policy, include: - Clear naming convention (e.g., 'users_select_own') - Comments explaining the security model - Rollback statementsGenerate the complete migration file with all fixes.
根据 AI 建议创建和应用数据库迁移。在 Continue CLI TUI 中输入此提示:示例:完整的 RLS 安全修复
复制
I need to secure my Supabase database. Please:1. First, audit all tables for RLS security issues2. Generate a complete migration to fix all issues found3. Create a security report I can share with my teamHere's what I need fixed:- Enable RLS on all tables- Create policies so users can only access their own data- Ensure admins (role = 'admin') have full access- Add policies for service accounts (role = 'service')- Include audit logging for sensitive operationsFor the users table specifically:- Users can read their own profile- Users can update their own profile (except role field)- Only admins can view all users- Only admins can delete users- New users can insert their own record during signupGenerate the complete migration with:- All SQL statements- Clear policy names and comments- Rollback statements- A summary of what each policy does
预期输出: AI 将生成一个完整的 SQL 迁移文件,该文件
在所有表上启用 RLS
创建安全、有据可查的策略
遵循 Supabase 安全最佳实践
包括回滚功能
为您的团队提供安全摘要
最佳实践:在应用 AI 生成的迁移之前务必进行审查。首先使用 Supabase 的分支功能在开发分支中进行测试。