-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
I have found these related issues/pull requests
Related to #2659
Description
Without additional configuration, migrations currently can be broken by changing line endings, e.g. between a Windows dev machine and a Linux server: #2659
Prefered solution
Option 1
We could automatically create a .gitattributes
file in the migrations folder:
# Force line endings in migrations to line feeds (LF) on all platforms to avoid changing checksums
*.sql text eol=lf
Most editors, even on Windows, can now generally handle LF line endings just fine, so this seems like it should be a sane default.
This should only happen if the project root is a Git repository since it has no effect otherwise.
Option 2
Create a sqlx.toml
file that sets migrate.ignored-chars
:
[migrate]
# Ignore all whitespace, as well as Byte-Order Marks added by Windows editors
ignored-chars = [" ", "\t", "\r", "\n", "\uFEFF"]
This example includes whitespace as well as the byte-order mark which is added by some Windows editors.
However, this only works if the sqlx-toml
feature is enabled, which I explicitly chose to make non-default in #3383 because TOML parsing brings in nontrivial dependencies.
Option 3
Prompt the user to choose option 1 or option 2 and then do it.
Option 4
Just tell the user that this is a thing, what the options are, then let them decide how to handle it.
This is by far the easiest to implement, as we already print a message when the user creates their first migration:
Lines 74 to 84 in c825bd3
Congratulations on creating your first migration! | |
Did you know you can embed your migrations in your application binary? | |
On startup, after creating your database connection or pool, add: | |
sqlx::migrate!({quoted_source}).run(<&your_pool OR &mut your_connection>).await?; | |
Note that the compiler won't pick up new migrations if no Rust source files have changed. | |
You can create a Cargo build script to work around this with `sqlx migrate build-script`. | |
See: https://docs.rs/sqlx/{version}/sqlx/macro.migrate.html |
It's perhaps a lot to explain all in one message so the full explanation should be added to the docs somewhere so the message can link to it. (I have plans to write guide-level docs for migrations, just haven't gotten around to it yet.)
Is this a breaking change? Why or why not?
No.