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.
100% found this useful

Personalize this prompt with Léa

Answer 3 questions and Léa tailors the prompt to your situation.

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

💻DeveloppementBeginnerAll AIs

Convert CSS to Tailwind

Migrate styling to Tailwind

090
💻DeveloppementIntermediateAll AIs

Refactor legacy code to modern patterns

Gradually modernizing legacy code

0100
💻DeveloppementIntermediateGemini

Gemini Prompt for Generating SQL Queries

Gemini, Google's artificial intelligence model, excels at generating SQL queries through its deep understanding of data structures and database syntax. Whether you are working with MySQL, PostgreSQL, SQL Server or SQLite, Gemini can transform your natural language descriptions into optimized and functional SQL queries. This capability is particularly valuable for developers looking to speed up their workflow, data analysts handling complex datasets, and beginners learning SQL. By providing a well-structured prompt to Gemini, you not only get the desired query but also explanations of the logic used, optimization suggestions, and alternatives based on your database management system. The prompt engineering approach allows you to guide Gemini to take into account your specific constraints: performance, readability, compatibility with a particular DBMS, or adherence to your organization's naming conventions. Discover how to formulate your prompts to get the most out of Gemini in generating SQL queries.

0112
💻DeveloppementIntermediateAll AIs

Implement secrets management

Secure credentials management

0102