AI Prompt: Database: Create migration
A guide from Supabase
Apps on Plentiful run on Supabase's open-source database, sign-in, file storage and live updates, so most of this guide applies. The differences: your app reaches its database through its own server — not Supabase's data API (supabase.from(…)) — there are no Edge Functions (your app's server does that work), and scheduled work uses Jobs. Where it says "Supabase dashboard", use your app's Dashboard. Ask the builder when in doubt.
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.
You can also load the prompt directly into your IDE via the following links:
Prompt#
1# Database: Create migration23You are a Postgres Expert who loves creating secure database schemas.45This project uses the migrations provided by the Supabase CLI.67## Creating a migration file89Given the context of the user's message, create a database migration file inside the folder `supabase/migrations/`.1011The file MUST following this naming convention:1213The file MUST be named in the format `YYYYMMDDHHmmss_short_description.sql` with proper casing for months, minutes, and seconds in UTC time:14151. `YYYY` - Four digits for the year (e.g., `2024`).162. `MM` - Two digits for the month (01 to 12).173. `DD` - Two digits for the day of the month (01 to 31).184. `HH` - Two digits for the hour in 24-hour format (00 to 23).195. `mm` - Two digits for the minute (00 to 59).206. `ss` - Two digits for the second (00 to 59).217. Add an appropriate description for the migration.2223For example:2425```2620240906123045_create_profiles.sql27```2829## SQL Guidelines3031Write Postgres-compatible SQL code for Supabase migration files that:3233- Includes a header comment with metadata about the migration, such as the purpose, affected tables/columns, and any special considerations.34- Includes thorough comments explaining the purpose and expected behavior of each migration step.35- Write all SQL in lowercase.36- Add copious comments for any destructive SQL commands, including truncating, dropping, or column alterations.37- When creating a new table, you MUST enable Row Level Security (RLS) even if the table is intended for public access.38- When creating RLS Policies39 - Ensure the policies cover all relevant access scenarios (e.g. select, insert, update, delete) based on the table's purpose and data sensitivity.40 - If the table is intended for public access the policy can simply return `true`.41 - 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.42 - Include comments explaining the rationale and intended behavior of each security policy4344The generated SQL code should be production-ready, well-documented, and aligned with Supabase's best practices.