docbrown/lib/data_update_scripts/20200826075937_migrate_profile_field_groups.rb
Michael Kohl 161ed7d55e
[deploy] Introduce ProfileFieldGroup model (#10007)
* Introduce ProfileFieldGroup model

* Make profile_fields_groups name column unique

* Fix some specs

* feat: allow the page to work again

* Add guard clause to data update script

* Remove unused file

* Fix specs

* Add foreign key

Co-authored-by: Ridhwana <ridhwana.khan16@gmail.com>
2020-08-28 10:51:33 +07:00

16 lines
498 B
Ruby

module DataUpdateScripts
class MigrateProfileFieldGroups
def run
# ensure we can run this after the group column gets removed
return unless "group".in?(ProfileField.column_names)
profile_field_groups = Hash.new do |hash, key|
hash[key] = ProfileFieldGroup.find_or_create_by(name: key)
end
ProfileField.find_each do |profile_field|
profile_field.update(profile_field_group: profile_field_groups[profile_field.group])
end
end
end
end