20150824000002_update_channel.rb 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. class UpdateChannel < ActiveRecord::Migration
  2. def up
  3. add_column :email_addresses, :channel_id, :integer, null: true
  4. EmailAddress.reset_column_information
  5. channel_inbound = Channel.find_by(area: 'Email::Inbound')
  6. if channel_inbound
  7. EmailAddress.all.each {|email_address|
  8. email_address.channel_id = channel_inbound.id
  9. email_address.save
  10. }
  11. end
  12. add_column :channels, :last_log_in, :text, limit: 500.kilobytes + 1, null: true
  13. add_column :channels, :last_log_out, :text, limit: 500.kilobytes + 1, null: true
  14. add_column :channels, :status_in, :string, limit: 100, null: true
  15. add_column :channels, :status_out, :string, limit: 100, null: true
  16. Channel.reset_column_information
  17. channel_outbound = Channel.find_by(area: 'Email::Outbound', active: true)
  18. Channel.all.each {|channel|
  19. if channel.area == 'Email::Inbound'
  20. channel.area = 'Email::Account'
  21. options = {
  22. inbound: {
  23. adapter: channel.adapter.downcase,
  24. options: channel.options,
  25. },
  26. outbound: {
  27. adapter: channel_outbound.adapter.downcase,
  28. options: channel_outbound.options,
  29. },
  30. }
  31. channel.options = options
  32. channel.save
  33. elsif channel.area == 'Email::Outbound'
  34. channel.area = 'Email::Notification'
  35. options = {
  36. outbound: {
  37. adapter: channel.adapter.downcase,
  38. options: channel.options,
  39. },
  40. }
  41. channel.options = options
  42. channel.save
  43. elsif channel.area == 'Twitter::Inbound'
  44. channel.area = 'Twitter::Account'
  45. channel.options[:adapter] = channel.adapter.downcase
  46. channel.save
  47. end
  48. }
  49. remove_column :channels, :adapter
  50. Channel.reset_column_information
  51. end
  52. end