Merge branch 'make-epics-position-migration-robust' into 'master'

Make epic_issues relative_position migration more robust

Closes #66923

See merge request gitlab-org/gitlab-ce!32646
This commit is contained in:
Andreas Brandl 2019-09-09 12:48:48 +00:00
commit 5abc37bd85

View file

@ -3,8 +3,23 @@
class RemoveEpicIssuesDefaultRelativePosition < ActiveRecord::Migration[5.2] class RemoveEpicIssuesDefaultRelativePosition < ActiveRecord::Migration[5.2]
DOWNTIME = false DOWNTIME = false
def change include Gitlab::Database::MigrationHelpers
change_column_null :epic_issues, :relative_position, true
change_column_default :epic_issues, :relative_position, from: 1073741823, to: nil disable_ddl_transaction!
def up
# The column won't exist if someone installed EE, downgraded to CE
# before it was added in EE, then tries to upgrade CE.
if column_exists?(:epic_issues, :relative_position)
change_column_null :epic_issues, :relative_position, true
change_column_default :epic_issues, :relative_position, from: 1073741823, to: nil
else
add_column_with_default(:epic_issues, :relative_position, :integer, default: nil, allow_null: true)
end
end
def down
change_column_default :epic_issues, :relative_position, from: nil, to: 1073741823
change_column_null :epic_issues, :relative_position, false
end end
end end