postgres-migrations icon indicating copy to clipboard operation
postgres-migrations copied to clipboard

Hash mismatch when running the same migration on different OS (Windows and macOS)

Open xeoneux opened this issue 3 years ago • 7 comments

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?

xeoneux avatar May 25 '21 23:05 xeoneux

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?

ThomWright avatar May 26 '21 08:05 ThomWright

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.

xeoneux avatar May 26 '21 13:05 xeoneux

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.

ThomWright avatar May 26 '21 21:05 ThomWright

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

Suvitruf avatar Nov 27 '21 06:11 Suvitruf

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.

xeoneux avatar Nov 27 '21 11:11 xeoneux

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.

oldschoolbg avatar Nov 27 '21 11:11 oldschoolbg

Faced this issue recently, ended up patching the package with pnpm patch.

andinus avatar Aug 26 '23 10:08 andinus