activerecord-postgis-adapter 7.0.0 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/active_record/connection_adapters/postgis/create_connection.rb +4 -0
- data/lib/active_record/connection_adapters/postgis/database_statements.rb +14 -0
- data/lib/active_record/connection_adapters/postgis/oid/spatial.rb +14 -15
- data/lib/active_record/connection_adapters/postgis/schema_statements.rb +0 -20
- data/lib/active_record/connection_adapters/postgis/spatial_column.rb +9 -10
- data/lib/active_record/connection_adapters/postgis/spatial_column_info.rb +1 -1
- data/lib/active_record/connection_adapters/postgis/spatial_table_definition.rb +2 -2
- data/lib/active_record/connection_adapters/postgis/type.rb +22 -0
- data/lib/active_record/connection_adapters/postgis/version.rb +1 -1
- data/lib/active_record/connection_adapters/postgis_adapter.rb +84 -10
- metadata +12 -27
- data/lib/active_record/connection_adapters/postgis/databases.rake +0 -19
- data/lib/active_record/connection_adapters/postgis/postgis_database_tasks.rb +0 -142
- data/lib/active_record/connection_adapters/postgis/railtie.rb +0 -13
- data/lib/active_record/connection_adapters/postgis/setup.rb +0 -19
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 88b08c026151d4f1a930e5fc3299bbf1898a20df441f86b57cde0aabcd29b4cb
         | 
| 4 | 
            +
              data.tar.gz: 823b5b9511687fa663273242d5cce9d490610b813df495ad81b43c241c3b443e
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: f851b74ce6e9da1a4aac3bfcf8acbda44e563f049de04eaf832a8b49cf2acc41cf98495a9ff123786d9bd871658d97637453ae6d845e55f0bf4f5074db01eab7
         | 
| 7 | 
            +
              data.tar.gz: 7e47c25711cf8ee49c62a8ad89f9d0b0e5525bf4fb1b45ddb185db6477d0e114a4868a50c612e9a51e880499213cb6cb82f051adf993618eb0978cc0d0f45dc7
         | 
| @@ -10,7 +10,11 @@ module ActiveRecord  # :nodoc: | |
| 10 10 | 
             
              module ConnectionHandling  # :nodoc:
         | 
| 11 11 | 
             
                if RUBY_ENGINE == "jruby"
         | 
| 12 12 |  | 
| 13 | 
            +
                  # modified from https://github.com/jruby/activerecord-jdbc-adapter/blob/master/lib/arjdbc/postgresql/connection_methods.rb#L3
         | 
| 13 14 | 
             
                  def postgis_connection(config)
         | 
| 15 | 
            +
                    config = config.deep_dup
         | 
| 16 | 
            +
                    config = symbolize_keys_if_necessary(config)
         | 
| 17 | 
            +
             | 
| 14 18 | 
             
                    config[:adapter_class] = ConnectionAdapters::PostGISAdapter
         | 
| 15 19 | 
             
                    postgresql_connection(config)
         | 
| 16 20 | 
             
                  end
         | 
| @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module ActiveRecord
         | 
| 4 | 
            +
              module ConnectionAdapters # :nodoc:
         | 
| 5 | 
            +
                module PostGIS
         | 
| 6 | 
            +
                  module DatabaseStatements
         | 
| 7 | 
            +
                    def truncate_tables(*table_names)
         | 
| 8 | 
            +
                      table_names -= ["spatial_ref_sys"]
         | 
| 9 | 
            +
                      super(*table_names)
         | 
| 10 | 
            +
                    end
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
            end
         | 
| @@ -4,16 +4,17 @@ module ActiveRecord | |
| 4 4 | 
             
              module ConnectionAdapters
         | 
| 5 5 | 
             
                module PostGIS
         | 
| 6 6 | 
             
                  module OID
         | 
| 7 | 
            +
                    # OID used to represent geometry/geography database types and attributes.
         | 
| 8 | 
            +
                    #
         | 
| 9 | 
            +
                    # Accepts `geo_type`, `srid`, `has_z`, `has_m`, and `geographic` as parameters.
         | 
| 10 | 
            +
                    # Responsible for parsing sql_types returned from the database and WKT features.
         | 
| 7 11 | 
             
                    class Spatial < Type::Value
         | 
| 8 | 
            -
                       | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
                      def initialize(oid, sql_type)
         | 
| 15 | 
            -
                        @sql_type = sql_type
         | 
| 16 | 
            -
                        @geo_type, @srid, @has_z, @has_m = self.class.parse_sql_type(sql_type)
         | 
| 12 | 
            +
                      def initialize(geo_type: "geometry", srid: 0, has_z: false, has_m: false, geographic: false)
         | 
| 13 | 
            +
                        @geo_type = geo_type
         | 
| 14 | 
            +
                        @srid = srid
         | 
| 15 | 
            +
                        @has_z = has_z
         | 
| 16 | 
            +
                        @has_m = has_m
         | 
| 17 | 
            +
                        @geographic = geographic
         | 
| 17 18 | 
             
                      end
         | 
| 18 19 |  | 
| 19 20 | 
             
                      # sql_type: geometry, geometry(Point), geometry(Point,4326), ...
         | 
