Commit e56279d0 authored by Andreas Brandl's avatar Andreas Brandl

Merge branch 'update-internal-ids-last-value-for-epics' into 'master'

Fix last_value record in internal_ids for epics

See merge request gitlab-org/gitlab!48988
parents fceec480 5f9aa33d
---
title: Fix last_value record in internal_ids for epics
merge_request: 48988
author:
type: fixed
# frozen_string_literal: true
class UpdateInternalIdsLastValueForEpics < ActiveRecord::Migration[6.0]
DOWNTIME = false
def up
ApplicationRecord.connection.execute(<<-SQL.squish)
UPDATE internal_ids
SET last_value = epics_max_iids.maximum_iid
FROM
(
SELECT
MAX(epics.iid) AS maximum_iid,
epics.group_id AS epics_group_id
FROM epics
GROUP BY epics.group_id
) epics_max_iids
WHERE internal_ids.last_value < epics_max_iids.maximum_iid
AND namespace_id = epics_max_iids.epics_group_id
AND internal_ids.usage = 4
SQL
end
def down
# no-op
end
end
cbc6bfa122167e9a46edaa14351a73eeb10586fa0eb82f231c792384c9d7986c
\ No newline at end of file
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('db', 'migrate', '20201202081429_update_internal_ids_last_value_for_epics.rb')
RSpec.describe UpdateInternalIdsLastValueForEpics, :migration, schema: 20201124185639 do
let(:namespaces) { table(:namespaces) }
let(:users) { table(:users) }
let(:epics) { table(:epics) }
let(:internal_ids) { table(:internal_ids) }
let!(:author) { users.create!(name: 'test', email: 'test@example.com', projects_limit: 0) }
let!(:group1) { namespaces.create!(type: 'Group', name: 'group1', path: 'group1') }
let!(:group2) { namespaces.create!(type: 'Group', name: 'group2', path: 'group2') }
let!(:group3) { namespaces.create!(type: 'Group', name: 'group3', path: 'group3') }
let!(:epic_last_value1) { internal_ids.create!(usage: 4, last_value: 5, namespace_id: group1.id) }
let!(:epic_last_value2) { internal_ids.create!(usage: 4, last_value: 5, namespace_id: group2.id) }
let!(:epic_last_value3) { internal_ids.create!(usage: 4, last_value: 5, namespace_id: group3.id) }
let!(:epic_1) { epics.create!(iid: 110, title: 'from epic 1', group_id: group1.id, author_id: author.id, title_html: 'any') }
let!(:epic_2) { epics.create!(iid: 5, title: 'from epic 1', group_id: group2.id, author_id: author.id, title_html: 'any') }
let!(:epic_3) { epics.create!(iid: 3, title: 'from epic 1', group_id: group3.id, author_id: author.id, title_html: 'any') }
it 'updates out of sync internal_ids last_value' do
migrate!
expect(internal_ids.find_by(usage: 4, namespace_id: group1.id).last_value).to eq(110)
expect(internal_ids.find_by(usage: 4, namespace_id: group2.id).last_value).to eq(5)
expect(internal_ids.find_by(usage: 4, namespace_id: group3.id).last_value).to eq(5)
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