postgres-migrations
postgres-migrations copied to clipboard
Hash mismatch when running the same migration on different OS (Windows and macOS)
There's a hash mismatch when running the same migration on different operating systems. I believe it's due to the line endings, the hash that gets generated is different. What's the possible solution to this? Will replacing CRLF with LF fix this?
Hi, thanks for the bug report.
Could you explain what practical problem this causes?
Do you have apps running on different OSs connecting to the same shared database and both doing migrations? If so... can I ask why?
The situation is: There are 2 developers, one uses Windows and the other one uses macOS. However, to populate the local DB, we bring in the data from our staging DB (restore it through pg_restore).
Now the migrations validation works without any issue on macOS but on Windows, they fail because the local files are checked out with CR LF endings by git. Therefore, there's a hash mismatch. The PR converts the CR LF line endings to LF before calculating the hash.
Great, thanks. That's useful context.
Since this is essentially a breaking change on Windows, in my mind this potentially needs a new major version.
I have some other changes I'd like to merge in as well (#58) so I'll find some time soon to get those changes in and release them.
Probably, faced the same problem. Initially ran migration on Windows. After that tried to run same migration on the same DB but in wsl2 ubuntu. Got:
Migration failed. Reason: Hashes don't match for migrations
I think hash should be generated after formatting the SQL file without any excessive new space or any new line at all. So that even with formatting differences, the output of the hash is the same.
I ended up forking and making the migrator log hash differences but not prevent the migrations from running. This is fine as the project is only for me so there isn't a chance of index clashes etc.
Faced this issue recently, ended up patching the package with pnpm patch
.