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 : 1. **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. 2. **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. 3. **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é. 4. **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). 5. **Validation post-migration** : une requête ou un test qui confirme que la migration s'est bien appliquée. 6. **Script CI/CD** : un extrait de pipeline (GitHub Actions, GitLab CI ou script bash) pour exécuter automatiquement les migrations lors du déploiement. 7. **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.
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.
Learn more
Check the full skill on Prompt Guide to master this technique from A to Z.
View on Prompt Guide📬 Get new prompts every week
Join our newsletter and never miss a prompt.
Similar Prompts
Create a Complete REST API from A to Z
A complete prompt to generate a professional REST API with authentication, validation, documentation, and integrated tests.
Debug Your Python Code with ChatGPT
A structured prompt to get a complete analysis of your Python bugs: identification, root cause explanation, commented fix, and prevention tips.
Write Professional and Robust Bash Scripts
A comprehensive prompt to generate robust, professional Bash scripts with error handling, argument parsing and built-in best practices.
Write Comprehensive Unit Tests
Generate an exhaustive unit test suite covering nominal cases, edge cases, and errors with appropriate mocks.