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:
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