-
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 #2363
Conversation
See comments on previous PR. #2110 (comment) |
Edit: seems to have been due to the force-push to main. Un-drafting again to check CI. |
Co-authored-by: Jonas Platte <jonas@lumeo.com>
Co-authored-by: Austin Bonander <austin@launchbadge.com>
ce20889
to
7978915
Compare
worth mentioning that:
more context in #1163 (comment) |
Is there a way to switch back to the |
Description
Copy of #2110.
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
.Related issues
Closes #570
#1005Edit: this PR is no longer related to MSSQL.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
(indicating 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.