activerecord-postgis-adapter 7.1.1 → 8.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40546b155985259941dab5c7fef8ec7f0d4959a29087044a133c4918929d7e2f
4
- data.tar.gz: b80326260c605d158e4647caa361d07000c622140ae90e505f97a0576f2ce26a
3
+ metadata.gz: 88b08c026151d4f1a930e5fc3299bbf1898a20df441f86b57cde0aabcd29b4cb
4
+ data.tar.gz: 823b5b9511687fa663273242d5cce9d490610b813df495ad81b43c241c3b443e
5
5
  SHA512:
6
- metadata.gz: 8b3aee9a59f53669fe3e44c1f471f30f3e37f20b0a18bb920ac46535e264f573492da49c268d04a037b959517018584aa69c6fe1d9f45b211b3a55ed8d19a1d2
7
- data.tar.gz: af501e0d2e9e3cc0990c67812fa9fc1fc2202ba9f15ed5f6a69dfe4e73709ef4cc339c9846ee60a804e6f5f2a5bf754d6f4082508a1cbd17dfa3e7c9f985c5f2
6
+ metadata.gz: f851b74ce6e9da1a4aac3bfcf8acbda44e563f049de04eaf832a8b49cf2acc41cf98495a9ff123786d9bd871658d97637453ae6d845e55f0bf4f5074db01eab7
7
+ data.tar.gz: 7e47c25711cf8ee49c62a8ad89f9d0b0e5525bf4fb1b45ddb185db6477d0e114a4868a50c612e9a51e880499213cb6cb82f051adf993618eb0978cc0d0f45dc7
@@ -9,7 +9,7 @@ module ActiveRecord
9
9
  # Accepts `geo_type`, `srid`, `has_z`, `has_m`, and `geographic` as parameters.
10
10
  # Responsible for parsing sql_types returned from the database and WKT features.
11
11
  class Spatial < Type::Value
12
- def initialize(geo_type: 'geometry', srid: 0, has_z: false, has_m: false, geographic: false)
12
+ def initialize(geo_type: "geometry", srid: 0, has_z: false, has_m: false, geographic: false)
13
13
  @geo_type = geo_type
14
14
  @srid = srid
15
15
  @has_z = has_z
@@ -83,33 +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 |_, _, sql_type|
100
- # sql_type is a string that comes from the database definition
101
- # examples:
102
- # "geometry(Point,4326)"
103
- # "geography(Point,4326)"
104
- # "geometry(Polygon,4326) NOT NULL"
105
- # "geometry(Geography,4326)"
106
- geo_type, srid, has_z, has_m, geographic = OID::Spatial.parse_sql_type(sql_type)
107
- OID::Spatial.new(geo_type: geo_type, srid: srid, has_z: has_z, has_m: has_m, geographic: geographic)
108
- end
109
- end
110
-
111
- super
112
- end
113
86
  end
114
87
  end
115
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
- if @srid
37
- @limit = { srid: @srid, type: to_type_name(geometric_type) }
38
- @limit[:has_z] = true if @has_z
39
- @limit[:has_m] = true if @has_m
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
 
@@ -73,9 +71,10 @@ module ActiveRecord # :nodoc:
73
71
 
74
72
  def to_type_name(geometric_type)
75
73
  name = geometric_type.type_name.underscore
76
- if name == "point"
74
+ case name
75
+ when "point"
77
76
  "st_point"
78
- elsif name == "polygon"
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) if limit.is_a?(::Hash)
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])
@@ -3,7 +3,7 @@
3
3
  module ActiveRecord
4
4
  module ConnectionAdapters
5
5
  module PostGIS
6
- VERSION = "7.1.1"
6
+ VERSION = "8.0.0"
7
7
  end
8
8
  end
9
9
  end
@@ -17,18 +17,9 @@ require "active_record/connection_adapters/postgis/spatial_column_info"
17
17
  require "active_record/connection_adapters/postgis/spatial_table_definition"
18
18
  require "active_record/connection_adapters/postgis/spatial_column"
19
19
  require "active_record/connection_adapters/postgis/arel_tosql"
20
- require "active_record/connection_adapters/postgis/setup"
21
20
  require "active_record/connection_adapters/postgis/oid/spatial"
22
21
  require "active_record/connection_adapters/postgis/type" # has to be after oid/*
23
22
  require "active_record/connection_adapters/postgis/create_connection"
24
- require "active_record/connection_adapters/postgis/postgis_database_tasks"
25
-
26
- ActiveRecord::ConnectionAdapters::PostGIS.initial_setup
27
-
28
- if defined?(Rails::Railtie)
29
- require "active_record/connection_adapters/postgis/railtie"
30
- end
31
-
32
23
  # :startdoc:
33
24
 
34
25
  module ActiveRecord
@@ -72,6 +63,35 @@ module ActiveRecord
72
63
  DEFAULT_SRID
73
64
  end
74
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
+
75
95
  def srs_database_columns
76
96
  {
77
97
  auth_name_column: "auth_name",
@@ -115,6 +135,16 @@ module ActiveRecord
115
135
  end
116
136
  end
117
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")
118
148
  end
119
149
 
120
150
  # if using JRUBY, create ArJdbc::PostGIS module
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: 7.1.1
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: 2021-08-17 00:00:00.000000000 Z
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: '6.1'
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: '6.1'
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: '12.0'
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: '12.0'
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.
@@ -111,12 +97,8 @@ files:
111
97
  - lib/active_record/connection_adapters/postgis/column_methods.rb
112
98
  - lib/active_record/connection_adapters/postgis/create_connection.rb
113
99
  - lib/active_record/connection_adapters/postgis/database_statements.rb
114
- - lib/active_record/connection_adapters/postgis/databases.rake
115
100
  - lib/active_record/connection_adapters/postgis/oid/spatial.rb
116
- - lib/active_record/connection_adapters/postgis/postgis_database_tasks.rb
117
- - lib/active_record/connection_adapters/postgis/railtie.rb
118
101
  - lib/active_record/connection_adapters/postgis/schema_statements.rb
119
- - lib/active_record/connection_adapters/postgis/setup.rb
120
102
  - lib/active_record/connection_adapters/postgis/spatial_column.rb
121
103
  - lib/active_record/connection_adapters/postgis/spatial_column_info.rb
122
104
  - lib/active_record/connection_adapters/postgis/spatial_table_definition.rb
@@ -127,7 +109,8 @@ files:
127
109
  homepage: http://github.com/rgeo/activerecord-postgis-adapter
128
110
  licenses:
129
111
  - BSD-3-Clause
130
- metadata: {}
112
+ metadata:
113
+ rubygems_mfa_required: 'true'
131
114
  post_install_message:
132
115
  rdoc_options: []
133
116
  require_paths:
@@ -136,7 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
119
  requirements:
137
120
  - - ">="
138
121
  - !ruby/object:Gem::Version
139
- version: 2.5.0
122
+ version: 2.7.0
140
123
  required_rubygems_version: !ruby/object:Gem::Requirement
141
124
  requirements:
142
125
  - - ">="
@@ -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.configuration_hash[:database].blank? }
13
- .each do |env|
14
- ActiveRecord::ConnectionAdapters::PostGIS::PostGISDatabaseTasks.new(env).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