Skill

Migrate Databases Across ORMs

Master schema and data migrations across Sequelize, TypeORM, and Prisma - with rollback strategies and zero-downtime patterns.

Works with sequelizetypeormprisma

91
Spark score
out of 100
Updated 22 days ago
Version 14.0.0

Add to Favorites

Why it matters

Automate complex database schema and data migrations, ensuring data integrity and minimizing downtime across different ORMs like Sequelize, TypeORM, and Prisma.

Outcomes

What it gets done

01

Perform schema transformations and data movement between databases.

02

Implement rollback strategies for safe migration execution.

03

Achieve zero-downtime deployments for critical database updates.

04

Manage database version upgrades and data model refactoring.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/ag-database-migration | bash

Overview

Database Migration

Covers schema and data migration patterns across Sequelize, TypeORM, and Prisma, including safe column changes, transaction- and checkpoint-based rollback, and blue-green zero-downtime deployments. Use when migrating between ORMs or databases, changing a schema, implementing rollback procedures, or planning a zero-downtime deployment.

What it does

Master database schema and data migrations across ORMs (Sequelize, TypeORM, Prisma), including rollback strategies and zero-downtime deployments. Covers three ORM migration formats side by side - Sequelize's up/down queryInterface pattern (run via npx sequelize-cli db:migrate, rolled back via db:migrate:undo), TypeORM's MigrationInterface class with QueryRunner (npm run typeorm migration:run/revert), and Prisma's schema.prisma model definitions (npx prisma migrate dev/deploy) - alongside schema transformation patterns for safely adding columns with defaults, renaming columns without downtime (add a new column, copy data, deploy code using it, then drop the old column in a later migration), and changing column types on large tables via a multi-step add/copy/drop/rename sequence. It documents a complex data migration example that parses a combined address_string into separate street/city/state columns row by row, with a symmetric down() that reconstructs the original column.

When to use - and when NOT to

Use this skill when migrating between different ORMs, performing schema transformations, moving data between databases, implementing rollback procedures, planning zero-downtime deployments, upgrading database versions, or refactoring the data model. It is not for tasks unrelated to database migration or for work in a different domain or tool outside this scope.

Inputs and outputs

Given a migration task, the skill outputs runnable migration code in the target ORM's format, always paired with a rollback (down()) implementation. It documents two rollback strategies - transaction-based migrations that wrap changes in a queryInterface transaction and roll back on error, and checkpoint-based rollback that snapshots a backup table, verifies the migration (e.g. checking for NULL values in a new column), and restores from the backup table if verification fails - plus a five-phase blue-green zero-downtime pattern (add a backward-compatible column, deploy dual-write code, backfill data, deploy code reading the new column, then remove the old one) and a cross-database example handling PostgreSQL JSONB versus MySQL JSON column-type differences via queryInterface.sequelize.getDialect().

// migrations/20231201-create-users.js
module.exports = {
  up: async (queryInterface, Sequelize) => {
    await queryInterface.createTable('users', {
      id: {
        type: Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true
      },
      email: {
        type: Sequelize.STRING,
        unique: true,
        allowNull: false
      },
      createdAt: Sequelize.DATE,
      updatedAt: Sequelize.DATE
    });
  },

  down: async (queryInterface, Sequelize) => {
    await queryInterface.dropTable('users');
  }
};

Integrations

Points to seven supporting resources: references/orm-switching.md, references/schema-migration.md, references/data-transformation.md, and references/rollback-strategies.md for deeper guides, plus assets/schema-migration-template.sql, assets/data-migration-script.py, and scripts/test-migration.sh for reusable templates and a migration test script. Eight best practices are stated explicitly - always provide rollback, test on staging first, use transactions for atomicity, backup before migrating, break changes into small incremental steps, monitor for errors during deployment, document why and how, and keep migrations idempotent/rerunnable - alongside six named common pitfalls: not testing rollback, breaking changes without a downtime strategy, mishandling NULL values, ignoring index performance, ignoring foreign key constraints, and migrating too much data at once.

Who it's for

Backend engineers and DBAs running schema or data migrations in production systems using Sequelize, TypeORM, or Prisma, who need concrete, rollback-safe patterns for zero-downtime column changes, cross-ORM or cross-database moves, and large-table transformations rather than ad-hoc one-off scripts.

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.