debian-mirror-gitlab/db/migrate/20210722150102_operations_feature_flags_correct_flexible_rollout_values.rb
2021-10-27 15:23:28 +05:30

30 lines
986 B
Ruby

# frozen_string_literal: true
class OperationsFeatureFlagsCorrectFlexibleRolloutValues < ActiveRecord::Migration[6.1]
STICKINESS = { "USERID" => "userId", "RANDOM" => "random", "SESSIONID" => "sessionId", "DEFAULT" => "default" }.freeze
def up
STICKINESS.each do |before, after|
update_statement = <<-SQL
UPDATE operations_strategies
SET parameters = parameters || jsonb_build_object('stickiness', '#{quote_string(after)}')
WHERE name = 'flexibleRollout' AND parameters->>'stickiness' = '#{quote_string(before)}'
SQL
execute(update_statement)
end
end
def down
STICKINESS.each do |before, after|
update_statement = <<-SQL
UPDATE operations_strategies
SET parameters = parameters || jsonb_build_object('stickiness', '#{quote_string(before)}')
WHERE name = 'flexibleRollout' AND parameters->>'stickiness' = '#{quote_string(after)}'
SQL
execute(update_statement)
end
end
end