2

我正在尝试postgis在公寓租用的 Postgresql 数据库中启用,但我完全被卡住了。

请参阅所有相关部分的要点:https ://gist.github.com/phildionne/6c5cdd210f4e91bd43bb

公寓.rb 配置

Apartment.configure do |config|
  config.persistent_schemas = %w{ shared_extensions }
end

数据库配置

defaults: &defaults
  adapter: postgis
  postgis_extension: true
  schema_search_path: "public,shared_extensions"
  encoding: unicode
  host: 127.0.0.1
  pool: 5
  timeout: 5000

development:
  <<: *defaults
  database: development
  username:
  password:

启用 PostGIS

  namespace :db do
    desc 'Creates shared_extensions Schema and enables postgis extension'
    task :extensions => :environment  do
      # Create shared_extensions schema
      ActiveRecord::Base.connection.execute 'CREATE SCHEMA IF NOT EXISTS shared_extensions;'
      # Enable PostGIS
      ActiveRecord::Base.connection.execute 'CREATE EXTENSION IF NOT EXISTS postgis SCHEMA shared_extensions;'
    end
  end

  Rake::Task["db:create"].enhance do
    Rake::Task["db:extensions"].invoke
  end

  Rake::Task["db:test:purge"].enhance do
    Rake::Task["db:extensions"].invoke
  end

移民

  class UpdateSamplingPointsGeo < ActiveRecord::Migration
    def change
      add_column(:sampling_points, :coordinates, :st_point, has_z: true)

      add_index :sampling_points, :coordinates, using: :gist
    end
  end

架构.rb

  AtiveRecord::Schema.define(version: 20150228171547) do

    # These are extensions that must be enabled in order to support this database
    enable_extension "plpgsql"
    enable_extension "postgis"

    create_table "sampling_points", force: :cascade do |t|
      t.geometry "coordinates",                     limit: {:srid=>0, :type=>"point"}
    end
  end

PostGIS 已安装:

  SELECT PostGIS_full_version();
  OTICE:  Function postgis_topology_scripts_installed() not found. Is topology support enabled and topology.sql installed?
                                                                           postgis_full_version
  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
   POSTGIS="2.1.5 r13152" GEOS="3.4.2-CAPI-1.8.2 r3921" PROJ="Rel. 4.8.0, 6 March 2012" GDAL="GDAL 1.11.1, released 2014/09/24" LIBXML="2.9.1" LIBJSON="UNKNOWN" RASTER
  (1 row)

错误日志

  CREATE TABLE "sampling_points" ("id" serial primary key, "localisation_description" text, "notes" text, "created_at" timestamp, "updated_at" timestamp, "waterbody_id" integer, "entity_id" integer, "name" character varying, "sampling_point_justification_id" integer, "slug" character varying NOT NULL, "coordinates" geometry(POINT,0))
  ActiveRecord::StatementInvalid: PG::UndefinedObject: ERROR:  type "geometry" does not exist
  LINE 1: ... "slug" character varying NOT NULL, "coordinates" geometry(P...
                                                               ^
  : CREATE TABLE "sampling_points" ("id" serial primary key, "localisation_description" text, "notes" text, "created_at" timestamp, "updated_at" timestamp, "waterbody_id" integer, "entity_id" integer, "name" character varying, "sampling_point_justification_id" integer, "slug" character varying NOT NULL, "coordinates" geometry(POINT,0))
  from /Users/pdionne/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `async_exec'
4

0 回答 0