我有一个复杂的问题与Devise和偏执狂(acts_as_paranoid)宝石。 我的用户模型相对简单:
class User < AR::Base devise :confirmable, :other_config_options acts_as_paranoid end我首先添加了Devise gem而没有确认选项。 然后我在此迁移中添加了可确认选项:
def up add_column :users, :confirmed_at, :datetime add_column :users, :confirmation_token, :string add_column :users, :confirmation_sent_at, :datetime add_column :users, :unconfirmed_email, :string add_index :users, :confirmation_token, unique: true User.update_all(:confirmed_at => Time.now) end到目前为止没问题。 然后我将Paranoia gem和acts_as_paranoid行添加到User模型中。 我的数据库在当前状态下很好,但我正在尝试重置我的数据库以将其与生产数据同步,这就是我遇到问题的地方。 当我执行db:reset时,它无法完成上述迁移:
PG::UndefinedColumn: ERROR: column users.deleted_at does not exist问题是我的模型包含一个只对当前数据库快照有效的指令acts_as_paranoid 。 如果我回滚到以前的数据库快照, User::deleted_at不存在,则paranoia gem仍会尝试仅更新未删除的对象,并且我的查询失败。
有什么想法以优雅的方式处理这种情况?
I have a complicated issue with Devise and the paranoia(acts_as_paranoid) gem. My User model is relatively simple:
class User < AR::Base devise :confirmable, :other_config_options acts_as_paranoid endI added the Devise gem first without the confirmable option. Then I later added the confirmable option with this migration:
def up add_column :users, :confirmed_at, :datetime add_column :users, :confirmation_token, :string add_column :users, :confirmation_sent_at, :datetime add_column :users, :unconfirmed_email, :string add_index :users, :confirmation_token, unique: true User.update_all(:confirmed_at => Time.now) endNo problem up to this point. Then I added the Paranoia gem and the acts_as_paranoid line to the User model. My database is fine in its current state, but I'm trying to reset my database to sync it with production data, and this is where I'm running into problems. When I do a db:reset, it fails the above migration:
PG::UndefinedColumn: ERROR: column users.deleted_at does not existThe trouble is that my model contains a directive acts_as_paranoid that is valid only with the current database snapshot. If I roll back to a previous database snapshot, User::deleted_at doesn't exist, the paranoia gem still attempts to update only non-deleted objects, and my query fails.
Any thoughts on an elegant way to handle this situation?
更多推荐
发布评论