How to remove HSTORE keys?

I have the following migration:

class CreateFoos < ActiveRecord::Migration def change create_table :foos do |t| t.hstore :foos_properties end end end 

In the hstore column, I have 2 keys :foo and :bar . Is it possible to create another migration to delete :foo ? What should it look like?

I found this:

 Foo.update_all([%(foos_properties = delete("foos_properties",?)), 'foo']) 

It's safe? Or should I consider a more reasonable approach?

+7
ruby-on-rails activerecord postgresql migration ruby-on-rails-4
source share
1 answer

I think your approach is great. I am doing something slightly similar:

 ObjectModel.find_each do |object_model| object_model.foos_properties.delete("foo") end 
0
source share

All Articles