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

rerun SKIP does not work when using to and sequelize storage #588

Open
Lewenhaupt opened this issue Dec 12, 2022 · 2 comments
Open

rerun SKIP does not work when using to and sequelize storage #588

Lewenhaupt opened this issue Dec 12, 2022 · 2 comments

Comments

@Lewenhaupt
Copy link

Version: 3.2.1
Storage: SequelizeStorage
Dev setup: Typescript

Reproduction:

  1. Run migrations using .sql files first
  2. Rerun using 'to' to run to a specific migration, with rerun set to SKIP

Expected:
In this case it is expected that it would skip any migrations that have already been run.

Actual:
Migration fails with 'Couldn't find migration' Error because pending migrations will not include migrations found in SequelizeStorage making the rerun flag redundant and the behavior a bit broken.

It appears that the rerun flag is only applicable when 'migrations' are passed to up, not when 'to' is used.

We use AWS CustomResources to control migrations in our environment and that means we create the CustomResource with an up and down migration set and this causes them to fail if we for some reason need to rerun the underlying AWS Lambda with the same parameters. To solve this we need to be able to skip any migration that has already been run, instead of having it throw this error. Not sure about the approach here as rerun and to in this context seems to more mean that it would then only be that migration that would be skipped if it was already ran.

I guess a workaround would be to simple load the glob we use, sort it, and then slice at the 'to' index and run those migrations with rerun: 'SKIP'.

@mmkal
Copy link
Contributor

mmkal commented Dec 13, 2022

So I understand better, are you saying that the the --to target is the one that should be skipped? And that's why it errors because it skips it, then fails to find the target?

@Lewenhaupt
Copy link
Author

@mmkal This might be an error on my part, seems typescript resolved the types a bit strangely for me in my editor leading me to believe that --to could be used with rerun: 'SKIP' which it seems it's not supposed to. I.e. I don't think this is a bug really, but maybe more of a feature request.
And no not really, we kind of want everything up until --to to be skipped it was already ran. We worked around it by simply globbing all our .sql migrations ourselves first and entering that list, up to and including --to, and then using the migrations param instead. A bit hacky but it works.

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