summaryrefslogtreecommitdiff
path: root/db/migrate/20220824175648_limit_namespaces_sync_triggers_to_traversal_ids_update.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-09-19 23:18:09 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-09-19 23:18:09 +0000
commit6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch)
treedc4d20fe6064752c0bd323187252c77e0a89144b /db/migrate/20220824175648_limit_namespaces_sync_triggers_to_traversal_ids_update.rb
parent9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff)
downloadgitlab-ce-6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde.tar.gz
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'db/migrate/20220824175648_limit_namespaces_sync_triggers_to_traversal_ids_update.rb')
-rw-r--r--db/migrate/20220824175648_limit_namespaces_sync_triggers_to_traversal_ids_update.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/db/migrate/20220824175648_limit_namespaces_sync_triggers_to_traversal_ids_update.rb b/db/migrate/20220824175648_limit_namespaces_sync_triggers_to_traversal_ids_update.rb
new file mode 100644
index 00000000000..142744b5493
--- /dev/null
+++ b/db/migrate/20220824175648_limit_namespaces_sync_triggers_to_traversal_ids_update.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+class LimitNamespacesSyncTriggersToTraversalIdsUpdate < Gitlab::Database::Migration[2.0]
+ include Gitlab::Database::SchemaHelpers
+
+ enable_lock_retries!
+
+ TABLE_NAME = 'namespaces'
+ EVENT_TABLE_NAME = 'namespaces_sync_events'
+ FUNCTION_NAME = 'insert_namespaces_sync_event'
+ OLD_TRIGGER_ON_INSERT = 'trigger_namespaces_parent_id_on_insert'
+ OLD_TRIGGER_ON_UPDATE = 'trigger_namespaces_parent_id_on_update'
+ NEW_TRIGGER_ON_UPDATE = 'trigger_namespaces_traversal_ids_on_update'
+
+ def up
+ create_trigger(TABLE_NAME, NEW_TRIGGER_ON_UPDATE, FUNCTION_NAME, fires: 'AFTER UPDATE') do
+ <<~SQL
+ WHEN (OLD.traversal_ids IS DISTINCT FROM NEW.traversal_ids)
+ SQL
+ end
+ drop_trigger(TABLE_NAME, OLD_TRIGGER_ON_UPDATE)
+ drop_trigger(TABLE_NAME, OLD_TRIGGER_ON_INSERT)
+ end
+
+ # Revert both triggers to the version defined in db/migrate/20211011141242_create_namespaces_sync_trigger.rb
+ def down
+ create_trigger(TABLE_NAME, OLD_TRIGGER_ON_INSERT, FUNCTION_NAME, fires: 'AFTER INSERT')
+ create_trigger(TABLE_NAME, OLD_TRIGGER_ON_UPDATE, FUNCTION_NAME, fires: 'AFTER UPDATE') do
+ <<~SQL
+ WHEN (OLD.parent_id IS DISTINCT FROM NEW.parent_id)
+ SQL
+ end
+ drop_trigger(TABLE_NAME, NEW_TRIGGER_ON_UPDATE)
+ end
+end