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

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

Open
xeoneux opened this issue May 25, 2021 · 7 comments · May be fixed by #65
Open

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

xeoneux opened this issue May 25, 2021 · 7 comments · May be fixed by #65

Comments

@xeoneux
Copy link

xeoneux commented May 25, 2021

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 xeoneux linked a pull request May 26, 2021 that will close this issue
@ThomWright
Copy link
Owner

ThomWright commented May 26, 2021

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?

@xeoneux
Copy link
Author

xeoneux commented May 26, 2021

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.

@ThomWright
Copy link
Owner

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.

@Suvitruf
Copy link

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

@xeoneux
Copy link
Author

xeoneux commented Nov 27, 2021

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.

@oldschoolbg
Copy link

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.

@andinus
Copy link

andinus commented Aug 26, 2023

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

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

Successfully merging a pull request may close this issue.

5 participants