0

I upgraded mailboxer gem and followed the steps in the documents from 0.11 to 0.12:

$ rails generate mailboxer:namespacing_compatibility
    create  db/migrate/20140707050845_mailboxer_namespacing_compatibility.rb
$ rails generate mailboxer:install -s
    skip  config/initializers/mailboxer.rb
    Copied migration 20140707050855_add_conversation_optout.mailboxer_engine.rb from mailboxer_engine

Then when I tried

$ rake db:migrate

It gives me an error

PG::UndefinedTable: ERROR:  relation "notifications_on_conversation_id" does not exist

Any suggestions what this means? and how to fix?

Thanks

hellomello
  • 8,219
  • 39
  • 151
  • 297

1 Answers1

0

i had the same problem upgrading from mailboxer 0.9.0 to 0.12.4 (on rails 3.2.19).

what i did was to manually edit the migration created by the namespacing_compatibility generator as follows:

  • in the up migration i prefixed the "from" index names with "index_" in the rename_index commands.
  • in the down migration, i similarly renamed the "to" index names.
  • also in the down migration, i found i needed to move the update_all command to the beginning, before the rename_table commands.

my edited migration ended up like this. here i have indicted the edited lines with comments.

class MailboxerNamespacingCompatibility < ActiveRecord::Migration

  def self.up
    rename_table :conversations, :mailboxer_conversations
    rename_table :notifications, :mailboxer_notifications
    rename_table :receipts,      :mailboxer_receipts

    if Rails.version < '4'
      # i edited the next two lines by adding the index_ prefix
      rename_index :mailboxer_notifications, :index_notifications_on_conversation_id, :mailboxer_notifications_on_conversation_id 
      rename_index :mailboxer_receipts,      :index_receipts_on_notification_id,      :mailboxer_receipts_on_notification_id 
    end

    Mailboxer::Notification.where(type: 'Message').update_all(type: 'Mailboxer::Message')
  end

  def self.down
    # i moved this line from the end of the down block to here
    Mailboxer::Notification.where(type: 'Mailboxer::Message').update_all(type: 'Message')

    rename_table :mailboxer_conversations, :conversations
    rename_table :mailboxer_notifications, :notifications
    rename_table :mailboxer_receipts,      :receipts

    if Rails.version < '4'
      # i edited the next two lines by adding the index_ prefix
      rename_index :notifications, :mailboxer_notifications_on_conversation_id, :index_notifications_on_conversation_id
      rename_index :receipts,      :mailboxer_receipts_on_notification_id,      :index_receipts_on_notification_id
    end
  end
end

i then ran the migration, ran the other (mailboxer:install) generator, and ran that migration. so far things seem to be working.

user778174
  • 27
  • 6