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

Cannot run skipped migration without rolling back #164

Open
reffu42 opened this issue Aug 8, 2023 · 1 comment
Open

Cannot run skipped migration without rolling back #164

reffu42 opened this issue Aug 8, 2023 · 1 comment

Comments

@reffu42
Copy link

reffu42 commented Aug 8, 2023

Describe the bug
It doesn't seem like there's a way to force postgrator to run a script that has been skipped/missed without first rolling back (assuming you have an undo for every script in between) and then re-running.

To Reproduce

  1. Create a handful of scripts that make small changes to the database.
  2. Number them sequentially
  3. Skip a number and create one more (e.g. 001, 002, 003, 005)
  4. Run Postgrator
  5. Create a script for the skipped number (004)
  6. Run Postgrator again
  7. Note that because the script is less than the current "version" it does not run or get added to the schema_versions table

Expected behavior
Since the script has not yet been run and is not in the schema_versions table, it should be run (or at least make a command/option to "catch up" and run any missed scripts/numbers)

Additional context
This is useful in cases where you have a shared repository and multiple developers. It is also necessary if you have a "dev" and "prod" setup and need to commit a quick fix to the "prod" version while working on the "dev" version (e.g. script 039 is run in dev as part of a feature, but a bug in prod requires script 040 to fix it first. When 039 is pulled to prod, it will not run)

@Fran-Rg
Copy link

Fran-Rg commented Oct 30, 2023

The flaw is in the way the getRunnableMigrations is calculated: https://github.com/rickbergfalk/postgrator/blob/master/postgrator.js#L211-L234

It only checks for the versions higher than the latest applied.
If should also check for files that have not been applied which are lower than the latest migration.

Is it best practice? Not sure.
Is is unexpected behaviour? Not sure

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

No branches or pull requests

2 participants