| @@ -43,7 +44,9 @@ module ActiveRecord | |
| 43 44 | 
             
                          # otherType(a,b)
         | 
| 44 45 | 
             
                          geo_type = sql_type
         | 
| 45 46 | 
             
                        end
         | 
| 46 | 
            -
                         | 
| 47 | 
            +
                        geographic = sql_type.match?(/geography/)
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                        [geo_type, srid, has_z, has_m, geographic]
         | 
| 47 50 | 
             
                      end
         | 
| 48 51 |  | 
| 49 52 | 
             
                      def spatial_factory
         | 
| @@ -53,16 +56,12 @@ module ActiveRecord | |
| 53 56 | 
             
                          )
         | 
| 54 57 | 
             
                      end
         | 
| 55 58 |  | 
| 56 | 
            -
                      def geographic?
         | 
| 57 | 
            -
                        @sql_type =~ /geography/
         | 
| 58 | 
            -
                      end
         | 
| 59 | 
            -
             | 
| 60 59 | 
             
                      def spatial?
         | 
| 61 60 | 
             
                        true
         | 
| 62 61 | 
             
                      end
         | 
| 63 62 |  | 
| 64 63 | 
             
                      def type
         | 
| 65 | 
            -
                        geographic | 
| 64 | 
            +
                        @geographic ? :geography : :geometry
         | 
| 66 65 | 
             
                      end
         | 
| 67 66 |  | 
| 68 67 | 
             
                      # support setting an RGeo object or a WKT string
         | 
| @@ -83,26 +83,6 @@ module ActiveRecord | |
| 83 83 | 
             
                      @spatial_column_info ||= {}
         | 
| 84 84 | 
             
                      @spatial_column_info[table_name.to_sym] ||= SpatialColumnInfo.new(self, table_name.to_s)
         | 
| 85 85 | 
             
                    end
         | 
| 86 | 
            -
             | 
| 87 | 
            -
                    def initialize_type_map(map = type_map)
         | 
| 88 | 
            -
                      %w(
         | 
| 89 | 
            -
                        geography
         | 
| 90 | 
            -
                        geometry
         | 
| 91 | 
            -
                        geometry_collection
         | 
| 92 | 
            -
                        line_string
         | 
| 93 | 
            -
                        multi_line_string
         | 
| 94 | 
            -
                        multi_point
         | 
| 95 | 
            -
                        multi_polygon
         | 
| 96 | 
            -
                        st_point
         | 
| 97 | 
            -
                        st_polygon
         | 
| 98 | 
            -
                      ).each do |geo_type|
         | 
| 99 | 
            -
                        map.register_type(geo_type) do |oid, _, sql_type|
         | 
| 100 | 
            -
                          OID::Spatial.new(oid, sql_type)
         | 
| 101 | 
            -
                        end
         | 
| 102 | 
            -
                      end
         | 
| 103 | 
            -
             | 
| 104 | 
            -
                      super
         | 
| 105 | 
            -
                    end
         | 
| 106 86 | 
             
                  end
         | 
| 107 87 | 
             
                end
         | 
| 108 88 | 
             
              end
         | 
| @@ -32,13 +32,11 @@ module ActiveRecord  # :nodoc: | |
| 32 32 | 
             
                      end
         | 
| 33 33 | 
             
                      super(name, default, sql_type_metadata, null, default_function,
         | 
| 34 34 | 
             
                            collation: collation, comment: comment, serial: serial)
         | 
| 35 | 
            -
                      if spatial?
         | 
| 36 | 
            -
                         | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
                          @limit[:geographic] = true if @geographic
         | 
| 41 | 
            -
                        end
         | 
| 35 | 
            +
                      if spatial? && @srid
         | 
| 36 | 
            +
                        @limit = { srid: @srid, type: to_type_name(geometric_type) }
         | 
| 37 | 
            +
                        @limit[:has_z] = true if @has_z
         | 
| 38 | 
            +
                        @limit[:has_m] = true if @has_m
         | 
| 39 | 
            +
                        @limit[:geographic] = true if @geographic
         | 
| 42 40 | 
             
                      end
         | 
| 43 41 | 
             
                    end
         | 
| 44 42 |  | 
| @@ -67,15 +65,16 @@ module ActiveRecord  # :nodoc: | |
| 67 65 | 
             
                    end
         | 
| 68 66 |  | 
| 69 67 | 
             
                    def build_from_sql_type(sql_type)
         | 
| 70 | 
            -
                      geo_type, @srid, @has_z, @has_m = OID::Spatial.parse_sql_type(sql_type)
         | 
| 68 | 
            +
                      geo_type, @srid, @has_z, @has_m, @geographic = OID::Spatial.parse_sql_type(sql_type)
         | 
| 71 69 | 
             
                      set_geometric_type_from_name(geo_type)
         | 
| 72 70 | 
             
                    end
         | 
| 73 71 |  | 
| 74 72 | 
             
                    def to_type_name(geometric_type)
         | 
| 75 73 | 
             
                      name = geometric_type.type_name.underscore
         | 
| 76 | 
            -
                       | 
| 74 | 
            +
                      case name
         | 
| 75 | 
            +
                      when "point"
         | 
| 77 76 | 
             
                        "st_point"
         | 
| 78 | 
            -
                       | 
| 77 | 
            +
                      when "polygon"
         | 
| 79 78 | 
             
                        "st_polygon"
         | 
| 80 79 | 
             
                      else
         | 
| 81 80 | 
             
                        name
         | 
| @@ -21,7 +21,7 @@ module ActiveRecord  # :nodoc: | |
| 21 21 | 
             
                        dimension = row[1].to_i
         | 
| 22 22 | 
             
                        has_m = !!(type =~ /m$/i)
         | 
| 23 23 | 
             
                        type.sub!(/m$/, "")
         | 
| 24 | 
            -
                        has_z = dimension > 3 || dimension == 3 && !has_m
         | 
| 24 | 
            +
                        has_z = dimension > 3 || (dimension == 3 && !has_m)
         | 
| 25 25 | 
             
                        result[name] = {
         | 
| 26 26 | 
             
                          dimension: dimension,
         | 
| 27 27 | 
             
                          has_m:     has_m,
         | 
| @@ -9,8 +9,8 @@ module ActiveRecord  # :nodoc: | |
| 9 9 | 
             
                    # super: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
         | 
| 10 10 | 
             
                    def new_column_definition(name, type, **options)
         | 
| 11 11 | 
             
                      if (info = PostGISAdapter.spatial_column_options(type.to_sym))
         | 
| 12 | 
            -
                        if (limit = options.delete(:limit))
         | 
| 13 | 
            -
                          options.merge!(limit) | 
| 12 | 
            +
                        if (limit = options.delete(:limit)) && limit.is_a?(::Hash)
         | 
| 13 | 
            +
                          options.merge!(limit)
         | 
| 14 14 | 
             
                        end
         | 
| 15 15 |  | 
| 16 16 | 
             
                        geo_type = ColumnDefinitionUtils.geo_type(options[:type] || type || info[:type])
         | 
| @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module ActiveRecord
         | 
| 4 | 
            +
              module ConnectionAdapters
         | 
| 5 | 
            +
                module PostGIS
         | 
| 6 | 
            +
                  module Type
         | 
| 7 | 
            +
                    # Look for :postgis types first, then check for :postgresql
         | 
| 8 | 
            +
                    # types to simulate a kind of Type inheritance.
         | 
| 9 | 
            +
                    def lookup(*args, adapter: current_adapter_name, **kwargs)
         | 
| 10 | 
            +
                      super(*args, adapter: adapter, **kwargs)
         | 
| 11 | 
            +
                    rescue ArgumentError => e
         | 
| 12 | 
            +
                      raise e unless current_adapter_name == :postgis
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                      super(*args, adapter: :postgresql, **kwargs)
         | 
| 15 | 
            +
                    end
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              # Type uses `class << self` syntax so we have to prepend to the singleton_class
         | 
| 21 | 
            +
              Type.singleton_class.prepend(ActiveRecord::ConnectionAdapters::PostGIS::Type)
         | 
| 22 | 
            +
            end
         | 
| @@ -12,27 +12,20 @@ require "active_record/connection_adapters/postgresql_adapter" | |
| 12 12 | 
             
            require "active_record/connection_adapters/postgis/version"
         | 
| 13 13 | 
             
            require "active_record/connection_adapters/postgis/column_methods"
         | 
| 14 14 | 
             
            require "active_record/connection_adapters/postgis/schema_statements"
         | 
| 15 | 
            +
            require "active_record/connection_adapters/postgis/database_statements"
         | 
| 15 16 | 
             
            require "active_record/connection_adapters/postgis/spatial_column_info"
         | 
| 16 17 | 
             
            require "active_record/connection_adapters/postgis/spatial_table_definition"
         | 
| 17 18 | 
             
            require "active_record/connection_adapters/postgis/spatial_column"
         | 
| 18 19 | 
             
            require "active_record/connection_adapters/postgis/arel_tosql"
         | 
| 19 | 
            -
            require "active_record/connection_adapters/postgis/setup"
         | 
| 20 20 | 
             
            require "active_record/connection_adapters/postgis/oid/spatial"
         | 
| 21 | 
            +
            require "active_record/connection_adapters/postgis/type" # has to be after oid/*
         | 
| 21 22 | 
             
            require "active_record/connection_adapters/postgis/create_connection"
         | 
| 22 | 
            -
            require "active_record/connection_adapters/postgis/postgis_database_tasks"
         | 
| 23 | 
            -
             | 
| 24 | 
            -
            ActiveRecord::ConnectionAdapters::PostGIS.initial_setup
         | 
| 25 | 
            -
             | 
| 26 | 
            -
            if defined?(Rails::Railtie)
         | 
| 27 | 
            -
              require "active_record/connection_adapters/postgis/railtie"
         | 
| 28 | 
            -
            end
         | 
| 29 | 
            -
             | 
| 30 23 | 
             
            # :startdoc:
         | 
| 31 24 |  | 
| 32 25 | 
             
            module ActiveRecord
         | 
| 33 26 | 
             
              module ConnectionAdapters
         | 
| 34 27 | 
             
                class PostGISAdapter < PostgreSQLAdapter
         | 
| 35 | 
            -
                  ADAPTER_NAME = 'PostGIS' | 
| 28 | 
            +
                  ADAPTER_NAME = 'PostGIS'
         | 
| 36 29 |  | 
| 37 30 | 
             
                  SPATIAL_COLUMN_OPTIONS =
         | 
| 38 31 | 
             
                    {
         | 
| @@ -52,6 +45,7 @@ module ActiveRecord | |
| 52 45 | 
             
                  DEFAULT_SRID = 0
         | 
| 53 46 |  | 
| 54 47 | 
             
                  include PostGIS::SchemaStatements
         | 
| 48 | 
            +
                  include PostGIS::DatabaseStatements
         | 
| 55 49 |  | 
| 56 50 | 
             
                  def arel_visitor # :nodoc:
         | 
| 57 51 | 
             
                    Arel::Visitors::PostGIS.new(self)
         | 
| @@ -69,6 +63,35 @@ module ActiveRecord | |
| 69 63 | 
             
                    DEFAULT_SRID
         | 
| 70 64 | 
             
                  end
         | 
| 71 65 |  | 
| 66 | 
            +
                  class << self
         | 
| 67 | 
            +
                    def initialize_type_map(map = type_map)
         | 
| 68 | 
            +
                      %w[
         | 
| 69 | 
            +
                        geography
         | 
| 70 | 
            +
                        geometry
         | 
| 71 | 
            +
                        geometry_collection
         | 
| 72 | 
            +
                        line_string
         | 
| 73 | 
            +
                        multi_line_string
         | 
| 74 | 
            +
                        multi_point
         | 
| 75 | 
            +
                        multi_polygon
         | 
| 76 | 
            +
                        st_point
         | 
| 77 | 
            +
                        st_polygon
         | 
| 78 | 
            +
                      ].each do |geo_type|
         | 
| 79 | 
            +
                        map.register_type(geo_type) do |_, _, sql_type|
         | 
| 80 | 
            +
                          # sql_type is a string that comes from the database definition
         | 
| 81 | 
            +
                          # examples:
         | 
| 82 | 
            +
                          #   "geometry(Point,4326)"
         | 
| 83 | 
            +
                          #   "geography(Point,4326)"
         | 
| 84 | 
            +
                          #   "geometry(Polygon,4326) NOT NULL"
         | 
| 85 | 
            +
                          #   "geometry(Geography,4326)"
         | 
| 86 | 
            +
                          geo_type, srid, has_z, has_m, geographic = PostGIS::OID::Spatial.parse_sql_type(sql_type)
         | 
| 87 | 
            +
                          PostGIS::OID::Spatial.new(geo_type: geo_type, srid: srid, has_z: has_z, has_m: has_m, geographic: geographic)
         | 
| 88 | 
            +
                        end
         | 
| 89 | 
            +
                      end
         | 
| 90 | 
            +
             | 
| 91 | 
            +
                      super
         | 
| 92 | 
            +
                    end
         | 
| 93 | 
            +
                  end
         | 
| 94 | 
            +
             | 
| 72 95 | 
             
                  def srs_database_columns
         | 
| 73 96 | 
             
                    {
         | 
| 74 97 | 
             
                      auth_name_column: "auth_name",
         | 
| @@ -87,6 +110,57 @@ module ActiveRecord | |
| 87 110 | 
             
                      super
         | 
| 88 111 | 
             
                    end
         | 
| 89 112 | 
             
                  end
         | 
| 113 | 
            +
             | 
| 114 | 
            +
                  def quote_default_expression(value, column)
         | 
| 115 | 
            +
                    if column.type == :geography || column.type == :geometry
         | 
| 116 | 
            +
                      quote(value)
         | 
| 117 | 
            +
                    else
         | 
| 118 | 
            +
                      super
         | 
| 119 | 
            +
                    end
         | 
| 120 | 
            +
                  end
         | 
| 121 | 
            +
             | 
| 122 | 
            +
                  # PostGIS specific types
         | 
| 123 | 
            +
                  [
         | 
| 124 | 
            +
                    :geography,
         | 
| 125 | 
            +
                    :geometry,
         | 
| 126 | 
            +
                    :geometry_collection,
         | 
| 127 | 
            +
                    :line_string,
         | 
| 128 | 
            +
                    :multi_line_string,
         | 
| 129 | 
            +
                    :multi_point,
         | 
| 130 | 
            +
                    :multi_polygon,
         | 
| 131 | 
            +
                    :st_point,
         | 
| 132 | 
            +
                    :st_polygon,
         | 
| 133 | 
            +
                  ].each do |geo_type|
         | 
| 134 | 
            +
                    ActiveRecord::Type.register(geo_type, PostGIS::OID::Spatial, adapter: :postgis)
         | 
| 135 | 
            +
                  end
         | 
| 90 136 | 
             
                end
         | 
| 91 137 | 
             
              end
         | 
| 138 | 
            +
              SchemaDumper.ignore_tables |= %w[
         | 
| 139 | 
            +
                geography_columns
         | 
| 140 | 
            +
                geometry_columns
         | 
| 141 | 
            +
                layer
         | 
| 142 | 
            +
                raster_columns
         | 
| 143 | 
            +
                raster_overviews
         | 
| 144 | 
            +
                spatial_ref_sys
         | 
| 145 | 
            +
                topology
         | 
| 146 | 
            +
              ]
         | 
| 147 | 
            +
              Tasks::DatabaseTasks.register_task(/postgis/, "ActiveRecord::Tasks::PostgreSQLDatabaseTasks")
         | 
| 148 | 
            +
            end
         | 
| 149 | 
            +
             | 
| 150 | 
            +
            # if using JRUBY, create ArJdbc::PostGIS module
         | 
| 151 | 
            +
            # and prepend it to the PostgreSQL adapter since
         | 
| 152 | 
            +
            # it is the default adapter_spec.
         | 
| 153 | 
            +
            # see: https://github.com/jruby/activerecord-jdbc-adapter/blob/master/lib/arjdbc/postgresql/adapter.rb#27
         | 
| 154 | 
            +
            if RUBY_ENGINE == "jruby"
         | 
| 155 | 
            +
              module ArJdbc
         | 
| 156 | 
            +
                module PostGIS
         | 
| 157 | 
            +
                  ADAPTER_NAME = 'PostGIS'
         | 
| 158 | 
            +
             | 
| 159 | 
            +
                  def adapter_name
         | 
| 160 | 
            +
                    ADAPTER_NAME
         | 
| 161 | 
            +
                  end
         | 
| 162 | 
            +
                end
         | 
| 163 | 
            +
              end
         | 
| 164 | 
            +
             | 
| 165 | 
            +
              ArJdbc::PostgreSQL.prepend(ArJdbc::PostGIS)
         | 
| 92 166 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: activerecord-postgis-adapter
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version:  | 
| 4 | 
            +
              version: 8.0.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Daniel Azuma
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date:  | 
| 12 | 
            +
            date: 2022-01-03 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: activerecord
         | 
| @@ -17,14 +17,14 @@ dependencies: | |
| 17 17 | 
             
                requirements:
         | 
| 18 18 | 
             
                - - "~>"
         | 
| 19 19 | 
             
                  - !ruby/object:Gem::Version
         | 
| 20 | 
            -
                    version:  | 
| 20 | 
            +
                    version: 7.0.0
         | 
| 21 21 | 
             
              type: :runtime
         | 
| 22 22 | 
             
              prerelease: false
         | 
| 23 23 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 24 24 | 
             
                requirements:
         | 
| 25 25 | 
             
                - - "~>"
         | 
| 26 26 | 
             
                  - !ruby/object:Gem::Version
         | 
| 27 | 
            -
                    version:  | 
| 27 | 
            +
                    version: 7.0.0
         | 
| 28 28 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 29 29 | 
             
              name: rgeo-activerecord
         | 
| 30 30 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -45,14 +45,14 @@ dependencies: | |
| 45 45 | 
             
                requirements:
         | 
| 46 46 | 
             
                - - "~>"
         | 
| 47 47 | 
             
                  - !ruby/object:Gem::Version
         | 
| 48 | 
            -
                    version: ' | 
| 48 | 
            +
                    version: '13.0'
         | 
| 49 49 | 
             
              type: :development
         | 
| 50 50 | 
             
              prerelease: false
         | 
| 51 51 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 52 52 | 
             
                requirements:
         | 
| 53 53 | 
             
                - - "~>"
         | 
| 54 54 | 
             
                  - !ruby/object:Gem::Version
         | 
| 55 | 
            -
                    version: ' | 
| 55 | 
            +
                    version: '13.0'
         | 
| 56 56 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 57 57 | 
             
              name: minitest
         | 
| 58 58 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -81,20 +81,6 @@ dependencies: | |
| 81 81 | 
             
                - - "~>"
         | 
| 82 82 | 
             
                  - !ruby/object:Gem::Version
         | 
| 83 83 | 
             
                    version: '1.1'
         | 
| 84 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 85 | 
            -
              name: appraisal
         | 
| 86 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 87 | 
            -
                requirements:
         | 
| 88 | 
            -
                - - "~>"
         | 
| 89 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 90 | 
            -
                    version: '2.0'
         | 
| 91 | 
            -
              type: :development
         | 
| 92 | 
            -
              prerelease: false
         | 
| 93 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 94 | 
            -
                requirements:
         | 
| 95 | 
            -
                - - "~>"
         | 
| 96 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 97 | 
            -
                    version: '2.0'
         | 
| 98 84 | 
             
            description: ActiveRecord connection adapter for PostGIS. It is based on the stock
         | 
| 99 85 | 
             
              PostgreSQL adapter, and adds built-in support for the spatial extensions provided
         | 
| 100 86 | 
             
              by PostGIS. It uses the RGeo library to represent spatial data in Ruby.
         | 
| @@ -110,22 +96,21 @@ files: | |
| 110 96 | 
             
            - lib/active_record/connection_adapters/postgis/arel_tosql.rb
         | 
| 111 97 | 
             
            - lib/active_record/connection_adapters/postgis/column_methods.rb
         | 
| 112 98 | 
             
            - lib/active_record/connection_adapters/postgis/create_connection.rb
         | 
| 113 | 
            -
            - lib/active_record/connection_adapters/postgis/ | 
| 99 | 
            +
            - lib/active_record/connection_adapters/postgis/database_statements.rb
         | 
| 114 100 | 
             
            - lib/active_record/connection_adapters/postgis/oid/spatial.rb
         | 
| 115 | 
            -
            - lib/active_record/connection_adapters/postgis/postgis_database_tasks.rb
         | 
| 116 | 
            -
            - lib/active_record/connection_adapters/postgis/railtie.rb
         | 
| 117 101 | 
             
            - lib/active_record/connection_adapters/postgis/schema_statements.rb
         | 
| 118 | 
            -
            - lib/active_record/connection_adapters/postgis/setup.rb
         | 
| 119 102 | 
             
            - lib/active_record/connection_adapters/postgis/spatial_column.rb
         | 
| 120 103 | 
             
            - lib/active_record/connection_adapters/postgis/spatial_column_info.rb
         | 
| 121 104 | 
             
            - lib/active_record/connection_adapters/postgis/spatial_table_definition.rb
         | 
| 105 | 
            +
            - lib/active_record/connection_adapters/postgis/type.rb
         | 
| 122 106 | 
             
            - lib/active_record/connection_adapters/postgis/version.rb
         | 
| 123 107 | 
             
            - lib/active_record/connection_adapters/postgis_adapter.rb
         | 
| 124 108 | 
             
            - lib/activerecord-postgis-adapter.rb
         | 
| 125 109 | 
             
            homepage: http://github.com/rgeo/activerecord-postgis-adapter
         | 
| 126 110 | 
             
            licenses:
         | 
| 127 111 | 
             
            - BSD-3-Clause
         | 
| 128 | 
            -
            metadata: | 
| 112 | 
            +
            metadata:
         | 
| 113 | 
            +
              rubygems_mfa_required: 'true'
         | 
| 129 114 | 
             
            post_install_message: 
         | 
| 130 115 | 
             
            rdoc_options: []
         | 
| 131 116 | 
             
            require_paths:
         | 
| @@ -134,14 +119,14 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 134 119 | 
             
              requirements:
         | 
| 135 120 | 
             
              - - ">="
         | 
| 136 121 | 
             
                - !ruby/object:Gem::Version
         | 
| 137 | 
            -
                  version: 2. | 
| 122 | 
            +
                  version: 2.7.0
         | 
| 138 123 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 139 124 | 
             
              requirements:
         | 
| 140 125 | 
             
              - - ">="
         | 
| 141 126 | 
             
                - !ruby/object:Gem::Version
         | 
| 142 127 | 
             
                  version: '0'
         | 
| 143 128 | 
             
            requirements: []
         | 
| 144 | 
            -
            rubygems_version: 3. | 
| 129 | 
            +
            rubygems_version: 3.1.4
         | 
| 145 130 | 
             
            signing_key: 
         | 
| 146 131 | 
             
            specification_version: 4
         | 
| 147 132 | 
             
            summary: ActiveRecord adapter for PostGIS, based on RGeo.
         | 
| @@ -1,19 +0,0 @@ | |
| 1 | 
            -
            # frozen_string_literal: true
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            namespace :db do
         | 
| 4 | 
            -
              namespace :gis do
         | 
| 5 | 
            -
                desc "Setup PostGIS data in the database"
         | 
| 6 | 
            -
                task setup: [:load_config] do
         | 
| 7 | 
            -
                  environments = [Rails.env]
         | 
| 8 | 
            -
                  environments << "test" if Rails.env.development?
         | 
| 9 | 
            -
                  environments.each do |environment|
         | 
| 10 | 
            -
                    ActiveRecord::Base.configurations
         | 
| 11 | 
            -
                      .configs_for(env_name: environment)
         | 
| 12 | 
            -
                      .reject { |env| env.config["database"].blank? }
         | 
| 13 | 
            -
                      .each do |env|
         | 
| 14 | 
            -
                        ActiveRecord::ConnectionAdapters::PostGIS::PostGISDatabaseTasks.new(env.config).setup_gis
         | 
| 15 | 
            -
                      end
         | 
| 16 | 
            -
                  end
         | 
| 17 | 
            -
                end
         | 
| 18 | 
            -
              end
         | 
| 19 | 
            -
            end
         | 
| @@ -1,142 +0,0 @@ | |
| 1 | 
            -
            # frozen_string_literal: true
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            module ActiveRecord  # :nodoc:
         | 
| 4 | 
            -
              module ConnectionAdapters  # :nodoc:
         | 
| 5 | 
            -
                module PostGIS  # :nodoc:
         | 
| 6 | 
            -
                  class PostGISDatabaseTasks < ::ActiveRecord::Tasks::PostgreSQLDatabaseTasks  # :nodoc:
         | 
| 7 | 
            -
                    def initialize(db_config)
         | 
| 8 | 
            -
                      super
         | 
| 9 | 
            -
                      ensure_installation_configs
         | 
| 10 | 
            -
                    end
         | 
| 11 | 
            -
             | 
| 12 | 
            -
                    def setup_gis
         | 
| 13 | 
            -
                      establish_su_connection
         | 
| 14 | 
            -
                      if extension_names
         | 
| 15 | 
            -
                        setup_gis_from_extension
         | 
| 16 | 
            -
                      end
         | 
| 17 | 
            -
                      establish_connection(db_config)
         | 
| 18 | 
            -
                    end
         | 
| 19 | 
            -
             | 
| 20 | 
            -
                    # Override to set the database owner and call setup_gis
         | 
| 21 | 
            -
                    def create(master_established = false)
         | 
| 22 | 
            -
                      establish_master_connection unless master_established
         | 
| 23 | 
            -
                      extra_configs = { encoding: encoding }
         | 
| 24 | 
            -
                      extra_configs[:owner] = username if has_su?
         | 
| 25 | 
            -
                      connection.create_database(db_config.database, configuration_hash.merge(extra_configs))
         | 
| 26 | 
            -
                      setup_gis
         | 
| 27 | 
            -
                    rescue ::ActiveRecord::StatementInvalid => error
         | 
| 28 | 
            -
                      if /database .* already exists/ === error.message
         | 
| 29 | 
            -
                        raise ::ActiveRecord::DatabaseAlreadyExists
         | 
| 30 | 
            -
                      else
         | 
| 31 | 
            -
                        raise
         | 
| 32 | 
            -
                      end
         | 
| 33 | 
            -
                    end
         | 
| 34 | 
            -
             | 
| 35 | 
            -
                    private
         | 
| 36 | 
            -
             | 
| 37 | 
            -
                    # Override to use su_username and su_password
         | 
| 38 | 
            -
                    def establish_master_connection
         | 
| 39 | 
            -
                      establish_connection(configuration_hash.merge(
         | 
| 40 | 
            -
                        database:           "postgres",
         | 
| 41 | 
            -
                        password:           su_password,
         | 
| 42 | 
            -
                        schema_search_path: "public",
         | 
| 43 | 
            -
                        username:           su_username
         | 
| 44 | 
            -
                      ))
         | 
| 45 | 
            -
                    end
         | 
| 46 | 
            -
             | 
| 47 | 
            -
                    def establish_su_connection
         | 
| 48 | 
            -
                      establish_connection(configuration_hash.merge(
         | 
| 49 | 
            -
                        password:           su_password,
         | 
| 50 | 
            -
                        schema_search_path: "public",
         | 
| 51 | 
            -
                        username:           su_username
         | 
| 52 | 
            -
                      ))
         | 
| 53 | 
            -
                    end
         | 
| 54 | 
            -
             | 
| 55 | 
            -
                    def username
         | 
| 56 | 
            -
                      @username ||= configuration_hash[:username]
         | 
| 57 | 
            -
                    end
         | 
| 58 | 
            -
             | 
| 59 | 
            -
                    def quoted_username
         | 
| 60 | 
            -
                      @quoted_username ||= ::ActiveRecord::Base.connection.quote_column_name(username)
         | 
| 61 | 
            -
                    end
         | 
| 62 | 
            -
             | 
| 63 | 
            -
                    def password
         | 
| 64 | 
            -
                      @password ||= configuration_hash[:password]
         | 
| 65 | 
            -
                    end
         | 
| 66 | 
            -
             | 
| 67 | 
            -
                    def su_username
         | 
| 68 | 
            -
                      @su_username ||= configuration_hash.fetch(:su_username, username)
         | 
| 69 | 
            -
                    end
         | 
| 70 | 
            -
             | 
| 71 | 
            -
                    def su_password
         | 
| 72 | 
            -
                      @su_password ||= configuration_hash.fetch(:su_password, password)
         | 
| 73 | 
            -
                    end
         | 
| 74 | 
            -
             | 
| 75 | 
            -
                    def has_su?
         | 
| 76 | 
            -
                      return @has_su if defined?(@has_su)
         | 
| 77 | 
            -
             | 
| 78 | 
            -
                      @has_su = configuration_hash.include?(:su_username)
         | 
| 79 | 
            -
                    end
         | 
| 80 | 
            -
             | 
| 81 | 
            -
                    def search_path
         | 
| 82 | 
            -
                      @search_path ||= configuration_hash[:schema_search_path].to_s.strip.split(",").map(&:strip)
         | 
| 83 | 
            -
                    end
         | 
| 84 | 
            -
             | 
| 85 | 
            -
                    def extension_names
         | 
| 86 | 
            -
                      @extension_names ||= begin
         | 
| 87 | 
            -
                        extensions = configuration_hash[:postgis_extension]
         | 
| 88 | 
            -
                        case extensions
         | 
| 89 | 
            -
                        when ::String
         | 
| 90 | 
            -
                          extensions.split(",")
         | 
| 91 | 
            -
                        when ::Array
         | 
| 92 | 
            -
                          extensions
         | 
| 93 | 
            -
                        else
         | 
| 94 | 
            -
                          ["postgis"]
         | 
| 95 | 
            -
                        end
         | 
| 96 | 
            -
                      end
         | 
| 97 | 
            -
                    end
         | 
| 98 | 
            -
             | 
| 99 | 
            -
                    def ensure_installation_configs
         | 
| 100 | 
            -
                      if configuration_hash[:setup] == "default" && !configuration_hash[:postgis_extension]
         | 
| 101 | 
            -
                        share_dir = `pg_config --sharedir`.strip rescue "/usr/share"
         | 
| 102 | 
            -
                        control_file = ::File.expand_path("extension/postgis.control", share_dir)
         | 
| 103 | 
            -
                        if ::File.readable?(control_file)
         | 
| 104 | 
            -
                          @configuration_hash = configuration_hash.merge(postgis_extension: "postgis").freeze
         | 
| 105 | 
            -
                        end
         | 
| 106 | 
            -
                      end
         | 
| 107 | 
            -
                    end
         | 
| 108 | 
            -
             | 
| 109 | 
            -
                    def setup_gis_from_extension
         | 
| 110 | 
            -
                      extension_names.each do |extname|
         | 
| 111 | 
            -
                        if extname == "postgis_topology"
         | 
| 112 | 
            -
                          unless search_path.include?("topology")
         | 
| 113 | 
            -
                            raise ArgumentError, "'topology' must be in schema_search_path for postgis_topology"
         | 
| 114 | 
            -
                          end
         | 
| 115 | 
            -
                          connection.execute("CREATE EXTENSION IF NOT EXISTS #{extname} SCHEMA topology")
         | 
| 116 | 
            -
                        else
         | 
| 117 | 
            -
                          if (postgis_schema = configuration_hash[:postgis_schema])
         | 
| 118 | 
            -
                            schema_clause = "WITH SCHEMA #{postgis_schema}"
         | 
| 119 | 
            -
                            unless schema_exists?(postgis_schema)
         | 
| 120 | 
            -
                              connection.execute("CREATE SCHEMA #{postgis_schema}")
         | 
| 121 | 
            -
                              connection.execute("GRANT ALL ON SCHEMA #{postgis_schema} TO PUBLIC")
         | 
| 122 | 
            -
                            end
         | 
| 123 | 
            -
                          else
         | 
| 124 | 
            -
                            schema_clause = ""
         | 
| 125 | 
            -
                          end
         | 
| 126 | 
            -
             | 
| 127 | 
            -
                          connection.execute("CREATE EXTENSION IF NOT EXISTS #{extname} #{schema_clause}")
         | 
| 128 | 
            -
                        end
         | 
| 129 | 
            -
                      end
         | 
| 130 | 
            -
                    end
         | 
| 131 | 
            -
             | 
| 132 | 
            -
                    def schema_exists?(schema_name)
         | 
| 133 | 
            -
                      connection.execute(
         | 
| 134 | 
            -
                        "SELECT schema_name FROM information_schema.schemata WHERE schema_name = '#{schema_name}'"
         | 
| 135 | 
            -
                      ).any?
         | 
| 136 | 
            -
                    end
         | 
| 137 | 
            -
                  end
         | 
| 138 | 
            -
             | 
| 139 | 
            -
                  ::ActiveRecord::Tasks::DatabaseTasks.register_task(/postgis/, PostGISDatabaseTasks)
         | 
| 140 | 
            -
                end
         | 
| 141 | 
            -
              end
         | 
| 142 | 
            -
            end
         | 
| @@ -1,13 +0,0 @@ | |
| 1 | 
            -
            # frozen_string_literal: true
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            module ActiveRecord  # :nodoc:
         | 
| 4 | 
            -
              module ConnectionAdapters  # :nodoc:
         | 
| 5 | 
            -
                module PostGIS  # :nodoc:
         | 
| 6 | 
            -
                  class Railtie < ::Rails::Railtie  # :nodoc:
         | 
| 7 | 
            -
                    rake_tasks do
         | 
| 8 | 
            -
                      load "active_record/connection_adapters/postgis/databases.rake"
         | 
| 9 | 
            -
                    end
         | 
| 10 | 
            -
                  end
         | 
| 11 | 
            -
                end
         | 
| 12 | 
            -
              end
         | 
| 13 | 
            -
            end
         | 
| @@ -1,19 +0,0 @@ | |
| 1 | 
            -
            # frozen_string_literal: true
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            module ActiveRecord  # :nodoc:
         | 
| 4 | 
            -
              module ConnectionAdapters  # :nodoc:
         | 
| 5 | 
            -
                module PostGIS  # :nodoc:
         | 
| 6 | 
            -
                  def self.initial_setup
         | 
| 7 | 
            -
                    ::ActiveRecord::SchemaDumper.ignore_tables |= %w(
         | 
| 8 | 
            -
                      geography_columns
         | 
| 9 | 
            -
                      geometry_columns
         | 
| 10 | 
            -
                      layer
         | 
| 11 | 
            -
                      raster_columns
         | 
| 12 | 
            -
                      raster_overviews
         | 
| 13 | 
            -
                      spatial_ref_sys
         | 
| 14 | 
            -
                      topology
         | 
| 15 | 
            -
                    )
         | 
| 16 | 
            -
                  end
         | 
| 17 | 
            -
                end
         | 
| 18 | 
            -
              end
         | 
| 19 | 
            -
            end
         |