Commit df2c5bb9 authored by Adam Hegyi's avatar Adam Hegyi

Fix non-custom Total stage in VSA

This change fixes the uneditable non-custom Total stage in value stream
analytics. The Total stage was removed from VSA a few releases ago thus
we need to make sure that the persisted Total stages have the custom
flag set to true.

Changelog: fixed
EE: true
parent bf020294
# frozen_string_literal: true
class FixTotalStageInVsa < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
TOTAL_STAGE = 'Total'
class GroupStage < ActiveRecord::Base
include EachBatch
self.table_name = 'analytics_cycle_analytics_group_stages'
end
def up
GroupStage.reset_column_information
GroupStage.each_batch(of: 100) do |relation|
relation.where(name: TOTAL_STAGE, custom: false).update_all(custom: true)
end
end
def down
# no-op
end
end
668f65ea77042e5b8054681e76f583a6061aca921b685f90d155fc4121e7ff78
\ No newline at end of file
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20210601073400_fix_total_stage_in_vsa.rb')
RSpec.describe FixTotalStageInVsa, :migration, schema: 20210518001450 do
let(:namespaces) { table(:namespaces) }
let(:group_value_streams) { table(:analytics_cycle_analytics_group_value_streams) }
let(:group_stages) { table(:analytics_cycle_analytics_group_stages) }
let!(:group) { namespaces.create!(name: 'ns1', path: 'ns1', type: 'Group') }
let!(:group_vs_1) { group_value_streams.create!(name: 'default', group_id: group.id) }
let!(:group_vs_2) { group_value_streams.create!(name: 'other', group_id: group.id) }
let!(:group_vs_3) { group_value_streams.create!(name: 'another', group_id: group.id) }
let!(:group_stage_total) { group_stages.create!(name: 'Total', custom: false, group_id: group.id, group_value_stream_id: group_vs_1.id, start_event_identifier: 1, end_event_identifier: 2) }
let!(:group_stage_different_name) { group_stages.create!(name: 'Issue', custom: false, group_id: group.id, group_value_stream_id: group_vs_2.id, start_event_identifier: 1, end_event_identifier: 2) }
let!(:group_stage_total_custom) { group_stages.create!(name: 'Total', custom: true, group_id: group.id, group_value_stream_id: group_vs_3.id, start_event_identifier: 1, end_event_identifier: 2) }
it 'deduplicates issue_metrics table' do
migrate!
group_stage_total.reload
group_stage_different_name.reload
group_stage_total_custom.reload
expect(group_stage_total.custom).to eq(true)
expect(group_stage_different_name.custom).to eq(false)
expect(group_stage_total_custom.custom).to eq(true)
end
end
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