I have been using the Acts as Paranoid gem and now I have a bunch of Users that have been soft deleted. I am trying to add a non-null column but I keep getting errors because those soft-deleted records have a null value and I cannot update them. How can I handle this?
Here's the migration I'm trying to run:
def change
add_column :users, :jti, :string
# Does not include soft-deleted records
User.all.each { |user| user.update_column(:jti, SecureRandom.uuid) }
missing_jti = User.with_deleted.where(jti: nil)
p "Users missing jti: #{missing_jti.count}" # NOT 0
change_column_null :users, :jti, false # throws error due to soft-deleted records containing null jti
end
When I attempt to update the soft-deleted records, I get an error:
User.with_deleted.each { |user| user.update_column(:jti, SecureRandom.uuid) }
ActiveRecord::ActiveRecordError: cannot update a destroyed record