Write a Database Migration Script
Create complete, reversible, and secure database migration scripts with pre/post validation and a zero-downtime strategy.
Paste in your AI
Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.
You are an expert in database administration and production data migrations. I need to create a migration script for my database.
Migration context:
- Database: [e.g. PostgreSQL 14, MySQL 8, SQLite]
- ORM/migration tool: [e.g. Prisma, Knex, Alembic, Flyway, raw SQL migration]
- Current schema: [CURRENT_DESCRIPTION_OR_DDL]
- Target schema: [DESCRIPTION_OF_CHANGES]
- Volume of data to migrate: [e.g. 500k rows in the users table]
- Availability constraint: [e.g. zero downtime required, 5-minute maintenance window acceptable]
Migration type:
[e.g. adding a column, renaming a table, changing a type, denormalization, migrating data between tables]
Create the complete migration scripts:
- UP script (migration): the complete migration script, transactional if possible, with comments explaining each step.
- DOWN script (rollback): a complete rollback script to restore the previous state.
- Pre-migration validation: SQL queries to check the initial state and detect anomalies before running the migration.
- Post-migration validation: queries to verify that the migration succeeded (row counts, constraints, consistency).
- Zero-downtime strategy: if applicable, explain how to deploy the migration without service interruption (expand-contract pattern).
- Time estimate: estimate the migration duration based on the data volume.
Personalize this prompt with Léa · AI assistant
Léa rewrites this prompt for your job and your exact goal — 3 quick questions.
Why this prompt works
Describe both the current schema and the target schema. Include table sizes and the downtime you can tolerate. The pre-migration checks can catch duplicates before you add a unique constraint. The post-migration checks verify row counts and data integrity. Review the rollback alongside the forward migration. For a system that must stay available, ask for an expand-and-contract sequence that allows old and new application versions to run during the transition.
Use Cases
Expected Output
Complete UP and DOWN scripts, pre/post migration validation queries, deployment strategy, and execution time estimate.
Improve this prompt
Run this prompt through the Optimizer to strengthen its context, constraints and expected format.
Improve this prompt with the OptimizerComments
Be the first to comment on this prompt.
Glossary Terms
📬 Get new prompts every week
Join our newsletter and never miss a prompt.
Go further
Improve this prompt with the Optimizer
Analyze the prompt, strengthen the context and get a more precise version.
ChatGPT Prompts
Core techniques to guide ChatGPT more effectively.
AI prompts for web developers
Code review and debugging, keeping API keys and secrets out of the prompt.
Security, GDPR & Business Plans
ChatGPT Business, Claude Team, Gemini Workspace and Mistral Vibe compared from vendor sources: training, EU hosting and a GDPR checklist.
Similar Prompts
Task brief for Claude Code: frame a feature end to end
Brief template to delegate a complete feature to Claude Code: goal, starting point, constraints, definition of done, working rules and recap format.
Write a project's CLAUDE.md: the brief Claude Code reads at every session
Turns your project description into a dense CLAUDE.md: commands, structure, conventions, pitfalls, off-limits areas and situations where the agent must ask before acting.
Design a Secure Webhook API
Design a webhook API with event subscriptions, signed deliveries, retry limits, and a delivery log your support team can inspect.
Generate Storybook Stories for UI Components
Generate Storybook stories for a UI component, with visual variants, interactive controls, interaction tests, and MDX documentation.