-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Bug Description
When a migration checksum is generated, it seems like it's putting the whole file as bytes through SHA384 generator as stated by this code:
impl Migration {
pub fn new(
version: i64,
description: Cow<'static, str>,
migration_type: MigrationType,
sql: Cow<'static, str>,
) -> Self {
let checksum = Cow::Owned(Vec::from(Sha384::digest(sql.as_bytes()).as_slice()));
Migration {
version,
description,
migration_type,
sql,
checksum,
}
}
}
What that means is when a migration is checked with version control (git in my case) it might manipulate the CRLF/LF line endings based on system. You could also run into this problem when creating/modifying the file on 2 different system even without version control I believe.
This was causing version mismatch error in my program, as I run migrate! in my main function to ensure that the db is set up correctly.
I work on 2 different systems and as of now it seems like I have to comment out my migrate! line if I'm sure it was run, don't know how to handle it in production though.
I'm not sure how to best handle this issue, but maybe conversion CRLF->LF before passing the text to sha would make sense?
Minimal Reproduction
- create a repository with a migration file on windows
- run migration
- check out with git while having core.autocrlf=true
- clone repository on mac/linux
- run migration
Info
- SQLx version: 0.7.1
- SQLx features enabled: "postgres", "runtime-tokio"
- Database server and version: Postgres
- Operating system: 2 different
rustc --version: rustc 1.70.0 (90c541806 2023-05-31)