【问题标题】:How to configure heroku ci for rails app with postgis?如何使用 postgis 为 rails 应用程序配置 heroku ci?
【发布时间】:2020-02-28 14:04:26
【问题描述】:

我的 rails 4 应用程序使用带有 activerecord-postgis-adapter 的 postgis。我正在尝试使用 Heroku CI。 ci 运行在加载数据库结构时到达 schema.rb 文件中的几何列描述时失败。

-----> Preparing test database

       Running: rake db:schema:load_if_ruby

       The PGconn, PGresult, and PGError constants are deprecated, and will be

       removed as of version 1.0.



       You should use PG::Connection, PG::Result, and PG::Error instead, respectively.



       Called from /app/vendor/bundle/ruby/2.5.0/gems/activesupport-4.2.11.1/lib/active_support/dependencies.rb:240:in `load_dependency'

       rake aborted!

       NoMethodError: undefined method `geometry' for #<ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition:0x000055bd614ea1a0>

       /app/db/schema.rb:105:in `block (2 levels) in <top (required)>'

       /app/vendor/bundle/ruby/2.5.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:216:in `create_table'
... 

我的 database.yml 文件为所有环境指定了 postgis 适配器,所以看到它使用 postgresql 适配器我很惊讶。

有什么建议吗?

我之前在sql中记录了数据库模式。我在 heroku 网站上找到了改用 ruby​​ 的建议。这没有帮助。

测试在本地运行良好。

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 heroku postgis heroku-ci


    【解决方案1】:

    我认为这只是 HerokuCI 的一个问题。一种解决方法是覆盖 DATABASE_URL 以指定 postgis。以下是实现此目的的两种不同方法:

    1. 在您的项目根目录中添加一个.profile 文件(documented here),其内容如下:
    export DATABASE_URL=`echo $DATABASE_URL | sed s/postgres/postgis/g`
    
    1. 或更新您的app.json 中的测试命令:
    {
      "environments": {
        "test": {
          "scripts": {
            "test": "export DATABASE_URL=`echo $DATABASE_URL | sed s/postgres/postgis/g`; <other test commands here>",
            ...
    

    因此,例如:如果 DATABASE_URL 是 postgres://foo:bar@example:5432/my-app,则在调用任何相关命令之前会将其更新为 postgis://foo:bar@example:5432/my-app

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-13
      • 2018-01-28
      • 2020-06-17
      • 1970-01-01
      相关资源
      最近更新 更多