Supabase Migration Skill
English
Description
When the user asks to create or apply a database migration for Supabase, follow these instructions:
Instructions
- Check Environment: Ensure
supabase/migrationsdirectory exists. Runlist_diron it if needed. - Review Available MCP Commands: Utilize the Supabase MCP integration.
- For listing existing migrations, use
mcp_supabase-mcp-server_list_migrationswithproject_id. - Before executing migration queries on the server directly, confirm the SQL is correct.
- For listing existing migrations, use
- Execute Command:
- Write the SQL script to a local migration file located in
supabase/migrations/usingwrite_to_file. Use standard timestamps orsupabase migration newcommand to get the filename. - Run
npx supabase migration upto test locally or use the remote MCPapply_migrationif the user wants it applied remotely.
- Write the SQL script to a local migration file located in
- Final Step: Confirm with the user that the migration successfully completed.
Implementation Checklist
- Generate a new migration file:
npx supabase migration new [name] - Write raw SQL in the generated migration file (DDL and DML).
- Test the migration locally:
npx supabase db resetornpx supabase migration up. - If using RLS, explicitly add policies to the new tables.
- Commit the migration file to version control.
Example: Supabase Migration Command Flow
# 1. Create a new migration file
npx supabase migration new create_users_table
# 2. Write SQL to supabase/migrations/<timestamp>_create_users_table.sql
# 3. Apply to local database
npx supabase migration up
# 4. Apply to remote production database
npx supabase db push
Orchestration & Integration
- Integrates with:
supabase-security-expert,database-orm-expert,ci-cd-devops-architect.
Bahasa Indonesia
Deskripsi
Ketika pengguna meminta untuk membuat atau menerapkan migrasi database untuk Supabase, ikuti instruksi berikut:
Instruksi
- Periksa Lingkungan: Pastikan direktori
supabase/migrationsada. Jalankanlist_dirjika diperlukan. - Tinjau Perintah MCP yang Tersedia: Manfaatkan integrasi Supabase MCP.
- Untuk mencantumkan migrasi yang ada, gunakan
mcp_supabase-mcp-server_list_migrationsdenganproject_id. - Sebelum menjalankan kueri migrasi di server secara langsung, pastikan kode SQL-nya sudah benar.
- Untuk mencantumkan migrasi yang ada, gunakan
- Jalankan Perintah:
- Tulis skrip SQL ke file migrasi lokal yang terletak di
supabase/migrations/menggunakanwrite_to_file. Gunakan timestamp standar atau perintahsupabase migration newuntuk mendapatkan nama file. - Jalankan
npx supabase migration upuntuk menguji secara lokal atau gunakan MCP remoteapply_migrationjika pengguna ingin menerapkannya secara remote.
- Tulis skrip SQL ke file migrasi lokal yang terletak di
- Langkah Terakhir: Konfirmasikan dengan pengguna bahwa migrasi telah berhasil diselesaikan.
Checklist Implementasi
- Buat file migrasi baru:
npx supabase migration new [nama] - Tulis SQL mentah di file migrasi yang dihasilkan (DDL dan DML).
- Uji migrasi secara lokal:
npx supabase db resetataunpx supabase migration up. - Jika menggunakan RLS, tambahkan kebijakan secara eksplisit ke tabel baru.
- Commit file migrasi ke sistem kontrol versi.
Contoh: Alur Perintah Migrasi Supabase
# 1. Buat file migrasi baru
npx supabase migration new create_users_table
# 2. Tulis SQL ke supabase/migrations/<timestamp>_create_users_table.sql
# 3. Terapkan ke database lokal
npx supabase migration up
# 4. Terapkan ke database remote produksi
npx supabase db push
Integrasi Orkestrasi
- Terintegrasi dengan:
supabase-security-expert,database-orm-expert,ci-cd-devops-architect.