-
Notifications
You must be signed in to change notification settings - Fork 0
refactor!: collapse postgres/sqlite repositories into a shared generic layer #111
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🌐 Web query:
sqlx postgres try_get i64 on INT4 column type mismatch error💡 Result:
The error occurs because sqlx strictly maps the PostgreSQL INT4 (INTEGER) type to the Rust i32 type, while i64 is exclusively reserved for the BIGINT (INT8) type [1][2][3]. When you attempt to decode an INT4 column into an i64 using try_get, sqlx detects a type mismatch between the database's reported type and the requested Rust type, resulting in a decoding error [4][5]. To resolve this issue, use one of the following approaches: 1. Use i32 in Rust: If the data in your database column is guaranteed to fit within a 32-bit integer, change your Rust code to use i32 instead of i64 [2][3]. 2. Explicitly cast in SQL: If you must use i64 in Rust, you can cast the column value in your SQL query to bigint. This promotes the type at the database level before it reaches sqlx [5]. For example: SELECT your_column::bigint FROM your_table; 3. Change the database schema: If the values in the column may exceed the range of an i32, consider altering your PostgreSQL table schema to use BIGINT instead of INT4/INTEGER [2][3].
Citations:
Row.try_get()should check the decoding type against the type reported by the server transact-rs/sqlx#8🏁 Script executed:
Repository: hops-ops/distributed
Length of output: 22782
🏁 Script executed:
Repository: hops-ops/distributed
Length of output: 895
🏁 Script executed:
Repository: hops-ops/distributed
Length of output: 198
🏁 Script executed:
Repository: hops-ops/distributed
Length of output: 4525
🏁 Script executed:
Repository: hops-ops/distributed
Length of output: 217
🏁 Script executed:
Repository: hops-ops/distributed
Length of output: 15165
🏁 Script executed:
Repository: hops-ops/distributed
Length of output: 16403
Add a follow-up migration for the widened columns
Changing
0001_initial.sqlonly affects fresh installs. SQLx records applied migrations in_sqlx_migrations, so already-deployed Postgres databases will keep the oldintegercolumns and fail to decode these fields asi64. Add a newALTER TABLE ... ALTER COLUMN ... TYPE bigintmigration forevent_version,payload_codec_version,snapshot_version, andattemptsinstead of editing0001.🤖 Prompt for AI Agents