Rails acts

编程入门 行业动态 更新时间:2024-10-24 01:54:42
Rails acts_as_paranoid迁移问题(Rails acts_as_paranoid migration issue)

我有一个复杂的问题与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 end

I 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) end

No 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 exist

The 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?

更多推荐

本文发布于:2023-08-03 13:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1391970.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Rails   acts

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!