Question

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?

Était-ce utile?

La solution 2

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

CREATE EXTENSION hstore

Autres conseils

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' })
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top