Repository navigation
[offline] Change prepare to one-file-per-query - #2363
Merged
Merged
Conversation
2 tasks done
Contributor
Author
|
See comments on previous PR. #2110 (comment) |
cycraig
marked this pull request as draft
February 22, 2023 07:03
Contributor
Author
|
Edit: seems to have been due to the force-push to main. Un-drafting again to check CI. |
Co-authored-by: Jonas Platte <[email protected]>
Co-authored-by: Austin Bonander <[email protected]>
cycraig
force-pushed
the
feat/one-file-per-query
branch
from
February 22, 2023 07:43
ce20889 to
7978915
Compare
cycraig
marked this pull request as ready for review
February 22, 2023 07:44
This was referenced Mar 3, 2023
This was referenced Mar 11, 2023
Merged
4 of 30 tasks
Contributor
|
worth mentioning that:
more context in #1163 (comment) |
|
Is there a way to switch back to the |
4 of 6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Copy of #2110.
Continuation of/supersedes #1770 (comment) and #1183.
Overhauls offline query metadata from being saved in a single
sqlx-data.jsonfile, to every query being saved separately in a.sqlxdirectory (either in the package or workspace root depending on the--workspaceflag).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
mainbranch, implemented outstanding things likecargo sqlx prepare --check, and fixed several bugs.sqlx prepareto save queries individually in a.sqlxdirectory.--mergedflag to--workspaceforsqlx 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-cliand re-runcargo sqlx preparein their projects.How does it work?
Saving offline queries
cargo sqlx prepare, the command will executecargo checkwith theSQLX_OFFLINE_DIRenvironment variable set to<package or workspace>/.sqlx, depending on the--workspaceflag.expand_with_datainsqlx-macrossaves the query metadata to a temporary file, before moving it to theSQLX_OFFLINE_DIRpath (the move/rename operation should be atomic).SQLX_OFFLINE_DIRis 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_DIRcan be set manually socargo checkwithoutcargo sqlx preparecan generate query files---useful for the CI---but the environment variable doesn't override the directories used bysqlx prepareorsqlx prepare --check, should it?I'm concerned about data loss if it's set to another directory andEdit: changed removal behaviour so onlysqlx preparetries to delete it.query-*.jsonfiles are deleted.Loading offline queries
When loading query metadata offline,
expand_inputinsqlx-macroswill check if the query is saved inSQLX_OFFLINE_DIRif set, then<package>/.sqlx, then<workspace>/.sqlx.Checking offline queries
Running
cargo sqlx prepare --checkwill generate queries and place them intarget/sqlx-prepare-checkand compare the contents to<package or workspace>/.sqlx, depending on the--workspaceflag.If there are queries in
target/sqlx-prepare-checkthat 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>/.sqlxthat 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.