1
0
mirror of https://github.com/meineerde/redmine.git synced 2026-03-29 12:11:13 +00:00
redmine/db/migrate/20210801211024_remove_orphaned_user_custom_values.rb
2021-09-06 18:30:04 +00:00

13 lines
387 B
Ruby

class RemoveOrphanedUserCustomValues < ActiveRecord::Migration[6.1]
def up
user_custom_field_ids = CustomField.where(field_format: 'user').pluck(:id)
if user_custom_field_ids.any?
user_ids = Principal.pluck(:id)
CustomValue.
where(custom_field_id: user_custom_field_ids).
where.not(value: [nil, ''] + user_ids).
delete_all
end
end
end