-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Added custom array example with documentation. #4169
Conversation
Signed-off-by: Marvin Hansen <[email protected]>
Signed-off-by: Marvin Hansen <[email protected]>
Signed-off-by: Marvin Hansen <[email protected]>
Added custom array example to GH CI action. Signed-off-by: Marvin Hansen <[email protected]>
Signed-off-by: Marvin Hansen <[email protected]>
Signed-off-by: Marvin Hansen <[email protected]>
…ma usage. Signed-off-by: Marvin Hansen <[email protected]>
Quick update:
Only thing I could not figure out was how to add the tests to CI. Should be straight forward to review this PR. |
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.
Thanks for working on this. This is already a really great starting point.
I left a bunch of comments on various things. Some of them are just more information that might be helpful for you and others that read that example. Some are minor stylistic comments and a few are things that we should likely improve. If something is unclear just let me know and I will try to explain it with more details.
That written: If that example is merged I will try to convert it into a guide on the web page. It's already a really good starting point, it mostly needs styling/linking for that. This hopefully makes it much more discoverable how to perform that kind of extensions.
examples/postgres/custom_arrays/migrations/2024-08-15-070500_services/down.sql
Outdated
Show resolved
Hide resolved
examples/postgres/custom_arrays/src/model/service/service_impl.rs
Outdated
Show resolved
Hide resolved
The tests are automatically picked up: https://github.com/diesel-rs/diesel/actions/runs/10411801607/job/28836874448?pr=4169#step:27:356. I'm not sure why they fail but I can have a look at them next week if you want. |
Added embedded schema migration and updated the Readme with a section on testing. Signed-off-by: Marvin Hansen <[email protected]>
Co-authored-by: Georg Semmler <[email protected]>
@weiznich Thank you so much for the substantial commentary. The bulk of your comments are relatively easy to fix. I still trying to figure out the details about how Diesel handles custom schema, so your comments here are invaluable and I most likely will update the Readme once I updated the code so that everything resides in the custom schema. Still learning... I have fixed the failing tests. Apparently, the CI picks up the test automatically and I simply wasn't running a migration prior to test execution. Once I added an embedded migration, the test seems to pass for now. Moving the content to the Website would be great! I look into all the details over the weekend and update the PR |
…ervices/down.sql [no ci] Syle fix in down.sql Co-authored-by: Georg Semmler <[email protected]>
[skip ci] Co-authored-by: Georg Semmler <[email protected]>
[skip ci] Updated check if service exists to return false on error, as suggested Co-authored-by: Georg Semmler <[email protected]>
[no ci] Several minor updates in the Readme Co-authored-by: Georg Semmler <[email protected]>
[no ci] updated service impl Co-authored-by: Georg Semmler <[email protected]>
…ice_impl.rs Updated update service method as to remove unneeded data loading. Co-authored-by: Georg Semmler <[email protected]>
Signed-off-by: Marvin Hansen <[email protected]>
…rs#4169 (comment))) Signed-off-by: Marvin Hansen <[email protected]>
…ngle PGConnection. (See [comment](diesel-rs#4169 (comment))) Signed-off-by: Marvin Hansen <[email protected]>
diesel-rs#4169 (comment)) Added a DatabaseError to PgProtocolType in from_sql implementation to convey that the DB contains something that isn't expected. See [comment](diesel-rs#4169 (comment)). Signed-off-by: Marvin Hansen <[email protected]>
Update:
Updating the Readme next. |
Co-authored-by: Georg Semmler <[email protected]>
Co-authored-by: Georg Semmler <[email protected]>
Co-authored-by: Georg Semmler <[email protected]>
Co-authored-by: Georg Semmler <[email protected]>
Thanks a lot for the consistency checks as I didn't had the time to do it. Overall, I already committed the bulk of corrections. I want to take a closer look at your suggestion to encapsulate tests into a transaction. I get the idea of basically piggy backing on the two phase commit mechanism inherent to transactions. I just have to write and run some sample tests to see how this works out in practice. I think if that works out, it's sensible to update the test suite and the Readme. Background is, I'm building and testing my Rust mono repo with Bazel and my CI runs already hundreds of tests in parallel. However, for DB integration tests at scale, the aborted transaction trick may work out and speeds things up further. |
1 similar comment
Thanks a lot for the consistency checks as I didn't had the time to do it. Overall, I already committed the bulk of corrections. I want to take a closer look at your suggestion to encapsulate tests into a transaction. I get the idea of basically piggy backing on the two phase commit mechanism inherent to transactions. I just have to write and run some sample tests to see how this works out in practice. I think if that works out, it's sensible to update the test suite and the Readme. Background is, I'm building and testing my Rust mono repo with Bazel and my CI runs already hundreds of tests in parallel. However, for DB integration tests at scale, the aborted transaction trick may work out and speeds things up further. |
# Conflicts: # .github/workflows/ci.yml # diesel/src/pg/query_builder/copy/copy_to.rs # examples/postgres/custom_arrays/README.md # examples/postgres/custom_arrays/tests/service_tests.rs
Updated run_db_migration Added revert_db_migration Signed-off-by: Marvin Hansen <[email protected]>
Updated check_if_service_id_exists at line 790 with actual implementation, Updated check_all_services_online at line 860 with actual implementation. Signed-off-by: Marvin Hansen <[email protected]>
Added parallel executable integration tests. Signed-off-by: Marvin Hansen <[email protected]>
Updated README.md Signed-off-by: Marvin Hansen <[email protected]>
Signed-off-by: Marvin Hansen <[email protected]>
Update summary:
Just one question: Does the test transaction aborts automatically when it goes out of scope? Either way, please review these changes and if there |
Updated README.md to ensure run_db_migration is the same as in the code. Added revert_db_migration to the Readme as well. Signed-off-by: Marvin Hansen <[email protected]>
Thanks for the update. I will try to do a final review (and likely some additional minor adjustments based on that) this week. Otherwise I think this is fine now.
It relays on the fact that you drop the connection itself at the end of the test. This will also drop any uncommited changes for that connection. |
Thank you for the detailed corrections and the links to the docs in the Readme. Also, thank you for getting the parallel tests in shape. While things worked locally on my box, apparently on CI each test really needs an unique connection. It was my first try with the dangling transaction test style so there is stil a bit of learning ahead. Anyways, just want to thank you for your time and effort to get this PR done. |
The problem there was that you likely had already applied the migrations manually. The tests run against an empty database and postgres do not allow to modify the schema from more than one connection at once. That's worked around by having the schema modification itself in the test transaction as well. So it doesn't get commited and there are no problem with concurrent access. Thanks again for writing this up. I think that's now a good starting point for at least two guides: One for custom types and one for testing. Now I only need to find the capacity to do the last bit of polishing to put it on the web page. |
Now this makes sense as I've just seen the same issue on my CI (BuildBuddy). As for the guide, I don't have the capacity to do that as my project progresses, but it might be an option to open an issue with a call for contribution with some guidance and some links to an example. This would be a great first PR for new contributors. |
I'm already really grateful that you wrote this PR. I will find the time at some point for the necessary work to turn this into a full guide, I just wanted to manage expectations that this likely won't be the case tomorrow. |
Added example code with a comprehensive Readme that covers the bulk of the custom array concepts and how they relate to each other.
In response to discussion: #4157
However, the Readme needs review and the tests need a fix for a serialization error.