pressly / goose

A database migration tool. Supports SQL migrations and Go functions.
http://pressly.github.io/goose/
Other
6.58k stars 505 forks source link

Improve Goose Migration Handling for Interleaved Migration Files #792

Open scaletech-milan opened 1 month ago

scaletech-milan commented 1 month ago

Problem Description: Currently, the goose package does not handle interleaved migration files effectively when developers work concurrently on different migrations. This causes issues when a developer attempts to apply migrations that were created in between existing ones, resulting in missing migration errors.

Steps to Reproduce:

  1. Developer A adds migration files for user and admin tables, which are merged and applied in production.
  2. Meanwhile, Developer B creates a migration for the roles table and alters the user table, with their changes existing between Developer A's migrations.
  3. When Developer B attempts to apply their migrations using goose up, they encounter an error indicating missing migrations before the current version, despite the necessary migration files existing.

For exa- migration

> goose -dir db/migrations postgres "postgresql://postgres:postgres@127.0.0.1:5432/go-migartion?sslmode=disable" up  
2024/07/15 18:13:28 goose run: error: found 2 missing migrations before current version 20240715084701:
    version 20240715084646: db/migrations/20240715084646_new_roles_table.sql
    version 20240715084655: db/migrations/20240715084655_alter_table_users.sql

Expected Behavior:

Proposed Solution:

Additional Context:

scaletech-milan commented 1 month ago

If anyone has encountered this issue before, please notify me immediately so I can prioritize fixing it.