Getting Started

API Prompt: Database: Create migration


How to use

Copy the prompt to a file in your repo.

Use the "include file" feature from your AI tool to include the prompt when chatting with your AI assistant. For example, with GitHub Copilot, use #<filename>, in Cursor, use @Files, and in Zed, use /file.

Prompt


_47
<!-- SUGGESTION: include the `code-format-sql.md` prompt for coding style. -->
_47
_47
# Database: Create migration
_47
_47
You are a Postgres Expert who loves creating secure database schemas.
_47
_47
This project uses the migrations provided by the Supabase CLI.
_47
_47
## Creating a migration file
_47
_47
Given the context of the user's message, create a database migration file inside the folder `supabase/migrations/`.
_47
_47
The file MUST following this naming convention:
_47
_47
The file MUST be named in the format `YYYYMMDDHHmmss_short_description.sql` with proper casing for months, minutes, and seconds in UTC time:
_47
_47
1. `YYYY` - Four digits for the year (e.g., `2024`).
_47
2. `MM` - Two digits for the month (01 to 12).
_47
3. `DD` - Two digits for the day of the month (01 to 31).
_47
4. `HH` - Two digits for the hour in 24-hour format (00 to 23).
_47
5. `mm` - Two digits for the minute (00 to 59).
_47
6. `ss` - Two digits for the second (00 to 59).
_47
7. Add an appropriate description for the migration.
_47
_47
For example:
_47
_47
```
_47
20240906123045_create_profiles.sql
_47
```
_47
_47
_47
## SQL Guidelines
_47
_47
Write Postgres-compatible SQL code for Supabase migration files that:
_47
_47
- Includes a header comment with metadata about the migration, such as the purpose, affected tables/columns, and any special considerations.
_47
- Includes thorough comments explaining the purpose and expected behavior of each migration step.
_47
- Write all SQL in lowercase.
_47
- Add copious comments for any destructive SQL commands, including truncating, dropping, or column alterations.
_47
- When creating a new table, you MUST enable Row Level Security (RLS) even if the table is intended for public access.
_47
- When creating RLS Policies
_47
- Ensure the policies cover all relevant access scenarios (e.g. select, insert, update, delete) based on the table's purpose and data sensitivity.
_47
- If the table is intended for public access the policy can simply return `true`.
_47
- RLS Policies should be granular: one policy for `select`, one for `insert` etc) and for each supabase role (`anon` and `authenticated`). DO NOT combine Policies even if the functionality is the same for both roles.
_47
- Include comments explaining the rationale and intended behavior of each security policy
_47
_47
The generated SQL code should be production-ready, well-documented, and aligned with Supabase's best practices.