如何使用data_migration删除?

问题描述

我想知道2021年9月7日以后如何完成删除会话类的方法

class RemovesConversationClass < ActiveRecord::Migration[5.2]

  def up
    ConversationClass.where("created_at > ")destroy_all
  end

  def down
    raise ActiveRecord::IrreversibleMigration
  end

end

解决方法

你可以有这样的时间Time.new(2021,9,7)

ConversationClass.where("created_at > ?",Time.new(2021,7)).destroy_all

应该可以。但在生产环境中使用之前,您应该先在开发环境中对其进行测试。