Deprecate `on_conflict: replace_all`

69 views
Skip to first unread message

Alexey Nikitin

unread,
Aug 24, 2020, 2:32:01 PM8/24/20
to elixir-ecto

`on_conflict: :replace_all` creates new DB records due to it also updates the primary key. Thus it breaks upsert semantics, it always inserts.
`EXPECTED.id` is most likely unintended in the vast majority of use-cases.
We should at least add a huge warning "Don't use replace_all unless you 100% sure. It could cause data duplication" or smth like that

José Valim

unread,
Aug 24, 2020, 3:26:20 PM8/24/20
to elixi...@googlegroups.com
It still has legit use cases for when the primary key has semantic meaning (i.e. the PK is not an auto-incrementing key). I will update the docs!

--
You received this message because you are subscribed to the Google Groups "elixir-ecto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-ecto...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-ecto/87b3c0fa-72c0-4c7e-a3b3-74d20d39370fn%40googlegroups.com.

Alexey Nikitin

unread,
Aug 24, 2020, 8:34:29 PM8/24/20
to elixir-ecto
You've decided to deprecate replace_all_except_primary_keys due to it can be achieved with another option. It is also true for the use case with non-autoincrementing PK. It can be perfectly handled with existing options. But replace_all can be very harmful. I'm pretty sure if we deprecate it a lot of applications will be fixed! I believe ecto should be safe by default and try as hard as possible not to allow developers to corrupt their data

понедельник, 24 августа 2020 г. в 22:26:20 UTC+3, José Valim:
Reply all
Reply to author
Forward
0 new messages