Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-04-20 13:00:54 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-04-20 13:00:54 +0300
commit3cccd102ba543e02725d247893729e5c73b38295 (patch)
treef36a04ec38517f5deaaacb5acc7d949688d1e187 /rubocop/cop/database/disable_referential_integrity.rb
parent205943281328046ef7b4528031b90fbda70c75ac (diff)
Add latest changes from gitlab-org/gitlab@14-10-stable-eev14.10.0-rc42
Diffstat (limited to 'rubocop/cop/database/disable_referential_integrity.rb')
-rw-r--r--rubocop/cop/database/disable_referential_integrity.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/rubocop/cop/database/disable_referential_integrity.rb b/rubocop/cop/database/disable_referential_integrity.rb
new file mode 100644
index 00000000000..80d52678011
--- /dev/null
+++ b/rubocop/cop/database/disable_referential_integrity.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+module RuboCop
+ module Cop
+ module Database
+ # Cop that checks if 'disable_referential_integrity' method is called.
+ class DisableReferentialIntegrity < RuboCop::Cop::Cop
+ MSG = <<~TEXT
+ Do not use `disable_referential_integrity`, disable triggers in a safe
+ transaction instead. Follow the format:
+ BEGIN;
+ ALTER TABLE my_table DISABLE TRIGGER ALL;
+ -- execute query that requires disabled triggers
+ ALTER TABLE my_table ENABLE TRIGGER ALL;
+ COMMIT;
+ TEXT
+
+ def_node_matcher :disable_referential_integrity?, <<~PATTERN
+ (send _ :disable_referential_integrity)
+ PATTERN
+
+ RESTRICT_ON_SEND = %i[disable_referential_integrity].freeze
+
+ def on_send(node)
+ return unless disable_referential_integrity?(node)
+
+ add_offense(node)
+ end
+ end
+ end
+ end
+end