summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2018-02-02 11:58:32 +0000
committerSean McGivern <sean@mcgivern.me.uk>2018-02-02 11:58:32 +0000
commit36838a843e99f551c971ec7062327e114c8f0188 (patch)
tree0ee2afe8228f184f7ad28e74d86bff2c5965c4ae /db
parenta5bb17ffd5d466568c3bcea161bac42123bd3c1e (diff)
parentc63af942e5baf7849a94fa99da8494bcba28e3f8 (diff)
downloadgitlab-ce-36838a843e99f551c971ec7062327e114c8f0188.tar.gz
Merge branch 'master' into '3867-port-to-ce'
# Conflicts: # db/schema.rb
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20180201145907_migrate_remaining_issues_closed_at.rb42
-rw-r--r--db/schema.rb2
2 files changed, 43 insertions, 1 deletions
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 962d25b40b1..01a2df13dd3 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: 20180119135717) do
+ActiveRecord::Schema.define(version: 20180201145907) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"