0

我升级了mailboxer gem,并按照文档中的步骤从0.11升级到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

然后当我尝试

$ rake db:migrate

它给了我一个错误

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

任何建议这意味着什么?以及如何解决?

谢谢

4

1 回答 1

0

我从邮箱 0.9.0 升级到 0.12.4(在 rails 3.2.19 上)时遇到了同样的问题。

我所做的是手动编辑namespacing_compatibility生成器创建的迁移,如下所示:

  • 在向上迁移中,我在命令中为“from”索引名称添加了“index_”前缀rename_index
  • 在向下迁移中,我同样重命名了“to”索引名称。
  • 同样在向下迁移中,我发现我需要将命令移到update_all命令的开头,在rename_table命令之前。

我编辑的迁移结果是这样的。在这里,我已经用评论指出了已编辑的行。

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

然后我运行迁移,运行另一个 (mailboxer:install) 生成器,然后运行迁移。到目前为止,事情似乎正在奏效。

于 2014-10-08T19:50:59.807 回答