Conversation
mooster531
requested changes
Nov 26, 2024
Collaborator
mooster531
left a comment
There was a problem hiding this comment.
I think that if we're using an ORM, we should use the ORM as much as we can :) I simplified the upsert function using sqlalchemy's built-in "on conflict update" utility.
Owner
Author
|
I think your comments have all been addressed. |
mooster531
approved these changes
Nov 26, 2024
Collaborator
|
🚀🚀🚀 |
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.
Introducing
INSERT ... ON CONFLICT ... DO UPDATE!This works well but also requires primary key or, more loosely, a uniqueness constraint on the table in question.
We have insightful error messaging that will literally print out the table alterations require for the provided
conflict_columns:So, when table exists without index we will see this error log suggesting how to fix the issue.
Note that, additionally, the table does not need to exist first. It will be created without any validation on the uniqueness constraints at first run. We only validate the uniqueness at the first time of actual upsert.
Test Plan
For now this is
If you already have the table (from previous runs) you will hit the error above.
Execute the suggested ALTER TABLE command and try again!
UPDATE:
There are now "unit" tests of all conflict column validation and upsert method works as expected.
Closes #56.