0

我的 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​​ 的建议。那没有帮助。

测试在本地运行良好。

4

1 回答 1

0

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

  1. 在您的项目根目录中添加一个.profile文件(在此处记录),其中包含以下内容:
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在调用任何相关命令之前将其更新。

于 2019-11-26T05:30:51.950 回答