2018-03-10 10:15:56 +01:00
|
|
|
class RemoveNotesFromArtists < ActiveRecord::Migration[5.1]
|
2010-04-20 23:05:11 +00:00
|
|
|
def self.up
|
2024-01-08 19:39:01 +09:00
|
|
|
Artist.find(:all, conditions: [ "notes <> '' and notes is not null" ]).each do |artist|
|
2010-04-20 23:05:11 +00:00
|
|
|
page = WikiPage.find_by_title(artist.name)
|
|
|
|
notes = artist.__send__(:read_attribute, :notes)
|
2014-08-23 16:19:01 +09:00
|
|
|
|
2010-04-20 23:05:11 +00:00
|
|
|
if page
|
2024-01-08 19:39:01 +09:00
|
|
|
page.update(body: notes, ip_addr: "127.0.0.1", user_id: 1)
|
2010-04-20 23:05:11 +00:00
|
|
|
else
|
2024-01-08 19:39:01 +09:00
|
|
|
WikiPage.create(title: artist.name, body: notes, ip_addr: "127.0.0.1", user_id: 1)
|
2010-04-20 23:05:11 +00:00
|
|
|
end
|
|
|
|
end
|
2014-08-23 16:19:01 +09:00
|
|
|
|
2010-04-20 23:05:11 +00:00
|
|
|
remove_column :artists, :notes
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.down
|
2024-01-08 19:39:01 +09:00
|
|
|
add_column :artists, :notes, :text, default: "", null: false
|
2010-04-20 23:05:11 +00:00
|
|
|
end
|
|
|
|
end
|