Sha256: 041516c93c86aa5cfac3da0dd9dc2ee206f61503cef3e772c5c6c38313d5ea1d
Contents?: true
Size: 681 Bytes
Versions: 200
Compression:
Stored size: 681 Bytes
Contents
class MoveHostDescriptionToHostComment < ActiveRecord::Migration[4.2] class Host < ApplicationRecord self.table_name = "hosts" end def up Host.find_each do |host| new_comment = nil if host.comment.blank? new_comment = host.description else new_comment = [host.comment, host.description].join("\n") unless host.description.empty? end host.update_column(:comment, new_comment) if new_comment end remove_column :hosts, :description end def down add_column :hosts, :description, :text Host.find_each do |host| host.update_columns(:comment => nil, :description => host.comment) end end end
Version data entries
200 entries across 200 versions & 1 rubygems