safe-agentic-workflow / rules
Cursor rule419 starsChanged 4 months agoMITView on GitHub
Database rules for PostgreSQL 16, Alembic migrations, SQLAlchemy models, and Row Level Security.
- Deletes or force-pushes
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,533 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository60 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .cursor/rules/00-core-principles.mdcCursor rule
- .cursor/rules/01-git-workflow.mdcCursor rule
- .cursor/rules/02-pattern-discovery.mdcCursor rule
- .cursor/rules/03-safe-ai-dlc.mdcCursor rule
- .cursor/rules/04-knowledge-vault.mdcCursor rule
- .cursor/rules/10-backend-python.mdcCursor rule
- .cursor/rules/11-frontend-react.mdcCursor rule
- .cursor/rules/13-testing.mdcCursor rule
- .cursor/rules/14-spec-creation.mdcCursor rule
- .cursor/rules/15-deployment.mdcCursor rule
- .cursor/rules/16-stripe-payments.mdcCursor rule
- .cursor/rules/20-agent-architect.mdcCursor rule
- .cursor/rules/21-agent-backend.mdcCursor rule
- .cursor/rules/22-agent-qas.mdcCursor rule
- .cursor/rules/23-agent-security.mdcCursor rule
- .cursor/rules/30-background-agents.mdcCursor rule
- .cursor/rules/31-mcp-integration.mdcCursor rule
- .cursor/rules/README.mdCursor rule
- agent-coordinationSkill
- api-patternsSkill
- confluence-docsSkill
- deployment-sopSkill
- frontend-patternsSkill
- git-advancedSkill
- linear-sopSkill
- migration-patternsSkill
- orchestration-patternsSkill
- pattern-discoverySkill
- release-patternsSkill
- rls-patternsSkill
- safe-ai-dlcSkill
- safe-workflowSkill
- security-auditSkill
- spec-creationSkill
- stripe-patternsSkill
- team-coordinationSkill
- testing-patternsSkill
- vault-syncSkill
- agent-coordinationSkill
- api-patternsSkill
- confluence-docsSkill
- deployment-sopSkill
- frontend-patternsSkill
- git-advancedSkill
- linear-sopSkill
- migration-patternsSkill
- orchestration-patternsSkill
- pattern-discoverySkill
- release-patternsSkill
- rls-patternsSkill
- safe-ai-dlcSkill
- safe-workflowSkill
- security-auditSkill
- spec-creationSkill
- stripe-patternsSkill
- team-coordinationSkill
- testing-patternsSkill
- vault-syncSkill
The file
We split this 12-database-sql.mdc into the rules it gives an agent
11 rules. About 0 are common, 9 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈9
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 24
Every database operation MUST use the appropriate context helper:
- Distinctive: line 34
No direct session/ORM calls without RLS context wrappers
- Distinctive: line 35
No bypassing RLS policies for convenience
- Distinctive: line 36
No using superuser credentials in application code
- Distinctive: line 40
After any schema change, validate RLS:
- Very specific: line 63
Never use DROP TABLE without a backup strategy
- Distinctive: line 64
Never skip Alembic (no manual DDL in production)
- Distinctive: line 65
Always add proper indexes for query patterns
- Distinctive: line 66
Add RLS policies for every new table with user data
- Very specific: line 71
Use SQLAlchemy 2.x Mapped type annotations
- Distinctive: line 74
Use UUIDs for primary keys
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
description: "Database rules for PostgreSQL 16, Alembic migrations, SQLAlchemy models, and Row Level Security."
globs: "alembic/**,**/models.py,**/schemas.py,**/models/**"
alwaysApply: false
---
# Database and SQL Rules
These rules apply when working on database models, schemas, and migrations.
## Technology
- **Database**: PostgreSQL 16
- **ORM**: SQLAlchemy 2.x
- **Migrations**: Alembic
- **RLS**: Row Level Security (MANDATORY)
## Row Level Security (RLS)
**CRITICAL**: RLS is mandatory for ALL tables containing user data.
### RLS Context Helpers
Every database operation MUST use the appropriate context helper:
| Helper | Use Case |
|-----------------------|------------------------------|
| `with_user_context` | User-scoped operations |
| `with_admin_context` | Admin-scoped operations |
| `with_system_context` | Background/webhook operations|
### Zero Tolerance
- No direct session/ORM calls without RLS context wrappers
- No bypassing RLS policies for convenience
- No using superuser credentials in application code
### RLS Validation
After any schema change, validate RLS:
- User isolation: User A cannot see User B's data
- Admin access: Admin can see data within policy scope
- System context: Background tasks use system context
## Migration Workflow
```bash
# 1. Create migration
alembic revision --autogenerate -m "description"
# 2. REVIEW the generated migration (do not blindly apply)
# 3. Add RLS policies if new table created
# 4. Test locally
alembic upgrade head
# 5. Commit
git add alembic/versions/
git commit -m "feat(db): description [{{TICKET_PREFIX}}-XXX]"
```
### Migration Rules
- Never use `DROP TABLE` without a backup strategy
- Never skip Alembic (no manual DDL in production)
- Always add proper indexes for query patterns
- Add RLS policies for every new table with user data
- Schema changes REQUIRE System Architect approval
## SQLAlchemy Model Standards
- Use SQLAlchemy 2.x `Mapped` type annotations
- Define relationships explicitly
- Include `created_at` and `updated_at` timestamps on all tables
- Use UUIDs for primary keys
## Key References
- `docs/database/DATA_DICTIONARY.md` -- Schema reference (SINGLE SOURCE OF TRUTH)
- `docs/database/RLS_DATABASE_MIGRATION_SOP.md` -- Migration SOP (MANDATORY reading)
- `docs/database/RLS_IMPLEMENTATION_GUIDE.md` -- RLS implementation details
- `patterns_library/database/rls-migration.md` -- RLS migration pattern
- `patterns_library/database/prisma-transaction.md` -- Transaction pattern
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

