Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Goose Migration Handling for Interleaved Migration Files #792

Open
scaletech-milan opened this issue Jul 15, 2024 · 1 comment
Open

Comments

@scaletech-milan
Copy link

scaletech-milan commented Jul 15, 2024

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:

  • Migrations should be applied based on their logical dependency order rather than solely relying on the timestamp or version number.
  • The goose package should support handling interleaved migrations effectively, allowing developers to apply migrations created in between existing ones without encountering missing migration errors.

Proposed Solution:

  • Implement dependency tracking between migration files to determine the order of execution based on schema dependencies rather than timestamp or version number.

Additional Context:

  • This issue is critical for teams working concurrently on database schema changes, where multiple developers may create migrations that are interleaved in the timeline.
  • Enhancing migration handling will improve developer productivity and reduce errors related to applying migrations out of order.
@scaletech-milan
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants