【问题标题】:Migration wont recognize hstore extension created on schema_search_path迁移无法识别在架构 search_path 上创建的 hstore 扩展
【发布时间】:2015-08-30 01:53:39
【问题描述】:

我正在尝试使用 postgresql HStore 添加列。

由于我正在运行一个多租户应用程序(使用公寓 gem),我已经在一个名为“shared_extensions”的专用架构上创建了 hstore 扩展,如下所示:[https://github.com/influitive/apartment#installing-extensions-into-persistent-schemas][1]

我还将 shared_extensions 架构添加到 database.yml 中:

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

但是,当我尝试运行 rake db:migrate 以添加 hstore 列时,我仍然收到错误:

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

这是 hstore 迁移代码:

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

我不确定,但迁移似乎无法识别 database.yml 文件中的 schema_search_path。

【问题讨论】:

    标签: ruby-on-rails postgresql rails-migrations hstore apartment-gem


    【解决方案1】:

    您需要在 postgres 中启用 hstore 扩展。

    尝试运行rails g migration add_hstore_extension,然后像下面这样编辑它:

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

    请注意,您需要在使用它的迁移之前运行

    【讨论】:

    • 嘿克里斯,这适用于我创建的示例应用程序。但是,我正在使用多个 postgresql 模式来运行多租户应用程序。一旦我尝试在另一个模式上使用 hstore,我就会遇到同样的错误。这就是为什么我提供了仅为 hstore 扩展创建特定架构的选项,然后尝试将其放在 search_path 上以用于所有其他架构。
    • 我正在尝试实施的解决方案是这里写的:github.com/influitive/…
    【解决方案2】:

    我最终将扩展添加到 pg_catalog,它始终隐含在 search_path 上,正如 Craig Ringer 在这篇文章中所描述的那样:

    Create HSTORE with multiple schemas

    CREATE EXTENSION hstore WITH SCHEMA pg_catalog;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-14
      • 1970-01-01
      • 2017-10-13
      • 2021-12-14
      • 2022-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多