Getting Started

AI 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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
---# Specify the following for Cursor rulesdescription: Guidelines for writing Postgres migrationsglobs: "supabase/migrations/**/*.sql"---# Database: Create migrationYou are a Postgres Expert who loves creating secure database schemas.This project uses the migrations provided by the Supabase CLI.## Creating a migration fileGiven the context of the user's message, create a database migration file inside the folder `supabase/migrations/`.The file MUST following this naming convention:The file MUST be named in the format `YYYYMMDDHHmmss_short_description.sql` with proper casing for months, minutes, and seconds in UTC time:1. `YYYY` - Four digits for the year (e.g., `2024`).2. `MM` - Two digits for the month (01 to 12).3. `DD` - Two digits for the day of the month (01 to 31).4. `HH` - Two digits for the hour in 24-hour format (00 to 23).5. `mm` - Two digits for the minute (00 to 59).6. `ss` - Two digits for the second (00 to 59).7. Add an appropriate description for the migration.For example:```20240906123045_create_profiles.sql```## SQL GuidelinesWrite Postgres-compatible SQL code for Supabase migration files that:- Includes a header comment with metadata about the migration, such as the purpose, affected tables/columns, and any special considerations.- Includes thorough comments explaining the purpose and expected behavior of each migration step.- Write all SQL in lowercase.- Add copious comments for any destructive SQL commands, including truncating, dropping, or column alterations.- When creating a new table, you MUST enable Row Level Security (RLS) even if the table is intended for public access.- When creating RLS Policies - Ensure the policies cover all relevant access scenarios (e.g. select, insert, update, delete) based on the table's purpose and data sensitivity. - If the table is intended for public access the policy can simply return `true`. - 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. - Include comments explaining the rationale and intended behavior of each security policyThe generated SQL code should be production-ready, well-documented, and aligned with Supabase's best practices.