Enabling Ruby PostGIS Support on Heroku

I am trying to incorporate PostGIS into my Rails application on Heroku. My Gemfile includes the activerecord-postgis-adapter stone:

 gem 'activerecord-postgis-adapter', '3.0.0' 

However, after loading my instance, I do not see full support:

 $ heroku run irb Running `irb` attached to terminal... up, run.5549 irb(main):001:0> require 'rgeo' => true irb(main):002:0> RGeo::Geos.supported? => false 

I added heroku-geo-buildpack as specified in PostGIS , although I am using the new, true multi-buildpack format:

 $ heroku buildpacks === staging Buildpack URLs 1. https://github.com/cyberdelia/heroku-geo-buildpack.git#1.3 2. https://github.com/heroku/heroku-buildpack-ruby.git#v140 

I am confused since my build process looks right:

 -----> Multipack app detected -----> Fetching custom git buildpack... done -----> geos/gdal/proj app detected Using geos version: 3.4.2 Using gdal version: 1.11.1 Using proj version: 4.8.0_1 -----> Vendoring geo libraries done -----> Fetching custom git buildpack... done -----> Ruby app detected -----> Compiling Ruby/Rails ... 

What am I missing? I do not have a set of environment variables BUILDPACK_URL , since I am compiling it for the old multi-buildpack approach.

+5
source share
2 answers

PostGIS works with Heroku Free dyno and:
- Rails 4.2
- activerecord-postgis-adapter 3.1.4

You must:

  • set your config / database.yml as follows:

 default: &default adapter: postgis encoding: unicode # For details on connection pooling, see rails configuration guide # http://guides.rubyonrails.org/configuring.html#database-pooling pool: 5 development: <<: *default database: adopt_your_geek_development username: postgres host: mydb.com port: 9999 postgis_extension: postgis schema_search_path: public,postgis ... production: <<: *default database: appname_production username: appname password: <%= ENV['ADOPT_YOUR_GEEK_DATABASE_PASSWORD'] %> postgis_extension: postgis schema_search_path: public,postgis 

  1. Add buildpacks:
 $ heroku buildpacks:add https://github.com/ddollar/heroku-buildpack-multi.git 

With the following .buildpacks file:

 $ cat .buildpacks https://github.com/cyberdelia/heroku-geo-buildpack.git https://github.com/heroku/heroku-buildpack-ruby.git 

  1. Then add a small monckey patch to config / environment / production.rb
 module ActiveRecord module ConnectionHandling class MergeAndResolveDefaultUrlConfig private def config @raw_config.dup.tap do |cfg| if url = ENV['DATABASE_URL'] cfg[@env] ||= {} cfg[@env]["url"] ||= url.try(:gsub, "postgres", "postgis") end end end end end end 

I work for me right now on the free Heroku announcer with free postgres.

+4
source

I missed the fact that host level databases do not support PostGIS.

0
source

Source: https://habr.com/ru/post/1231993/


All Articles