class ConvertReleasableNotesToCollection < ActiveRecord::DataMigration RELEASABLE_TYPES = [ TalentRelease, AppearanceRelease, LocationRelease, AcquiredMediaRelease, MaterialRelease, MusicRelease, ] def up RELEASABLE_TYPES.each { |type| convert_notes_to_collection_for(type) } say "Done." end private def convert_notes_to_collection_for(releasable_type) say "Converting #{releasable_type}#notes to collection..." releasable_type.where.not(notes_old: nil).find_each do |releasable| content = releasable[:notes_old] user = releasable.project.account.users.order(:created_at).first Note.create(content: content, user: user, notable: releasable) end end class Note < ActiveRecord::Base belongs_to :user belongs_to :notable, polymorphic: true end end