Chatwoot/db/migrate/20200605130625_agent_away_message_to_auto_reply.rb

22 lines
659 B
Ruby
Raw Normal View History

class AgentAwayMessageToAutoReply < ActiveRecord::Migration[6.0]
def change
add_column :inboxes, :greeting_enabled, :boolean, default: false # rubocop:disable Rails/BulkChangeTable
add_column :inboxes, :greeting_message, :string
migrate_agent_away_to_greeting
remove_column :channel_web_widgets, :agent_away_message, :string
end
def migrate_agent_away_to_greeting
::Channel::WebWidget.find_in_batches do |widget_batch|
widget_batch.each do |widget|
inbox = widget.inbox
inbox.greeting_enabled = true
inbox.greeting_message = widget.agent_away_message
widget.save!
end
end
end
end