【问题标题】:Heroku: error for PostGIS column in web dyno but not in one-off or worker dynosHeroku:Web dyno 中 PostGIS 列的错误,但在一次性或工人 dyno 中没有
【发布时间】:2016-02-01 21:17:09
【问题描述】:

我已经有了一个空间应用程序(PostGIS + Rails + RGeo)的开端,我的一个模型上有一个 line_string 列。在我的本地机器上一切都很好,问题出在 Heroku web dynos 上,Rails/activerecord 无法识别 RGeo/PostGIS line_string 类型。

每次部署后,第一次加载模型时,我都会在日志中看到以下内容:

app[web.1]: unknown OID 17059: failed to recognize type of 'line_string'. It will be treated as String.

然后,如果我向 STDOUT 添加一些日志记录,我可以看到:

mymodel.line_string.class # String
RGeo::Feature::Geometry.check_type(mymodel.line_string) # false

但是,如果我使用 Rails 控制台 (heroku run rails c production) 运行一次性测功机,一切都很好。我看到了我期望的输出:

irb(main):001:0> mymodel.line_string.class
=> RGeo::Geographic::SphericalLineStringImpl

irb(main):002:0> RGeo::Feature::Geometry.check_type(mymodel.line_string)
=> true

在worker dynos下也可以。

什么会导致未知的 OID 错误?为什么一次性和工人 dyno 能够完美地使用这个专栏,而 web dyno 却不能?

【问题讨论】:

    标签: ruby-on-rails heroku postgis rgeo


    【解决方案1】:

    Puma 开始时没有配置我在 application.rb 中添加的 PostGIS。一旦我将以下内容添加到config/puma.rb,ActiveRecord 就开始使用 PostGIS:

    on_worker_boot do
      if defined?(ActiveRecord::Base)
        config = ActiveRecord::Base.configurations[Rails.env] ||
          Rails.application.config.database_configuration[Rails.env]
        config['adapter'] = 'postgis'
        ActiveRecord::Base.establish_connection(config)
      end
    end
    
    on_restart do
      if defined?(ActiveRecord::Base)
        config = ActiveRecord::Base.configurations[Rails.env] ||
          Rails.application.config.database_configuration[Rails.env]
        config['adapter'] = 'postgis'
        ActiveRecord::Base.establish_connection(config)
      end
    end
    

    其他测功机类型只是使用application.rb,所以它们总是被正确配置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-04
      • 1970-01-01
      • 2023-03-09
      • 2020-11-17
      • 2021-05-13
      • 2021-02-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多