From 998258467247adf04be4f22b831fcb86244c5e58 Mon Sep 17 00:00:00 2001 From: charlieablett Date: Thu, 11 Jul 2019 22:04:52 +1200 Subject: Port CE changes from EE - DB migration of board milestone values - issue finder & spec updates --- app/finders/issuable_finder.rb | 4 +- app/models/milestone.rb | 4 +- .../20190703001116_default_milestone_to_nil.rb | 49 ++++++++++++++++++++++ spec/finders/issues_finder_spec.rb | 4 +- .../requests/api/issues/get_project_issues_spec.rb | 2 +- 5 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 db/migrate/20190703001116_default_milestone_to_nil.rb diff --git a/app/finders/issuable_finder.rb b/app/finders/issuable_finder.rb index f4fbeacfaba..6c8db32e7c3 100644 --- a/app/finders/issuable_finder.rb +++ b/app/finders/issuable_finder.rb @@ -487,9 +487,9 @@ class IssuableFinder def by_milestone(items) if milestones? if filter_by_no_milestone? - items = items.left_joins_milestones.where(milestone_id: [-1, nil]) + items = items.left_joins_milestones.where(milestone_id: nil) elsif filter_by_any_milestone? - items = items.any_milestone + items elsif filter_by_upcoming_milestone? upcoming_ids = Milestone.upcoming_ids(projects, related_groups) items = items.left_joins_milestones.where(milestone_id: upcoming_ids) diff --git a/app/models/milestone.rb b/app/models/milestone.rb index 37c129e843a..eda14694105 100644 --- a/app/models/milestone.rb +++ b/app/models/milestone.rb @@ -4,8 +4,8 @@ class Milestone < ApplicationRecord # Represents a "No Milestone" state used for filtering Issues and Merge # Requests that have no milestone assigned. MilestoneStruct = Struct.new(:title, :name, :id) - None = MilestoneStruct.new('No Milestone', 'No Milestone', 0) - Any = MilestoneStruct.new('Any Milestone', '', -1) + None = MilestoneStruct.new('No Milestone', 'No Milestone', -1) + Any = MilestoneStruct.new('Any Milestone', '', nil) Upcoming = MilestoneStruct.new('Upcoming', '#upcoming', -2) Started = MilestoneStruct.new('Started', '#started', -3) diff --git a/db/migrate/20190703001116_default_milestone_to_nil.rb b/db/migrate/20190703001116_default_milestone_to_nil.rb new file mode 100644 index 00000000000..e6143cd619c --- /dev/null +++ b/db/migrate/20190703001116_default_milestone_to_nil.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class DefaultMilestoneToNil < ActiveRecord::Migration[5.1] + include Gitlab::Database::MigrationHelpers + + # Set this constant to true if this migration requires downtime. + DOWNTIME = false + + # When a migration requires downtime you **must** uncomment the following + # constant and define a short and easy to understand explanation as to why the + # migration requires downtime. + # DOWNTIME_REASON = '' + + # When using the methods "add_concurrent_index", "remove_concurrent_index" or + # "add_column_with_default" you must disable the use of transactions + # as these methods can not run in an existing transaction. + # When using "add_concurrent_index" or "remove_concurrent_index" methods make sure + # that either of them is the _only_ method called in the migration, + # any other changes should go in a separate migration. + # This ensures that upon failure _only_ the index creation or removing fails + # and can be retried or reverted easily. + # + # To disable transactions uncomment the following line and remove these + # comments: + # disable_ddl_transaction! + + def up + update_board_milestone_from_none_to_any + end + + def down + update_board_milestone_from_any_to_none + end + + # up methods + + def update_board_milestone_from_none_to_any + execute("UPDATE boards SET milestone_id = null WHERE milestone_id = -1") + end + + # down methods + + def update_board_milestone_from_any_to_none + execute("UPDATE boards SET milestone_id = -1 WHERE milestone_id = null") + end +end diff --git a/spec/finders/issues_finder_spec.rb b/spec/finders/issues_finder_spec.rb index bf38d083ca6..f6eeb38edaf 100644 --- a/spec/finders/issues_finder_spec.rb +++ b/spec/finders/issues_finder_spec.rb @@ -113,13 +113,13 @@ describe IssuesFinder do let(:params) { { milestone_title: 'Any' } } it 'returns issues with any assigned milestone' do - expect(issues).to contain_exactly(issue1) + expect(issues).to contain_exactly(issue1, issue2, issue3, issue4) end it 'returns issues with any assigned milestone (deprecated)' do params[:milestone_title] = Milestone::Any.title - expect(issues).to contain_exactly(issue1) + expect(issues).to contain_exactly(issue1, issue2, issue3, issue4) end end diff --git a/spec/requests/api/issues/get_project_issues_spec.rb b/spec/requests/api/issues/get_project_issues_spec.rb index f7ca6fd1e0a..f11d8259d4a 100644 --- a/spec/requests/api/issues/get_project_issues_spec.rb +++ b/spec/requests/api/issues/get_project_issues_spec.rb @@ -389,7 +389,7 @@ describe API::Issues do it 'returns an array of issues with any milestone' do get api("#{base_url}/issues", user), params: { milestone: any_milestone_title } - expect_paginated_array_response([issue.id, closed_issue.id]) + expect_paginated_array_response([issue.id, confidential_issue.id, closed_issue.id]) end context 'without sort params' do -- cgit v1.2.1