简体   繁体   中英

How to configure heroku ci for rails app with postgis?

My rails 4 app uses postgis with the activerecord-postgis-adapter. I'm attempting to use Heroku CI. The ci run fails when it is loading the database structure when it reaches a geometry column description in the schema.rb file.

-----> 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'
... 

My database.yml file specifies the postgis adapter for all environments, so I'm surprised to see it using the postgresql adapter.

Any suggestions?

I previously recorded the database schema in sql. I found a suggestion on the heroku site to switch to ruby. That didn't help.

The tests run fine locally.

I think this is just an issue with HerokuCI. A workaround is to overwrite the DATABASE_URL to specify postgis. Below are two different ways to accomplish that:

  1. Add a .profile file ( documented here ) in your project root with the following contents:
export DATABASE_URL=`echo $DATABASE_URL | sed s/postgres/postgis/g`
  1. OR Update the test command in your app.json :
{
  "environments": {
    "test": {
      "scripts": {
        "test": "export DATABASE_URL=`echo $DATABASE_URL | sed s/postgres/postgis/g`; <other test commands here>",
        ...

So, for example: if the DATABASE_URL was postgres://foo:bar@example:5432/my-app , that would update it to postgis://foo:bar@example:5432/my-app before any of the relevant commands are invoked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM