Use RESTRICT instead of CASCADE when truncating with postgres#58
Conversation
Codecov Report
@@ Coverage Diff @@
## main #58 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 12 12
Lines 535 549 +14
=========================================
+ Hits 535 549 +14
Continue to review full report at Codecov.
|
|
Hey @botandrose the only thing I cannot figure out is how and to what number bump the version of the gem? |
|
@bsuchodolski Thanks for putting this together! Don't worry about bumping the version, I'll do that when I release v2.0.1 |
|
You should use RESTRICT if table names are defined. Otherwise, CASCADE is the only option to truncate multiple tables with default behavior. Our tests broke because of this change. |
So the problem was described in this issue #57
In case of two tables, from which one was referencing another, when only referenced table was set to be truncated (e.g. with
onlyoption) then referencing table was silently truncated as well because of how postgres'sTRUNCATEworks withCASCADEoption:In case of applications with complex database schema it was easy to stumble upon a problem when such referencing table was truncated despite it was not named to truncate and it was really hard to tell why at the first glance.
With RESTRICT option truncation fails with an exception with clear message about what is the problem and which tables are referencing each another.