Database migration script generator prompt
Describe a schema change and get a migration script with up and down steps, plus a note on any data-loss risk.
متى تستخدم هذا البرومبت
- When adding, renaming, or removing a column or table.
- When backfilling data as part of a schema change.
- When writing a rollback plan before a risky migration.
نص البرومبت
Write a {{language}} database migration that: {{focus}}. Target: {{framework}}. Include both the up and down migration, and note any risk of data loss.
{{CLIPBOARD}}{{language}}{{focus}}{{framework}}{{CLIPBOARD}}الكتلة {{CLIPBOARD}} تُستبدل تلقائياً بما نسخته قبل الضغط على «نسخ».
كيف تستخدمه
- انسخ البرومبت بالزر أو املأ المتغيرات أولاً.
- الصقه في ChatGPT أو Claude أو Gemini.
- عدّل النتيجة أو أعد الطلب بتغيير المتغيرات.
مثال على النتيجة
-- Up ALTER TABLE users ADD COLUMN last_login_at TIMESTAMP; -- Down ALTER TABLE users DROP COLUMN last_login_at; Risk: the down migration is destructive, any last_login_at data written after the up migration will be permanently lost on rollback.
نصائح للاستخدام
- Name your migration tool (Prisma, Rails, Alembic, Flyway, raw SQL) for the correct file format.
- Always review the down migration yourself before running it against production data.
- For renames or type changes, ask specifically about backward compatibility during a rolling deploy.
أسئلة شائعة
- Is it safe to run the down migration on production?
- Not automatically; the prompt flags data-loss risk, but you should test rollbacks on a staging copy first.
- Can it write a data backfill migration, not just schema changes?
- Yes, describe the backfill logic needed in the focus field and it will include the data-transformation step.