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 :
- Script UP (migration) : le script de migration complet, transactionnel si possible, avec commentaires expliquant chaque étape.
- Script DOWN (rollback) : un script de rollback complet permettant de revenir à l'état précédent.
- Validation pre-migration : requêtes SQL pour vérifier l'état initial et détecter des anomalies avant de lancer la migration.
- Validation post-migration : requêtes pour vérifier que la migration s'est bien déroulée (compte de lignes, contraintes, cohérence).
- Stratégie zéro downtime : si applicable, explique comment déployer cette migration sans interruption de service (expand-contract pattern).
- 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
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
- 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
Brand Comment Responses
Consistent and fast social media community management
Complete Code Review for Pull Requests
Get an exhaustive code review covering quality, performance, security, and maintainability for any language.
Master Advanced TypeScript Types
Strengthen your code's type safety with advanced generics, utility types, and discriminated unions.
Perplexity Prompt for Generating Python Code
Perplexity AI stands out from other AI assistants with its unique ability to combine real-time web search and code generation. When it comes to producing Python code, this advantage is significant: Perplexity can rely on the latest official documentation, current best practices, and up-to-date libraries to generate reliable and modern code. Unlike a classic LLM whose knowledge is frozen at a cutoff date, Perplexity verifies its sources in real time, drastically reducing the risk of obsolete code or deprecated functions. Whether you are a developer looking to speed up your workflow, a data scientist wanting to prototype quickly, or a beginner learning Python, a well-structured prompt turns Perplexity into a true development assistant. The key lies in the precision of your request: by specifying the technical context, constraints, and expected output format, you get production-ready code rather than a generic snippet. This guide offers optimized prompts to get the most out of Perplexity in your Python projects.