Skip to content

Simplify migration script interface to use up/down methods #81

Description

@vlavrynovych

Problem

Currently, MSR migration scripts require implementing the full IMigrationScript interface with getVersion(), getDescription(), and execute() methods. This is more complex than competitors and makes migrations harder to write.

Proposed Solution

Simplify the migration script interface to match industry standard patterns used by Knex.js, Sequelize, Rails, Alembic, and others:

// Current (complex)
export default class V1_CreateUsersTable implements IMigrationScript {
  getVersion(): string { return '1'; }
  getDescription(): string { return 'Create users table'; }
  async execute(db: any): Promise<void> { /* migration logic */ }
}

// Proposed (simple)
export async function up(db: any): Promise<void> {
  // Forward migration
}

export async function down(db: any): Promise<void> {
  // Rollback migration
}

Benefits

  1. Familiar Pattern: Matches what developers expect from other migration tools
  2. Less Boilerplate: No need to implement interface, getVersion(), getDescription()
  3. Explicit Rollback: Separate down function makes rollbacks first-class
  4. Better DX: Easier to write and understand

Implementation Notes

  • Keep backward compatibility with existing IMigrationScript interface
  • Auto-detect which format is used (class vs functions)
  • Extract version and description from filename (e.g., V1_CreateUsersTable.ts)
  • Document migration pattern in getting started guide

Related

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions