data-migration-scripts▌
aj-geddes/useful-ai-prompts · updated Apr 8, 2026
Create robust, safe, and reversible data migration scripts for database schema changes and data transformations with minimal downtime.
Data Migration Scripts
Table of Contents
Overview
Create robust, safe, and reversible data migration scripts for database schema changes and data transformations with minimal downtime.
When to Use
- Database schema changes
- Adding/removing/modifying columns
- Migrating between database systems
- Data transformations and cleanup
- Splitting or merging tables
- Changing data types
- Adding indexes and constraints
- Backfilling data
- Multi-tenant data migrations
Quick Start
Minimal working example:
import { Knex } from "knex";
// migrations/20240101000000_add_user_preferences.ts
export async function up(knex: Knex): Promise<void> {
// Create new table
await knex.schema.createTable("user_preferences", (table) => {
table.uuid("id").primary().defaultTo(knex.raw("gen_random_uuid()"));
table
.uuid("user_id")
.notNullable()
.references("id")
.inTable("users")
.onDelete("CASCADE");
table.jsonb("preferences").defaultTo("{}");
table.timestamp("created_at").defaultTo(knex.fn.now());
table.timestamp("updated_at").defaultTo(knex.fn.now());
table.index("user_id");
});
// Migrate existing data
await knex.raw(`
INSERT INTO user_preferences (user_id, preferences)
SELECT id, jsonb_build_object(
'theme', COALESCE(theme, 'light'),
// ... (see reference guides for full implementation)
Reference Guides
Detailed implementations in the references/ directory:
| Guide | Contents |
|---|---|
| Knex.js Migrations (Node.js) | Knex.js Migrations (Node.js) |
| Alembic Migrations (Python/SQLAlchemy) | Alembic Migrations (Python/SQLAlchemy) |
| Large Data Migration with Batching | Large Data Migration with Batching |
| Zero-Downtime Migration Pattern | Zero-Downtime Migration Pattern |
| Migration Validation | Migration Validation |
| Cross-Database Migration | Cross-Database Migration |
Best Practices
✅ DO
- Always write both
upanddownmigrations - Test migrations on production-like data
- Use transactions for atomic operations
- Process large datasets in batches
- Add indexes after data insertion
- Validate data after migration
- Log progress and errors
- Use feature flags for application code changes
- Back up database before running migrations
- Test rollback procedures
- Document migration side effects
- Version control all migrations
- Use idempotent operations
❌ DON'T
- Run untested migrations on production
- Make breaking changes without backwards compatibility
- Process millions of rows in single transaction
- Skip rollback implementation
- Ignore migration failures
- Modify old migrations
- Delete data without backups
- Run migrations manually in production
Discussion
Product Hunt–style comments (not star reviews)- No comments yet — start the thread.
Ratings
4.5★★★★★30 reviews- ★★★★★Pratham Ware· Dec 24, 2024
Registry listing for data-migration-scripts matched our evaluation — installs cleanly and behaves as described in the markdown.
- ★★★★★Alexander Kapoor· Dec 24, 2024
data-migration-scripts fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.
- ★★★★★Dhruvi Jain· Dec 20, 2024
We added data-migration-scripts from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.
- ★★★★★Charlotte Jackson· Dec 20, 2024
data-migration-scripts is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.
- ★★★★★Zara Park· Nov 23, 2024
Registry listing for data-migration-scripts matched our evaluation — installs cleanly and behaves as described in the markdown.
- ★★★★★Daniel Johnson· Nov 15, 2024
We added data-migration-scripts from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.
- ★★★★★Oshnikdeep· Nov 11, 2024
data-migration-scripts fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.
- ★★★★★Charlotte Wang· Nov 11, 2024
Solid pick for teams standardizing on skills: data-migration-scripts is focused, and the summary matches what you get after install.
- ★★★★★Zara Sanchez· Oct 14, 2024
Keeps context tight: data-migration-scripts is the kind of skill you can hand to a new teammate without a long onboarding doc.
- ★★★★★Daniel Malhotra· Oct 6, 2024
Solid pick for teams standardizing on skills: data-migration-scripts is focused, and the summary matches what you get after install.
showing 1-10 of 30