agenda-libre-ruby/db/migrate/20161210154558_populate_tag...

21 lines
577 B
Ruby

# Migrate tags from inline attribute to separate table
class PopulateTags < ActiveRecord::Migration
def self.up
execute('SELECT id, tags FROM events;').each do |result|
event = Event.find_by id: result[0]
event.tag_list = result[1] + ' helo world'
event.save
say event.id
say event.tag_list
end
change_column :events, :tags, :text, null: true
change_column :orgas, :tags, :text, null: true
end
def self.down
change_column :events, :tags, :text, null: false
change_column :orgas, :tags, :text, null: false
end
end