Issue with truncate cascade in Postgres
Opened this issue · 1 comments
Hello,
first of all, thank you very much for creating Respawn. I have enjoyed using the library so far.
We are running into problems because we have a table with a single row that should not be deleted. It is protected with a trigger that makes sure of that. I excluded the table from Respawn's processing, but it still triggers the exception that it's being deleted.
I saw that the generated SQL creates a 'truncate ... cascade' statement.
The way this apparently works is that Postgres just truncates any table that has a relationship with the truncated ones. This unfortunately means that the excluded table, still gets truncated (it has foreign keys with 'on cascade delete set null' set), which raises an error.
What would be the best way to deal with this issue? I would offer you a pull-request with the truncate
removed, but I'm worried that there might be a good reason for it being there?
Thanks & best
Alon
Truncate is there because we had reports that it's faster. You can look at the history to see the original PR that added it.
I'm not a PG developer so I dunno the nuances here.