diff --git a/db/migrate/20190806071559_remove_epic_issues_default_relative_position.rb b/db/migrate/20190806071559_remove_epic_issues_default_relative_position.rb index f6db90f6637..3037f2ea106 100644 --- a/db/migrate/20190806071559_remove_epic_issues_default_relative_position.rb +++ b/db/migrate/20190806071559_remove_epic_issues_default_relative_position.rb @@ -3,8 +3,23 @@ class RemoveEpicIssuesDefaultRelativePosition < ActiveRecord::Migration[5.2] DOWNTIME = false - def change - change_column_null :epic_issues, :relative_position, true - change_column_default :epic_issues, :relative_position, from: 1073741823, to: nil + include Gitlab::Database::MigrationHelpers + + 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