summaryrefslogtreecommitdiff
path: root/db/post_migrate/20210303165302_cleanup_cluster_tokens_with_null_name.rb
diff options
context:
space:
mode:
Diffstat (limited to 'db/post_migrate/20210303165302_cleanup_cluster_tokens_with_null_name.rb')
-rw-r--r--db/post_migrate/20210303165302_cleanup_cluster_tokens_with_null_name.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/db/post_migrate/20210303165302_cleanup_cluster_tokens_with_null_name.rb b/db/post_migrate/20210303165302_cleanup_cluster_tokens_with_null_name.rb
new file mode 100644
index 00000000000..80ea1748eed
--- /dev/null
+++ b/db/post_migrate/20210303165302_cleanup_cluster_tokens_with_null_name.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+class CleanupClusterTokensWithNullName < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ BATCH_SIZE = 1000
+
+ disable_ddl_transaction!
+
+ class AgentToken < ActiveRecord::Base
+ include EachBatch
+
+ self.table_name = 'cluster_agent_tokens'
+ end
+
+ def up
+ AgentToken.each_batch(of: BATCH_SIZE) do |relation|
+ relation.where('name IS NULL').update_all("name = 'agent-token-' || id")
+ end
+ end
+
+ def down
+ # no-op : can't go back to `NULL` without first dropping the `NOT NULL` constraint
+ end
+end