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

Extract and rewrite migrations #1407

Open
aljazerzen opened this issue Nov 25, 2024 · 0 comments
Open

Extract and rewrite migrations #1407

aljazerzen opened this issue Nov 25, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@aljazerzen
Copy link
Contributor

Recently we had a case where a user had gotten diverging migrations in production and staging databases.

They got there by:

  • creating a migration in VCS and successfully applying it to staging database,
  • trying to apply it to production database, where they failed,
  • replacing it with a fixed migration and successfully applying it to the production database.

The schemas of the two databases might be exactly the same, but last applied migration has a different hash, so going forward, new migrations cannot be applied to both databases.

EdgeDB has mechanisms for dealing with such scenarios (migration rewrites), but CLI uses them only when squashing migrations. We should use migration rewrites for this use case as well.


I'd suggest the following fixup path:

  • first, user needs to decide which migration history should be considered the "source of truth" (in the case above, that would probably be the production database),
  • edgedb-cli migration extract --force -I prod to override migrations in dbschema/migrations (this already exists),
  • now, create "fixup migrations" for each of the other databases that we want to move to the "source of truth" schema:
  • edgedb-cli migration extract --rewrite to create a "fixup migration" that would, when applied:
    a) migrate the database to the "source of truth" schema,
    b) apply a migration rewrite
@aljazerzen aljazerzen added the enhancement New feature or request label Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant