-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[offline] Change prepare to one-file-per-query #2110
Conversation
Edit: it was running a test with MySQL 5.7 + rustls which is not supported, pushed a commit to conditionally exclude it from the CI like before.
|
In #2039 I'm actually doing quite a number to the code for the macros right now. Are you okay waiting until I've finished that? I don't recommend basing on it right now because of how much in flux it is though. |
Sure, I can certainly try when you're finished! No guarantee though, depending on how large the differences are it might be better to start from scratch and copy pieces over, rather than continue this PR and risk overwriting changes. |
Co-authored-by: Jonas Platte <jonas@lumeo.com>
2293793
to
1855f0d
Compare
👋 Sure! I ended up rewriting several parts since the I'm unsure how popular this change will be. Displaying many Another thing to consider is printing an error/warning when the installed One (hacky) way to achieve this is to have |
Co-authored-by: Austin Bonander <austin@launchbadge.com>
1855f0d
to
2ab1582
Compare
Just one anecdotal point, but the single Another plus is that this removes the need to cache the parsed |
2ab1582
to
2930032
Compare
+1 to this or some form of version checking. Problems due to a version mismatch seem to be a constant source of issues for people |
Looks like this automatically got closed from the target branch getting deleted or something along those lines |
Oh yeah, I merged |
@cycraig looks like I can't do that, sorry. Can you rebase back against |
Perhaps when I cut a release I should immediately bump the version number on |
Probably my fault for not clicking the "Allow edits and access to secrets by maintainers" checkbox! Opened #2363 targeting |
Description
Continuation of/supersedes #1770 (comment) and #1183.
Overhauls offline query metadata from being saved in a single
sqlx-data.json
file, to every query being saved separately in a.sqlx
directory (either in the package or workspace root depending on the--workspace
flag).E.g.
Changed
Many of the changes are from #1770 and #1183. I updated the previous work on this with the latest changes from the
main
branch, implemented outstanding things likecargo sqlx prepare --check
, and fixed several bugs.sqlx prepare
to save queries individually in a.sqlx
directory.--merged
flag to--workspace
forsqlx prepare
.Add offline query support for MSSQL.The file changes look bigger than they are becauseEdit: reverted this change after rebasing onsqlx-macros/src/query/data.rs
was split into its own submodule:sqlx-macros/src/query/{mod.rs, offline.rs}
.0.7-dev
.TODO:
Related issues
Closes #570
Closes #1005
Supersedes #2322
Type of change
Breaking change. Developers will need to install the latest
sqlx-cli
and re-runcargo sqlx prepare
in their projects.How does it work?
Saving offline queries
cargo sqlx prepare
, the command will executecargo check
with theSQLX_OFFLINE_DIR
environment variable set to<package or workspace>/.sqlx
, depending on the--workspace
flag.expand_with_data
insqlx-macros
saves the query metadata to a temporary file, before moving it to theSQLX_OFFLINE_DIR
path (the move/rename operation should be atomic).SQLX_OFFLINE_DIR
is not set (either manually or bysqlx prepare
), should avoid any race conditions with IDEs building at the same time like cargo sqlx prepare picks up queries from another crate #2049.Note that
SQLX_OFFLINE_DIR
can be set manually socargo check
withoutcargo sqlx prepare
can generate query files---useful for the CI---but the environment variable doesn't override the directories used bysqlx prepare
orsqlx prepare --check
, should it?I'm concerned about data loss if it's set to another directory andEdit: changed removal behaviour so onlysqlx prepare
tries to delete it.query-*.json
files are deleted.Loading offline queries
When loading query metadata offline,
expand_input
insqlx-macros
will check if the query is saved inSQLX_OFFLINE_DIR
if set, then<package>/.sqlx
, then<workspace>/.sqlx
.Checking offline queries
Running
cargo sqlx prepare --check
will generate queries and place them intarget/sqlx-prepare-check
and compare the contents to<package or workspace>/.sqlx
, depending on the--workspace
flag.If there are queries in
target/sqlx-prepare-check
that aren't in<package or workspace>/.sqlx
(indicating new queries were probably added), the command will fail with an error:prepare check failed: .sqlx is missing one or more queries; you should re-run sqlx prepare
.If there are unused queries in
<package or workspace>/.sqlx
that aren't intarget/sqlx-prepare-check
(indicated old queries were probably removed), the command will succeed with a warning:potentially unused queries found in .sqlx; you may want to re-run sqlx prepare
.Finally, it will compare the JSON contents of files in both directories to ensure they match.