diff options
author | Luke Duncalfe <lduncalfe@gitlab.com> | 2019-07-29 18:55:19 +0000 |
---|---|---|
committer | Mayra Cabrera <mcabrera@gitlab.com> | 2019-07-29 18:55:19 +0000 |
commit | 177463007b1b97d29c7f4f8e279365c1ca6bfc9e (patch) | |
tree | c2aee6237ef1603e39ffc5c020bd28159b8672dd /spec/migrations | |
parent | fe22704a203111ab2146143a4ff9d2e1256aecc7 (diff) | |
download | gitlab-ce-177463007b1b97d29c7f4f8e279365c1ca6bfc9e.tar.gz |
Migrations for adding issue_id to versions table
These migrations do the following:
- Adds a new `issue_id` column to `versions`. This fixes an n+1 problem
when loading versions for an issue in GraphQL as AR can now load from
cache
- Change the unique restraint on versions.sha to be scoped to `issue_id`
as in order to import version data, we need to allow duplicate `sha`
values for versions
- Update all versions with an `issue_id`
https://gitlab.com/gitlab-org/gitlab-ee/issues/11090
Diffstat (limited to 'spec/migrations')
-rw-r--r-- | spec/migrations/set_issue_id_for_all_versions_spec.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/spec/migrations/set_issue_id_for_all_versions_spec.rb b/spec/migrations/set_issue_id_for_all_versions_spec.rb new file mode 100644 index 00000000000..bfc2731181b --- /dev/null +++ b/spec/migrations/set_issue_id_for_all_versions_spec.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'migrate', '20190715043954_set_issue_id_for_all_versions.rb') + +describe SetIssueIdForAllVersions, :migration do + let(:projects) { table(:projects) } + let(:issues) { table(:issues) } + let(:designs) { table(:design_management_designs) } + let(:designs_versions) { table(:design_management_designs_versions) } + let(:versions) { table(:design_management_versions) } + + before do + @project = projects.create!(name: 'gitlab', path: 'gitlab-org/gitlab-ce', namespace_id: 1) + + @issue_1 = issues.create!(description: 'first', project_id: @project.id) + @issue_2 = issues.create!(description: 'second', project_id: @project.id) + + @design_1 = designs.create!(issue_id: @issue_1.id, filename: 'homepage-1.jpg', project_id: @project.id) + @design_2 = designs.create!(issue_id: @issue_2.id, filename: 'homepage-2.jpg', project_id: @project.id) + + @version_1 = versions.create!(sha: 'foo') + @version_2 = versions.create!(sha: 'bar') + + designs_versions.create!(version_id: @version_1.id, design_id: @design_1.id) + designs_versions.create!(version_id: @version_2.id, design_id: @design_2.id) + end + + it 'correctly sets issue_id' do + expect(versions.where(issue_id: nil).count).to eq(2) + + migrate! + + expect(versions.where(issue_id: nil).count).to eq(0) + expect(versions.find(@version_1.id).issue_id).to eq(@issue_1.id) + expect(versions.find(@version_2.id).issue_id).to eq(@issue_2.id) + end +end |