Files
old-holivud2/db/data_migrations/20191022200146_convert_releasable_notes_to_collection.rb
2020-05-31 22:38:19 +02:00

33 lines
843 B
Ruby

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