Skip to content

Instantly share code, notes, and snippets.

@DanielVartanov
Created April 30, 2010 10:25
Show Gist options
  • Save DanielVartanov/385042 to your computer and use it in GitHub Desktop.
Save DanielVartanov/385042 to your computer and use it in GitHub Desktop.
class ExtractAnswersTableMigration < ActiveRecord::Migration
def self.up
create_table :answers do |table|
table.string :body
table.integer :question_id
end
answers_strings = Question.all.map(&:answer)
answers_strings.each do |answer_string|
Answer.create! :body => answer_string
end
remove_column :questions, :answer
end
def self.down
add_column :questions, :answer, :string
Answer.all.each do |answer|
answer.question.answer = answer.body
end
drop_table :answers
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment