-
Notifications
You must be signed in to change notification settings - Fork 64
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
Upserting using insert on conflict #963
Comments
Related: #790 I'd definitely like to add the ON CONFLICT portion. I know we use a ton of upserts in my app, but we also rely on the after callbacks to run, so that would make things a bit tricky and become a breaking change. The other thing is we have a method available to us that tells us if the record was created or updated #904 Here's the original thread where we talked about building it as a normal upsert, but deciding to go a different direction #298 I'm not opposed to it, but I think we have to also consider any potential breaking changes, or what we lose on (e.g. do we lose any type-safety? etc...) |
I keep thinking about this and coming back to it. Maybe @grepsedawk was right about a rename... It would still be a breaking change which isn't good, but the current upsert could be renamed to Where things get fuzzy is I don't really like the idea of having a method on Maybe we can shine the @paulcsmith signal in the air and get some extra thoughts on this? 😄 |
I think this ticket should be JUST a rename ticket and we should make a new ticket for "add upsert", to reduce confusion moving forward. |
I like the idea of renaming it and adding a new upsert. It's been long enough that I don't quite remember the complexities of adding upsert, but it would be wonderful to keep it type-safe if possible. I also agree that having it working differently and not runing callbacks would be quite odd. I think if it didn't it would have to be a new operation, or would need to raise at compile time if you try to use any of those methods if you're using upsert (for example, if you add I'm not sure this is helpful at all though 😆LMK if you have other questions and I'll try to help if I can. |
Just came across this post which mentions a way to know if a record was inserted or not:
It's a little funky, and I think it would require adding some special property to models for it to work, but maybe this will spark some ideas. |
Just came across a new NEW post that suggest using This may be a way to keep the current |
I was looking into
upsert
for something I am working on and noticed that it is actually afind
followed bycreate
orupdate
rather than a "true" upsert. This means it is prone to race conditions as we may have inserted a conflicting record between thefind
and the subsequent action.For my use-case ideally I want to use
INSERT ... ON CONFLICT UPDATE SET foo=$1
to do the upsert in a single query. The downside is that we wouldn't run any of theafter
callbacks as we will no longer know whether it was anupdate
or asave
. This matches the behaviour provided by other frameworks like Rails (https://apidock.com/rails/v6.0.0/ActiveRecord/Persistence/ClassMethods/upsert).Looking for feedback whether this change would be accepted into
Avram
and along those lines should it replace the existingupsert
method (although this would be a breaking change due to callbacks) or be a new API entirely?The text was updated successfully, but these errors were encountered: