Commit 442a5199 authored by Steve Abrams's avatar Steve Abrams

Merge branch '322745-add-missing-token-names' into 'master'

Update cluster agent tokens with null names

See merge request gitlab-org/gitlab!55673
parents 7029c480 443974be
---
title: Update cluster agent tokens with null names
merge_request: 55673
author:
type: changed
# frozen_string_literal: true
class AddNotNullConstraintToClusterTokenName < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
# This will add the `NOT NULL` constraint WITHOUT validating it
add_not_null_constraint :cluster_agent_tokens, :name, validate: false
end
def down
remove_not_null_constraint :cluster_agent_tokens, :name
end
end
# 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
fa82a0f6c57a527a143da56ae0d70245a7d711b5e5ff3eb959fd6b2cf5872dac
\ No newline at end of file
1cb74abdc7134c3252425c3ceb8cd9dc4b157d64b1a2ff7928153e78b05d9121
\ No newline at end of file
......@@ -19953,6 +19953,9 @@ ALTER TABLE ONLY chat_names
ALTER TABLE ONLY chat_teams
ADD CONSTRAINT chat_teams_pkey PRIMARY KEY (id);
ALTER TABLE cluster_agent_tokens
ADD CONSTRAINT check_0fb634d04d CHECK ((name IS NOT NULL)) NOT VALID;
ALTER TABLE vulnerability_scanners
ADD CONSTRAINT check_37608c9db5 CHECK ((char_length(vendor) <= 255)) NOT VALID;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment