7

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 remove :foo? How should it look like?

I've found this:

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

Is that safe? Or should I consider a more sensible approach?

Christian Fazzini
  • 19,613
  • 21
  • 110
  • 215

1 Answers1

0

I think your approach is fine. I do something slightly similar:

ObjectModel.find_each do |object_model|
  object_model.foos_properties.delete("foo")
end
Arturo Herrero
  • 12,772
  • 11
  • 42
  • 73