Skip to content

Add validation to prevent duplicate migration timestamps #82

@vlavrynovych

Description

@vlavrynovych

Problem

Users can accidentally create two migrations with the same timestamp, which causes:

  • Undefined execution order
  • Potential overwrites in version tracking
  • Confusing errors during migration runs

This is especially problematic when:

  • Multiple developers work on migrations simultaneously
  • Migrations are created in rapid succession
  • Generated timestamps collide (same second)

Proposed Solution

Add validation that detects and prevents duplicate timestamps:

// During migration scanning
const timestamps = new Set<string>();
for (const migration of migrations) {
  if (timestamps.has(migration.version)) {
    throw new Error(
      `Duplicate migration timestamp detected: ${migration.version}\n` +
      `This can cause undefined behavior. Please rename one of:\n` +
      `  - ${migration1.filename}\n` +
      `  - ${migration2.filename}`
    );
  }
  timestamps.add(migration.version);
}

Validation Scenarios

  1. At Scan Time: Check for duplicates when discovering migrations
  2. At Generation Time: When creating new migration, check existing ones
  3. Clear Error Messages: Tell user exactly which files conflict

Benefits

  1. Prevent Data Corruption: Stop migrations before they run with undefined order
  2. Early Detection: Fail fast with clear error message
  3. Developer Safety: Catch mistakes before production
  4. Better UX: Clear guidance on how to fix the issue

Implementation Notes

  • Add to MigrationScanner service
  • Include in migration template generator (#TBD)
  • Show both conflicting filenames in error
  • Suggest resolution: rename one migration with new timestamp
  • Add test cases for duplicate detection

Related

Metadata

Metadata

Assignees

Labels

⚡ Priority: HighImportant tasks requiring quick attention✨ Type: FeatureNew functionality or enhancement🟢 Test: LowMinimal testing effort needed

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions