-
Notifications
You must be signed in to change notification settings - Fork 389
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
chore: update seaorm to latest #4925
base: main
Are you sure you want to change the base?
Conversation
|
let mut buf = [0u8; 32]; | ||
v.to_little_endian(&mut buf); | ||
BigDecimal::from(BigInt::from_bytes_le(Sign::Plus, &buf as &[u8])) | ||
let big_dec = &BigDecimal::from(BigInt::from_bytes_le(Sign::Plus, &buf as &[u8])).to_string(); | ||
Decimal::from_str(big_dec).unwrap() |
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.
I wonder if we can fit U256 into Decimal?
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.
Decimal and BigDecimal are both mapped to the same type on PostgreSQL, I was wondering why the change in that too but if you look at the definition of Wei
(which uses BigDecimal) that has not changed from the old version.
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.
Another note on this, the BigDecimal -> Decimal was a change which was made by the entity generation of the updated sea-orm
package, and has nothing do with any specific changes made to the schema.
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.
I suppose that the definition of column type Wei
did not change since it is specified in the native Postgres type: decimal
, which is equivalent of numeric
("The types decimal and numeric are equivalent"). So, Wei
defines the column type, not the type which is going to be used in Rust struct which is mapped to the record in the table.
I don't believe that Rust Decimal
can contain all values possible in U256
. Type Decimal
supports only 96-bit integers. In contrast, BigDecimal
internally contains a vector of digits (see BigUint
type).
I wonder if it is possible to enable feature with-bigdecimal
on Postgres driver?
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.
Not from what I found though going through code and docs.
Their discord is pretty dead, but it's better than nothing so I've tried to ask there.
In general, I doubt you would be storing gas values that overflow the decimal type in rust, perhaps one thing we could do is swap it to bigint 🤔
pub use super::{ | ||
block::Entity as Block, cursor::Entity as Cursor, |
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.
I suppose we can commit prelude which was generated by generate_entities
.
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.
I am not sure what you mean by commit
could you please specify?
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.
If you run generate_entities
, it will generate entities files. They will be the same as currently committed in this PR with the exception of prelude.rs
file. I think that prelude.rs
can be also added to this PR. Current one and the generate one are equivalent.
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.
Ahhh, I get it now, the new prelude is added in this PR. It is just that the generated one has a line by line format, not a block format, I changed it back to the block format so we can use the allow_unused_imports
on the whole block as before. You can see the update I did here ed6d556
But you are right, the generated one is the same as the old one so everything is fine in that regard. The edit is just so we avoid having the warnings from the generated prelude.rs
Hope that makes sense
#[tokio::main(flavor = "current_thread")] | ||
async fn main() -> Result<(), DbErr> { |
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.
I wonder if it produces the same database schema as before (i.e. old version vs new version)?
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.
It appears so, I did the test which you mentioned in the issue of the description, which is to generate a schema on the old version, scrape a bit, then switch to the new version and continue scraping, everything worked fine
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.
It is good that it works. It is not the test for this comment though (but a good test for that comment)
The test is mostly manual for this:
- Start Postgres on one port.
- Init schema there (
init_db.rs
) frommain
. - Start Postgres on a different port.
- Init schema from this branch.
- Compare the tables and field types.
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.
And it will be great to check if newly generated entities can work with old schema without issue. I can see that we have replaced |
I checked it during the manual tests, scraping with the old/new versions, it was working fine ✅ |
Implementation details of Decimal vs BigDecimal |
Description
Updated
sea-orm
andsea-orm-migration
to1.1.1
(latest as of opening this PR) and resolved any issues that occurred due to the version bump.Drive-by changes
sea-orm
fromrust/sealevel
sea-orm-migration
data typesrust-toolchain
to1.81.0
due tosea-orm-cli
issue: Compilation error with url 2.5.3 / idna 1.0.3 with Rust < 1.81 and edition 2021 (resolver 2) when sqlx-core is in the dependency graph servo/rust-url#992Related issues
Backward compatibility
Yes
Testing
Manual, as described in #4793