Rails are not fully compatible with the postgresql + postgis geometry data type

I am using Rails 3.1 and I have tables with the PostGIS geometry data type. They do not seem to be compatible with the rake db:schema:dump or rake db:test:clone and rake test:* tasks. Tables containing this data type are simply not processed or created by these tasks.

Is there a patch or solution for this?

+4
source share
1 answer

There is a solution:

First of all, you will need a PostgreSQL template with support for PostGIS functions.

Create a template database:

 $ psql -U postgres > CREATE DATABASE template_postgis WITH TEMPLATE=template1 ENCODING='UTF8'; > \c template_postgis; > CREATE LANGUAGE plpgsql; 

Download the necessary PostGIS functions to the template (I use Homebrew, so find the paths to your PostGIS SQL files):

 $ psql -f /usr/local/share/postgis/postgis.sql template_postgis $ psql -f /usr/local/share/postgis/spatial_ref_sys.sql template_postgis 

Set the database as a template and grant permissions:

 $ psql -U postgres template_postgis > UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template_postgis'; > GRANT ALL ON geometry_columns TO PUBLIC; > GRANT ALL ON spatial_ref_sys TO PUBLIC; 

Then add the gem 'postgis_adapter' to your Gemfile and run bundle . After that, add template: template_postgis to your config/database.yml as follows:

 development: adapter: postgresql template: template_postgis database: postgis_db 

And - voila! Welcome aboard!

+4
source

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


All Articles