summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2018-02-01 16:23:32 +0100
committerYorick Peterse <yorickpeterse@gmail.com>2018-02-01 16:24:10 +0100
commitf01e9c1ef65d77d10807f98cde9ce5f5911787c8 (patch)
tree534f206a653ab60cce54abdd09b3725b3029b134
parent5b73e0eb35f5b9b78c228a4867ef78538ef05653 (diff)
downloadgitlab-ce-issues-closed-at-steal.tar.gz
Finish any remaining jobs for issues.closed_atissues-closed-at-steal
In the event of Sidekiq jobs getting lost there may be some rows left to migrate. This migration ensures any remaining jobs are completed and that all data has been migrated. This fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/41595
-rw-r--r--changelogs/unreleased/issues-closed-at-steal.yml5
-rw-r--r--db/migrate/20180201145907_migrate_remaining_issues_closed_at.rb42
-rw-r--r--db/schema.rb2
3 files changed, 48 insertions, 1 deletions
diff --git a/changelogs/unreleased/issues-closed-at-steal.yml b/changelogs/unreleased/issues-closed-at-steal.yml
new file mode 100644
index 00000000000..a5f0898995f
--- /dev/null
+++ b/changelogs/unreleased/issues-closed-at-steal.yml
@@ -0,0 +1,5 @@
+---
+title: Finish any remaining jobs for issues.closed_at
+merge_request:
+author:
+type: other
diff --git a/db/migrate/20180201145907_migrate_remaining_issues_closed_at.rb b/db/migrate/20180201145907_migrate_remaining_issues_closed_at.rb
new file mode 100644
index 00000000000..7cb913bb2bf
--- /dev/null
+++ b/db/migrate/20180201145907_migrate_remaining_issues_closed_at.rb
@@ -0,0 +1,42 @@
+# See http://doc.gitlab.com/ce/development/migration_style_guide.html
+# for more information on how to write migrations for GitLab.
+
+class MigrateRemainingIssuesClosedAt < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ # Set this constant to true if this migration requires downtime.
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ class Issue < ActiveRecord::Base
+ self.table_name = 'issues'
+ include EachBatch
+ end
+
+ def up
+ 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?
+ end
+
+ def down
+ end
+
+ def migrate_remaining_rows
+ Issue.where('closed_at_for_type_change IS NULL AND closed_at IS NOT NULL').each_batch do |batch|
+ batch.update_all('closed_at_for_type_change = closed_at')
+ end
+
+ cleanup_concurrent_column_type_change(:issues, :closed_at)
+ end
+
+ def migrate_column_type?
+ # Some environments may have already executed the previous version of this
+ # migration, thus we don't need to migrate those environments again.
+ column_for('issues', 'closed_at').type == :datetime # rubocop:disable Migration/Datetime
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 4e82a688725..0d97b6f9ddd 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20180115201419) do
+ActiveRecord::Schema.define(version: 20180201145907) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"