mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-16 06:06:56 +08:00
24 lines
776 B
Ruby
24 lines
776 B
Ruby
# frozen_string_literal: true
|
|
|
|
class FixDuplicatedChecklistsPositions < ActiveRecord::Migration[7.0]
|
|
def up
|
|
ActiveRecord::Base.no_touching do
|
|
checklists = Checklist.where(id: ChecklistItem.select(:checklist_id)
|
|
.group(:checklist_id, :position)
|
|
.having('COUNT(*) > 1').distinct)
|
|
|
|
ChecklistItem.acts_as_list_no_update do
|
|
checklists.find_each do |checklist|
|
|
checklist.checklist_items.each.with_index do |checklist_item, index|
|
|
checklist_item.position = index
|
|
checklist_item.save!(validate: false)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
def down
|
|
raise ActiveRecord::IrreversibleMigration
|
|
end
|
|
end
|