I’d like to match the result of the delete_all and, if it is not exactly 1, stop the transaction.
I think I could do it with Multi.run but I’d like to know if there is an elegant way to perform this using only “data queries”.
I think you will have to use Multi.run this in this case. In order to see the results of delete_all the query needs to actually execute, which only takes place when Repo.transaction is finally called. You will need to use run if you want to adjust an operation in your transaction based on the result of a previous operation.
I have it, but you still can delete without creating.
At the moment, I don’t have it as a primary key and i’m using unique_index with the constraint. Ecto does not allow deleting by composed key so this won’t solve my problem. Any additional reason to add it like composed primary key? I really don’t know