5

How do I create a hstore column in a Sequel migration?

Sequel.migration do
  change do
    add_column :logs, :geo, HStore
  end
end

fails. Do I have to load an extension?

MegaTux
  • 1,591
  • 21
  • 26
  • I suspect your answer lies in this documentation, http://sequel.jeremyevans.net/rdoc/files/doc/postgresql_rdoc.html. Specifically, look at the heading **PostgreSQL-specific Database Type Support** – Srdjan Pejic Jan 14 '14 at 21:26
  • 1
    Thanks for pointing me the correct doc page, but I still can't run the migration. I tried different names like :hstore, :h_store, :pg_hstore, HStore, etc. I've loaded the :pg_store DB extension and even added sequel_pg & sequel-hstore gems to the Gemfile. Tried with json datatype and works ok, but I prefer hstore. – MegaTux Jan 15 '14 at 14:34
  • Maybe it's a bug in the gem. Have you reported it to the maintainers? – Srdjan Pejic Jan 17 '14 at 18:35
  • I'll look in the [G.Group](https://groups.google.com/forum/#!forum/sequel-talk), thanks. – MegaTux Jan 20 '14 at 18:53

2 Answers2

4

I could not find this in the documentation so I asked on IRC.

jeremyevans: method_missing is used, allowing you to use any custom database types

So you can specify json, jsonb as long as the extension is enabled:

Sequel.migration do
  change do
    create_table :foo do
      primary_key :id
      jsonb :bar
    end
  end
end

To enable the extension:

Sequel.extension :pg_json

And to create a new record:

foo = Foo.new bar: Sequel.pg_jsonb({ 'baz' => 'qux' })
Austin Richardson
  • 8,078
  • 13
  • 43
  • 49
2

As the Author's gem answered me, the DB needs this additional extension before using it:

CREATE EXTENSION hstore
MegaTux
  • 1,591
  • 21
  • 26