summaryrefslogtreecommitdiff
path: root/db/post_migrate/20190715193142_migrate_discussion_id_on_promoted_epics.rb
diff options
context:
space:
mode:
Diffstat (limited to 'db/post_migrate/20190715193142_migrate_discussion_id_on_promoted_epics.rb')
-rw-r--r--db/post_migrate/20190715193142_migrate_discussion_id_on_promoted_epics.rb36
1 files changed, 22 insertions, 14 deletions
diff --git a/db/post_migrate/20190715193142_migrate_discussion_id_on_promoted_epics.rb b/db/post_migrate/20190715193142_migrate_discussion_id_on_promoted_epics.rb
index 3fd68198f42..efafcee4723 100644
--- a/db/post_migrate/20190715193142_migrate_discussion_id_on_promoted_epics.rb
+++ b/db/post_migrate/20190715193142_migrate_discussion_id_on_promoted_epics.rb
@@ -13,34 +13,42 @@ class MigrateDiscussionIdOnPromotedEpics < ActiveRecord::Migration[5.2]
disable_ddl_transaction!
+ class SystemNoteMtadata < ActiveRecord::Base
+ self.table_name = 'system_note_metadata'
+ end
+
class Note < ActiveRecord::Base
include EachBatch
+
+ has_one :system_note_metadata
+
self.table_name = 'notes'
def self.fetch_discussion_ids_query
promoted_epics_query = Note
- .where(system: true)
- .where(noteable_type: 'Epic')
- .where("note LIKE 'promoted from%'")
- .select("DISTINCT noteable_id")
+ .joins(:system_note_metadata)
+ .where(system: true)
+ .where(noteable_type: 'Epic')
+ .where("system_note_metadata.action='moved'")
+ .select("DISTINCT noteable_id")
+
Note.where(noteable_type: 'Epic')
.where(noteable_id: promoted_epics_query)
- .select("DISTINCT discussion_id").order(:discussion_id)
+ .order(:discussion_id)
+ .distinct.pluck(:discussion_id)
end
end
def up
- # add_concurrent_index(:system_note_metadata, :action)
-
- all_discussion_ids = Note.fetch_discussion_ids_query.collect(&:discussion_id)
- index = 0
- all_discussion_ids.in_groups_of(BATCH_SIZE) do |ids|
- index += 1
- delay = DELAY_INTERVAL * index
- BackgroundMigrationWorker.perform_in(delay, MIGRATION, [ids.compact])
+ add_concurrent_index(:system_note_metadata, :action, where: "action='moved'")
+
+ all_discussion_ids = Note.fetch_discussion_ids_query
+ all_discussion_ids.in_groups_of(BATCH_SIZE, false).each_with_index do |ids, index|
+ delay = DELAY_INTERVAL * (index + 1)
+ BackgroundMigrationWorker.perform_in(delay, MIGRATION, [ids])
end
- # add_concurrent_index(:system_note_metadata, :action)
+ remove_concurrent_index(:system_note_metadata, :action)
end
def down