I am trying to avoid deadlock between my Ecto Transaction operating on the same Table. To do that I am trying to replicate Postgres “Select … for Update” in Ecto Multi.
Question is: Can I avoid lock here?
Query:
query =
from(s in Split,
where: <condition>
lock: fragment("FOR UPDATE OF ?", s),
order_by: [asc: :id],
select: %{
id: s.id
}
)
Repo.multi_update_all(
multi,
:updated_splits,
from(s in Split,
join: t in subquery(query),
on: s.id == t.id,
update: [
set: [
....
]
]
),
[]
)