Automate Database Migrations with AI
A comprehensive prompt to generate automated database migration scripts with rollback, validation, CI/CD integration and zero-downtime strategy.
Paste in your AI
Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.
Tu es un ingénieur base de données senior spécialisé en automatisation des migrations. Tu maîtrises les outils de migration (Flyway, Liquibase, Alembic, Knex, Drizzle, Prisma) et les bonnes pratiques de gestion de schéma en production.
Contexte du projet :
- SGBD utilisé : [SGBD : ex. PostgreSQL, MySQL, SQLite, SQL Server]
- Outil de migration ou ORM : [OUTIL_MIGRATION : ex. Alembic, Drizzle, Prisma, Flyway, Knex, migration manuelle SQL]
- Langage backend : [LANGAGE : ex. Python, TypeScript, Java, Go]
- Description du changement de schéma souhaité : [DESCRIPTION_CHANGEMENT : ex. ajouter une colonne 'status' à la table 'orders', renommer une table, créer une relation many-to-many]
- Environnement cible : [ENVIRONNEMENT : ex. développement local, staging, production]
Génère une migration complète et automatisée en respectant ces exigences :
- Script de migration UP : le changement de schéma demandé, avec les types de données appropriés, les contraintes (NOT NULL, DEFAULT, INDEX) et les commentaires explicatifs.
- Script de migration DOWN (rollback) : l'opération inverse exacte pour revenir à l'état précédent, en gérant la perte de données potentielle.
- Script de migration de données (si applicable) : si le changement nécessite de transformer ou déplacer des données existantes, fournis le script de data migration séparé.
- Validation pré-migration : une requête SQL ou un script qui vérifie les prérequis avant d'exécuter la migration (existence de tables, absence de conflits).
- Validation post-migration : une requête ou un test qui confirme que la migration s'est bien appliquée.
- Script CI/CD : un extrait de pipeline (GitHub Actions, GitLab CI ou script bash) pour exécuter automatiquement les migrations lors du déploiement.
- Stratégie zero-downtime : si l'environnement est la production, propose une approche de migration sans interruption de service (expand-contract, blue-green, etc.).
Pour chaque élément, ajoute des commentaires expliquant le raisonnement et les risques potentiels. Signale explicitement toute opération destructive ou irréversible.
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 transforms the AI into a database engineer capable of producing complete, production-ready migrations. By specifying your <strong>DBMS</strong>, your <strong>migration tool</strong> and the <strong>change description</strong>, you get a deliverable directly integrable into your workflow.</p><p>The approach covers the entire migration lifecycle: the UP script to apply the change, the DOWN script to roll back, pre and post-execution validation, and integration into your CI/CD pipeline. This eliminates common oversights like missing rollback or lack of post-deployment tests.</p><p>For production environments, the prompt explicitly requests a <strong>zero-downtime strategy</strong>, which pushes the AI to propose patterns like expand-contract or multi-phase migrations. Adapt the variables to your stack: a Python/Alembic project will not have the same output as a TypeScript/Drizzle project, and that is precisely the point of customization.</p>
Use Cases
Expected Output
A complete set of migration scripts (UP, DOWN, data migration), pre and post-migration validation queries, a ready-to-use CI/CD pipeline excerpt, and a documented strategy for zero-downtime migrations.
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.
📬 Get new prompts every week
Join our newsletter and never miss a prompt.