Ensure Migrations Use The Latest Schema
# Assume the following are defined:
# GenericAuthor for table 'authors'
# GenericBook for table 'books'
def up
add_column :books, :genre, :string
GenericAuthor.find_each do |author|
book = GenericBook.find_by(author_id: author.id)
book.update!(genre: author.genre)
end
remove_column :authors, :genre
enddef up
add_column :books, :genre, :string
GenericBook.reset_column_information
GenericAuthor.find_each do |author|
book = GenericBook.find_by(author_id: author.id)
book.update!(genre: author.genre)
end
remove_column :authors, :genre
endLast updated