Upserts support
aerosol opened this issue · 7 comments
Options such as on_conflict
, conflict_target
and returning
for upserts are passed down to insert_versions
and cause a crash since the target is non existent for the Version
schema.
defmodule ExAudit.Test.Repo.Migrations.UniqueConstraint do
use Ecto.Migration
def change do
alter table(:users) do
add(:unique_field, :string)
end
create(unique_index(:users, [:unique_field]))
end
end
test "on conflict" do
user = Repo.insert!(%User{name: "Admin", email: "admin@example.com", unique_field: "foo"})
user2 = %User{name: "Should not change", email: "shouldchange@example.com", unique_field: "foo"}
# this will crash
Repo.insert!(user2, on_conflict: {:replace, [:email]}, conflict_target: :unique_field, returning: true)
end
I think it'd require dropping specific opts in insert_versions
and introducing a new action type. I haven't figured out yet how to qualify upsert as either update
or insert
-- the most tricky bit is calculating diffs to support the rollback feature.
I think the opts sent to Query should be separated from the new opts being added
All requests with on_conflict fails
Oh yeah that's not right, I should implement a whitelist for the options passed to the version recording
let me know when done, thank you!!
@narrowtux is there any update?
Sorry, I'm very swamped at work
@bruteforcecat fixed this.
Update to 0.7