blakeembrey / node-immigration

Simple, no-frills migration utility
Other
17 stars 3 forks source link

Log and Unlog runs in parallel when run for multiple migrations #26

Closed joakimbeng closed 7 years ago

joakimbeng commented 7 years ago

Because of the Promise.all in both log and unlog Immigration tries to log/unlog migrations in parallel when run for multiple migrations (this should be a problem in the tidy method as well because it's built in the same way). This destroys the .migrate.json file if used with the fs plugin, and is probably bad for other plugins as well. In my case when running log for about 15 migrations only one (random) of them is stored in the .migrate.json and the file contains malformed json (it ends in triple }).

An Array.reduce would fix this, in the same way as the migrate method runs all migrations.

I will try and get some time fixing this and submitting a PR for it.

blakeembrey commented 7 years ago

Thanks for the issue. I was trying to think about how to improve this, since it really is only an issue with the fs plugin in particular, and what I've come up with is using an internal queue for mutation. That way the async nature can still be used with the other plugins. However, I am wondering if perhaps the plugin API should be changed to an array instead so database plugins can just insert multiple entries easier. Probably not worth breaking today since it's an oddity that would only be needed with a manual log anyway.