P
💻DeveloppementAdvancedChatGPT

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

Adapt this prompt

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:

  1. UP script (migration): the complete migration script, transactional if possible, with comments explaining each step.
  2. DOWN script (rollback): a complete rollback script to restore the previous state.
  3. Pre-migration validation: SQL queries to check the initial state and detect anomalies before running the migration.
  4. Post-migration validation: queries to verify that the migration succeeded (row counts, constraints, consistency).
  5. Zero-downtime strategy: if applicable, explain how to deploy the migration without service interruption (expand-contract pattern).
  6. 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

Production database migrationsSchema changes without downtimeRollback scripts for risky migrations

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 Optimizer

Comments

Be the first to comment on this prompt.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Go further

Similar Prompts

💻DeveloppementIntermediateClaude

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.

1678
💻DeveloppementIntermediateClaude

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.

639
💻DeveloppementAdvancedAll AIs

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.

411
💻DeveloppementIntermediateAll AIs

Generate Storybook Stories for UI Components

Generate Storybook stories for a UI component, with visual variants, interactive controls, interaction tests, and MDX documentation.

473