diff options
author | Sean McGivern <sean@gitlab.com> | 2019-09-04 13:06:06 +0100 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2019-09-04 15:25:50 +0100 |
commit | d1c761b3e93ec09ba3f77ba7f4b2f229c425bd3c (patch) | |
tree | 7e90d9ea0c3a1d84e106717abc45f6f1669f5db5 /db | |
parent | f8f8ed471f6ce62b7198d49170845f7f5a09cf64 (diff) | |
download | gitlab-ce-d1c761b3e93ec09ba3f77ba7f4b2f229c425bd3c.tar.gz |
Make epic_issues relative_position migration more robustmake-epics-position-migration-robust
If someone installed EE, then downgraded to CE before this column was
added, upgrading to the latest version of CE will fail:
1. We have a backport migration for the entire EE schema but the table
`epic_issues` exists, just not the `relative_position` column.
2. The migration that changes the default (quite reasonably) didn't
check if the column exists.
If the column doesn't exist, we can just create it with the correct
default.
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20190806071559_remove_epic_issues_default_relative_position.rb | 21 |
1 files changed, 18 insertions, 3 deletions
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 |