You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20210801211024_remove_orphaned_user_custom_values.rb 373B

123456789101112
  1. class RemoveOrphanedUserCustomValues < ActiveRecord::Migration[6.1]
  2. def up
  3. user_custom_field_ids = CustomField.where(field_format: 'user').ids
  4. if user_custom_field_ids.any?
  5. user_ids = Principal.ids
  6. CustomValue.
  7. where(custom_field_id: user_custom_field_ids).
  8. where.not(value: [nil, ''] + user_ids).
  9. delete_all
  10. end
  11. end
  12. end