blob: 80ea1748eeddd31f96e3230e20d238ed8a8dfe13 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
|