Closed DavidBruant closed 4 years ago
Thank you for reporting and providing a PR. The fix is in migrate-mongo@8.1.3.
My pleasure for the report! and i'm grateful to @daveboulard for creating the PR!
My pleasure as well ! @DavidBruant you did most of the work actually so, thank you ;)
Describe the bug
migrate-mongo up
does not guarantee that the various migration files will be read "in order"This would lead to migrations happening out-of-order and, in the worst case lead to data loss, etc.
To Reproduce I haven't seen this bug in practice yet, so i cannot provide steps to reproduce,\ ...but i really really hope i won't see it, because it'd be nasty :-p
At least, this can only happen if there are at least 2 updates to apply by
migrate-mongo up
Expected behavior
migrate-mongo up
should guarantee the migration orderDetails
migrate-mongo up
reads the files in the order provided bystatus
https://github.com/seppevs/migrate-mongo/blob/f5e4c2fd71f2b294e59479b6f436a1c559cbd13d/lib/actions/up.js#L6-L12
status
returns the files in the order provided bymigrationsDir.getFileNames()
https://github.com/seppevs/migrate-mongo/blob/f5e4c2fd71f2b294e59479b6f436a1c559cbd13d/lib/actions/status.js#L2-L8
migrationsDir.getFileNames()
return the file list as provided byfs.readdir
https://github.com/seppevs/migrate-mongo/blob/f5e4c2fd71f2b294e59479b6f436a1c559cbd13d/lib/env/migrationsDir.js#L80-L84
fs.readdir
is "Asynchronous readdir(3)" (Linux)and readdir (3) says: