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

Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.

Tu es un expert en administration de bases de données et en migrations de données en production. Je dois créer un script de migration pour ma base de données.

Contexte de la migration :

  • Base de données : [EX: PostgreSQL 14, MySQL 8, SQLite]
  • ORM/outil de migration : [EX: Prisma, Knex, Alembic, Flyway, migration SQL brut]
  • Schéma actuel : [DESCRIPTION_OU_DDL_ACTUEL]
  • Schéma cible : [DESCRIPTION_DES_CHANGEMENTS]
  • Volume de données à migrer : [EX: 500k lignes dans la table users]
  • Contrainte de disponibilité : [EX: zéro downtime requis, maintenance acceptée de 5min]

Type de migration :
[EX: ajout de colonne, renommage de table, changement de type, dénormalisation, migration de données entre tables]

Crée les scripts de migration complets :

  1. Script UP (migration) : le script de migration complet, transactionnel si possible, avec commentaires expliquant chaque étape.
  2. Script DOWN (rollback) : un script de rollback complet permettant de revenir à l'état précédent.
  3. Validation pre-migration : requêtes SQL pour vérifier l'état initial et détecter des anomalies avant de lancer la migration.
  4. Validation post-migration : requêtes pour vérifier que la migration s'est bien déroulée (compte de lignes, contraintes, cohérence).
  5. Stratégie zéro downtime : si applicable, explique comment déployer cette migration sans interruption de service (expand-contract pattern).
  6. Estimation du temps : estime la durée de la migration selon le volume de données.

Personalize this prompt with Léa

Léa rewrites this prompt for your job and your exact goal — 3 quick questions.

Why this prompt works

<p>This prompt approaches database migration as a five-phase process (pre-validation, migration, post-validation, rollback, monitoring) corresponding to best practices for change management in production. Many developers only write the UP script and forget the rollback until the moment they need it.</p><p>Requesting pre/post validation scripts is often overlooked but critical: it detects data issues before migration (e.g., duplicates that would prevent adding a UNIQUE constraint) and confirms success afterward.</p><p>The expand-contract pattern mentioned for zero downtime is an advanced but essential technique for high-availability applications: deploy code compatible with both old AND new schema before migration, then remove the old code afterward.</p>

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

  • LéaAI

    Pour réduire le risque en production, ajoute une étape de test du script DOWN sur un jeu de données résiduel (10 % du volume) avant la migration réelle. Cela valide le rollback sans engager le coût complet.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Go further

Similar Prompts

💻DeveloppementAdvancedAll AIs

Analyze and Optimize Algorithmic Complexity

Analyze the Big O complexity of your algorithms and optimize them with appropriate data structures and more efficient algorithms.

0699
💻DeveloppementAdvancedAll AIs

Kubernetes Backup Strategy

Kubernetes Disaster Recovery Plan

0316
💻DeveloppementAdvancedAll AIs

Create a capacity planning report

Plan infrastructure capacity

0416
💻DeveloppementIntermediateAll AIs

Convert Code Between Programming Languages with AI

A prompt to convert code from one programming language to another while respecting the conventions, native idioms and best practices of the target language.

0446