examples: Updates example rules to match the latest format of Cursor rules and add declarative schema example (#34992)

* remove glob from all examples

* Add declarative schema instructions

* run prettier

* update file extension for declarative-database-schema rule

* update the example prompts in the examples folder
This commit is contained in:
Tyler
2025-04-16 01:02:10 +09:00
committed by GitHub
parent eadff19571
commit e3b03513e9
13 changed files with 166 additions and 11 deletions

View File

@@ -1,7 +1,7 @@
---
# Specify the following for Cursor rules
description: Guidelines for writing Supabase database functions
globs: **/*.sql
alwaysApply: false
---
# Database: Create functions

View File

@@ -1,7 +1,7 @@
---
# Specify the following for Cursor rules
description: Guidelines for writing Postgres migrations
globs: supabase/migrations/**/*.sql
alwaysApply: false
---
# Database: Create migration

View File

@@ -1,6 +1,5 @@
---
description: Guidelines for writing Postgres Row Level Security policies
globs: **/*.sql
alwaysApply: false
---

View File

@@ -0,0 +1,78 @@
---
# Specify the following for Cursor rules
description: For when modifying the Supabase database schema.
alwaysApply: false
---
# Database: Declarative Database Schema
Mandatory Instructions for Supabase Declarative Schema Management
## 1. **Exclusive Use of Declarative Schema**
-**All database schema modifications must be defined within `.sql` files located in the `supabase/schemas/` directory. -**Do not\*\* create or modify files directly in the `supabase/migrations/` directory unless the modification is about the known caveats below. Migration files are to be generated automatically through the CLI.
## 2. **Schema Declaration**
-For each database entity (e.g., tables, views, functions), create or update a corresponding `.sql` file in the `supabase/schemas/` directory
-Ensure that each `.sql` file accurately represents the desired final state of the entity
## 3. **Migration Generation**
- Before generating migrations, **stop the local Supabase development environment**
```bash
supabase stop
```
- Generate migration files by diffing the declared schema against the current database state
```bash
supabase db diff -f <migration_name>
```
Replace `<migration_name>` with a descriptive name for the migration
## 4. **Schema File Organization**
- Schema files are executed in lexicographic order. To manage dependencies (e.g., foreign keys), name files to ensure correct execution order
- When adding new columns, append them to the end of the table definition to prevent unnecessary diffs
## 5. **Rollback Procedures**
- To revert changes
- Manually update the relevant `.sql` files in `supabase/schemas/` to reflect the desired state
- Generate a new migration file capturing the rollback
```bash
supabase db diff -f <rollback_migration_name>
```
- Review the generated migration file carefully to avoid unintentional data loss
## 6. **Known caveats**
The migra diff tool used for generating schema diff is capable of tracking most database changes. However, there are edge cases where it can fail.
If you need to use any of the entities below, remember to add them through versioned migrations instead.
### Data manipulation language
- DML statements such as insert, update, delete, etc., are not captured by schema diff
### View ownership
- view owner and grants
- security invoker on views
- materialized views
- doesnt recreate views when altering column type
### RLS policies
- alter policy statements
- column privileges
- Other entities#
- schema privileges are not tracked because each schema is diffed separately
- comments are not tracked
- partitions are not tracked
- alter publication ... add table ...
- create domain statements are ignored
- grant statements are duplicated from default privileges
---
**Non-compliance with these instructions may lead to inconsistent database states and is strictly prohibited.**

View File

@@ -1,7 +1,7 @@
---
# Specify the following for Cursor rules
description: Guidelines for writing Postgres SQL
globs: **/*.sql
alwaysApply: false
---
# Postgres SQL Style Guide

View File

@@ -1,6 +1,6 @@
---
description: Coding rules for Supabase Edge Functions
globs: supabase/functions/**/*.ts
alwaysApply: false
---
# Writing Supabase Edge Functions

View File

@@ -1,7 +1,7 @@
---
# Specify the following for Cursor rules
description: Guidelines for writing Postgres SQL
globs: "**/*.sql"
alwaysApply: false
---
# Postgres SQL Style Guide

View File

@@ -1,7 +1,7 @@
---
# Specify the following for Cursor rules
description: Guidelines for writing Postgres migrations
globs: "supabase/migrations/**/*.sql"
alwaysApply: false
---
# Database: Create migration

View File

@@ -1,7 +1,7 @@
---
# Specify the following for Cursor rules
description: Guidelines for writing Supabase database functions
globs: "**/*.sql"
alwaysApply: false
---
# Database: Create functions

View File

@@ -1,7 +1,7 @@
---
# Specify the following for Cursor rules
description: Guidelines for writing Postgres Row Level Security policies
globs: "**/*.sql"
alwaysApply: false
---
# Database: Create RLS policies

View File

@@ -0,0 +1,78 @@
---
# Specify the following for Cursor rules
description: For when modifying the Supabase database schema.
alwaysApply: false
---
# Database: Declarative Database Schema
Mandatory Instructions for Supabase Declarative Schema Management
## 1. **Exclusive Use of Declarative Schema**
-**All database schema modifications must be defined within `.sql` files located in the `supabase/schemas/` directory. -**Do not\*\* create or modify files directly in the `supabase/migrations/` directory unless the modification is about the known caveats below. Migration files are to be generated automatically through the CLI.
## 2. **Schema Declaration**
-For each database entity (e.g., tables, views, functions), create or update a corresponding `.sql` file in the `supabase/schemas/` directory
-Ensure that each `.sql` file accurately represents the desired final state of the entity
## 3. **Migration Generation**
- Before generating migrations, **stop the local Supabase development environment**
```bash
supabase stop
```
- Generate migration files by diffing the declared schema against the current database state
```bash
supabase db diff -f <migration_name>
```
Replace `<migration_name>` with a descriptive name for the migration
## 4. **Schema File Organization**
- Schema files are executed in lexicographic order. To manage dependencies (e.g., foreign keys), name files to ensure correct execution order
- When adding new columns, append them to the end of the table definition to prevent unnecessary diffs
## 5. **Rollback Procedures**
- To revert changes
- Manually update the relevant `.sql` files in `supabase/schemas/` to reflect the desired state
- Generate a new migration file capturing the rollback
```bash
supabase db diff -f <rollback_migration_name>
```
- Review the generated migration file carefully to avoid unintentional data loss
## 6. **Known caveats**
The migra diff tool used for generating schema diff is capable of tracking most database changes. However, there are edge cases where it can fail.
If you need to use any of the entities below, remember to add them through versioned migrations instead.
### Data manipulation language
- DML statements such as insert, update, delete, etc., are not captured by schema diff
### View ownership
- view owner and grants
- security invoker on views
- materialized views
- doesnt recreate views when altering column type
### RLS policies
- alter policy statements
- column privileges
- Other entities#
- schema privileges are not tracked because each schema is diffed separately
- comments are not tracked
- partitions are not tracked
- alter publication ... add table ...
- create domain statements are ignored
- grant statements are duplicated from default privileges
---
**Non-compliance with these instructions may lead to inconsistent database states and is strictly prohibited.**

View File

@@ -1,7 +1,7 @@
---
# Specify the following for Cursor rules
description: Coding rules for Supabase Edge Functions
globs: "supabase/functions/**/*.ts"
alwaysApply: false
---
# Writing Supabase Edge Functions

View File

@@ -1,7 +1,7 @@
---
# Specify the following for Cursor rules
description: Guidelines for writing Next.js apps with Supabase Auth
globs: "**/*.ts, **/*.tsx, **/*.js, **/*.jsx"
alwaysApply: false
---
# Bootstrap Next.js app with Supabase Auth