2

I´m trying to add a column using postgresql HStore.

Since I´m running a multi tenant app (using apartment gem), I´ve created the hstore extension on a dedicated schema, called "shared_extensions", as seen here: [https://github.com/influitive/apartment#installing-extensions-into-persistent-schemas][1]

I also added the shared_extensions schema to database.yml as:

default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5
  schema_search_path: "public,shared_extensions"

However, when I try to run rake db:migrate to add hstore column, I´m still receiving the error:

ActiveRecord::StatementInvalid: PG::UndefinedObject: ERROR:  type "hstore" does not exist

This is the hstore migration code:

class AddAdditionalInformationsToParties < ActiveRecord::Migration
  def change
    add_column :parties, :additional_informations, :hstore
  end
end

I´m not sure, but it looks like migrations are not recognizing the schema_search_path on database.yml file.

Chris
  • 11,819
  • 19
  • 91
  • 145
Leandro França
  • 1,884
  • 2
  • 11
  • 11

2 Answers2

3

You need to enable the hstore extension in postgres.

Try running rails g migration add_hstore_extension, then edit it like below:

class AddHstoreExtension < ActiveRecord::Migration def self.up enable_extension "hstore" end def self.down disable_extension "hstore" end end

Note that you'll need that to run before the migration which uses it.

Chris
  • 11,819
  • 19
  • 91
  • 145
  • Hey Chris, This works on a sample app I have created. However, I´m using multiple postgresql schemas to run a multi-tenant app. As soon as I try to use hstore on another schema, I run into the same error. This is why I came with the option to create a specific schema just for hstore extension, and then try to put it on search_path for all other schemas. – Leandro França Aug 30 '15 at 02:23
  • The solution I´m trying to implement is the one written here: https://github.com/influitive/apartment#installing-extensions-into-persistent-schemas – Leandro França Aug 30 '15 at 02:24
0

I ended up adding the extension to pg_catalog, which is always implicitly on search_path, as described by Craig Ringer in this post:

Create HSTORE with multiple schemas

CREATE EXTENSION hstore WITH SCHEMA pg_catalog;
Community
  • 1
  • 1
Leandro França
  • 1,884
  • 2
  • 11
  • 11