Agent skill

data-migration-scripts

Create safe, reversible database migration scripts with rollback capabilities, data validation, and zero-downtime deployments. Use when changing database schemas, migrating data between systems, or performing large-scale data transformations.

Stars 151
Forks 20

Install this agent skill to your Project

npx add-skill https://github.com/aj-geddes/useful-ai-prompts/tree/main/skills/data-migration-scripts

SKILL.md

Data Migration Scripts

Table of Contents

  • Overview
  • When to Use
  • Quick Start
  • Reference Guides
  • Best Practices

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:

typescript
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 up and down migrations
  • 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

Expand your agent's capabilities with these related and highly-rated skills.

aj-geddes/useful-ai-prompts

websocket-implementation

Implement real-time bidirectional communication with WebSockets including connection management, message routing, and scaling. Use when building real-time features, chat systems, live notifications, or collaborative applications.

151 20
Explore
aj-geddes/useful-ai-prompts

refactor-legacy-code

Modernize and improve legacy codebases while maintaining functionality. Use when you need to refactor old code, reduce technical debt, modernize deprecated patterns, or improve code maintainability without breaking existing behavior.

151 20
Explore
aj-geddes/useful-ai-prompts

Sentiment Analysis

Classify text sentiment using NLP techniques, lexicon-based analysis, and machine learning for opinion mining, brand monitoring, and customer feedback analysis

151 20
Explore
aj-geddes/useful-ai-prompts

flask-api-development

Develop lightweight Flask APIs with routing, blueprints, database integration, authentication, and request/response handling. Use when building RESTful APIs, microservices, or lightweight web services with Flask.

151 20
Explore
aj-geddes/useful-ai-prompts

ML Model Explanation

Interpret machine learning models using SHAP, LIME, feature importance, partial dependence, and attention visualization for explainability

151 20
Explore
aj-geddes/useful-ai-prompts

Statistical Hypothesis Testing

Conduct statistical tests including t-tests, chi-square, ANOVA, and p-value analysis for statistical significance, hypothesis validation, and A/B testing

151 20
Explore

Didn't find tool you were looking for?

Be as detailed as possible for better results