summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2018-02-05 15:07:18 +0100
committerYorick Peterse <yorickpeterse@gmail.com>2018-02-05 15:07:18 +0100
commite26d993f99ddae8b15c68c7a80a924e12f7d8614 (patch)
tree7a34b13587ce83d792b74d93c3e481537e988e5b
parentbedfc7b103c25cd6b9aada350142549160e41a5e (diff)
downloadgitlab-ce-e26d993f99ddae8b15c68c7a80a924e12f7d8614.tar.gz
Handle EE edge cases in issues.closed_at migrationbetter-issues-closed-at-cleanup
EE seems to have had an outdated schema at some point, leading to some environments not having the right columns in place. This adjusts the migration for `issues.closed_at` so it takes care of those cases, ensuring data can be migrated properly. Fixes https://gitlab.com/gitlab-org/gitlab-ee/issues/4803
-rw-r--r--db/migrate/20180201145907_migrate_remaining_issues_closed_at.rb19
1 files changed, 16 insertions, 3 deletions
diff --git a/db/migrate/20180201145907_migrate_remaining_issues_closed_at.rb b/db/migrate/20180201145907_migrate_remaining_issues_closed_at.rb
index 7cb913bb2bf..5a36dec6a9a 100644
--- a/db/migrate/20180201145907_migrate_remaining_issues_closed_at.rb
+++ b/db/migrate/20180201145907_migrate_remaining_issues_closed_at.rb
@@ -18,12 +18,21 @@ class MigrateRemainingIssuesClosedAt < ActiveRecord::Migration
Gitlab::BackgroundMigration.steal('CopyColumn')
Gitlab::BackgroundMigration.steal('CleanupConcurrentTypeChange')
- # It's possible the cleanup job was killed which means we need to manually
- # migrate any remaining rows.
- migrate_remaining_rows if migrate_column_type?
+ if migrate_column_type?
+ if closed_at_for_type_change_exists?
+ migrate_remaining_rows
+ else
+ # Due to some EE merge problems some environments may not have the
+ # "closed_at_for_type_change" column. If this is the case we have no
+ # other option than to migrate the data _right now_.
+ change_column_type_concurrently(:issues, :closed_at, :datetime_with_timezone)
+ cleanup_concurrent_column_type_change(:issues, :closed_at)
+ end
+ end
end
def down
+ # Previous migrations already revert the changes made here.
end
def migrate_remaining_rows
@@ -39,4 +48,8 @@ class MigrateRemainingIssuesClosedAt < ActiveRecord::Migration
# migration, thus we don't need to migrate those environments again.
column_for('issues', 'closed_at').type == :datetime # rubocop:disable Migration/Datetime
end
+
+ def closed_at_for_type_change_exists?
+ columns('issues').any? { |col| col.name == 'closed_at_for_type_change' }
+ end
end