Commit 1ea4b236 authored by Sean McGivern's avatar Sean McGivern

Add clean-up migration for RemoveCommaFromWeightSystemNotes

parent d91899d5
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180704204006) do
ActiveRecord::Schema.define(version: 20180718100455) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......
---
title: Ensure no weight change system notes end with a superfluous comma
merge_request: 6571
author:
type: other
class CleanUpFromWeightSystemNoteCommaMigration < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
MIGRATION = 'RemoveCommaFromWeightSystemNotes'.freeze
BATCH_SIZE = 1000
class Note < ActiveRecord::Base
self.table_name = 'notes'
include ::EachBatch
end
disable_ddl_transaction!
def up
Gitlab::BackgroundMigration.steal(MIGRATION)
migrate_inline if weight_system_notes.any?
end
def down
end
private
def weight_system_notes
Note
.joins('INNER JOIN system_note_metadata ON notes.id = system_note_metadata.note_id')
.where(system: true)
.where(system_note_metadata: { action: 'weight' })
.where("notes.note LIKE '%,'")
end
def migrate_inline
add_concurrent_index(:system_note_metadata, :action, where: "action = 'weight'")
weight_system_notes.each_batch(of: BATCH_SIZE) do |relation, index|
ids = relation.pluck(:id)
Gitlab::BackgroundMigration::RemoveCommaFromWeightSystemNotes.new.perform(ids)
end
remove_concurrent_index(:system_note_metadata, :action, where: "action = 'weight'")
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment