Commit ceae8c86 authored by Felipe Artur's avatar Felipe Artur Committed by Stan Hu

Fix migration to sync issuables with unknown states

Allow migration to sync state_id for issuables with unknown states.
Prevents errors when upgrading GitLab.
parent f0b38873
...@@ -62,6 +62,7 @@ class SyncIssuablesStateId < ActiveRecord::Migration[5.2] ...@@ -62,6 +62,7 @@ class SyncIssuablesStateId < ActiveRecord::Migration[5.2]
CASE state CASE state
WHEN 'opened' THEN 1 WHEN 'opened' THEN 1
WHEN 'closed' THEN 2 WHEN 'closed' THEN 2
ELSE 2
END END
SQL SQL
end end
...@@ -73,6 +74,7 @@ class SyncIssuablesStateId < ActiveRecord::Migration[5.2] ...@@ -73,6 +74,7 @@ class SyncIssuablesStateId < ActiveRecord::Migration[5.2]
WHEN 'closed' THEN 2 WHEN 'closed' THEN 2
WHEN 'merged' THEN 3 WHEN 'merged' THEN 3
WHEN 'locked' THEN 4 WHEN 'locked' THEN 4
ELSE 2
END END
SQL SQL
end end
......
...@@ -19,19 +19,23 @@ describe SyncIssuablesStateId, :migration, :sidekiq do ...@@ -19,19 +19,23 @@ describe SyncIssuablesStateId, :migration, :sidekiq do
it 'migrates state column to state_id as integer' do it 'migrates state column to state_id as integer' do
opened_issue = issues.create!(description: 'first', state: 'opened') opened_issue = issues.create!(description: 'first', state: 'opened')
closed_issue = issues.create!(description: 'second', state: 'closed') closed_issue = issues.create!(description: 'second', state: 'closed')
unknown_state_issue = issues.create!(description: 'second', state: 'unknown')
opened_merge_request = merge_requests.create!(state: 'opened', target_project_id: project.id, target_branch: 'feature1', source_branch: 'master') opened_merge_request = merge_requests.create!(state: 'opened', target_project_id: project.id, target_branch: 'feature1', source_branch: 'master')
closed_merge_request = merge_requests.create!(state: 'closed', target_project_id: project.id, target_branch: 'feature2', source_branch: 'master') closed_merge_request = merge_requests.create!(state: 'closed', target_project_id: project.id, target_branch: 'feature2', source_branch: 'master')
merged_merge_request = merge_requests.create!(state: 'merged', target_project_id: project.id, target_branch: 'feature3', source_branch: 'master') merged_merge_request = merge_requests.create!(state: 'merged', target_project_id: project.id, target_branch: 'feature3', source_branch: 'master')
locked_merge_request = merge_requests.create!(state: 'locked', target_project_id: project.id, target_branch: 'feature4', source_branch: 'master') locked_merge_request = merge_requests.create!(state: 'locked', target_project_id: project.id, target_branch: 'feature4', source_branch: 'master')
unknown_state_merge_request = merge_requests.create!(state: 'unknown', target_project_id: project.id, target_branch: 'feature4', source_branch: 'master')
migrate! migrate!
expect(opened_issue.reload.state_id).to eq(state_ids[:opened]) expect(opened_issue.reload.state_id).to eq(state_ids[:opened])
expect(closed_issue.reload.state_id).to eq(state_ids[:closed]) expect(closed_issue.reload.state_id).to eq(state_ids[:closed])
expect(unknown_state_issue.reload.state_id).to eq(state_ids[:closed])
expect(opened_merge_request.reload.state_id).to eq(state_ids[:opened]) expect(opened_merge_request.reload.state_id).to eq(state_ids[:opened])
expect(closed_merge_request.reload.state_id).to eq(state_ids[:closed]) expect(closed_merge_request.reload.state_id).to eq(state_ids[:closed])
expect(merged_merge_request.reload.state_id).to eq(state_ids[:merged]) expect(merged_merge_request.reload.state_id).to eq(state_ids[:merged])
expect(locked_merge_request.reload.state_id).to eq(state_ids[:locked]) expect(locked_merge_request.reload.state_id).to eq(state_ids[:locked])
expect(unknown_state_merge_request.reload.state_id).to eq(state_ids[:closed])
end end
end end
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