activerecord-postgis-adapter 6.0.3 → 7.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: 69cf59b00676a1afdd07f0f6569b267995f5a5a3587fdf52a706876d5e4a1f87
4
- data.tar.gz: d678ad7901ed89fae596ebfef4a48d2f04231a085da840c7fa2c4714f0aca534
3
+ metadata.gz: bb1e1b34ad600caf80e784c5ed95979d2712fe102d7845814d7258cec6605425
4
+ data.tar.gz: 6c9dcf403ec396a9482a9d88a02fd4282d6c9c50fbcc84d2581927f2bbf570d0
5
5
  SHA512:
6
- metadata.gz: 355f65508295569307ac86dba4970477eb6d41f1f48484bb203a61ff31b7a3ec827b9eea321441c24a83f8706ceead8c916cb833947074b2463e8ffdf0060050
7
- data.tar.gz: ea179ffdf8d4d31a0065001ae396e552732679c7048e48994ef503c8e8ff206e7aa2140f07ffe31f67be5a046f3ee679ba3e8d50e993f54a08512bf214ccceed
6
+ metadata.gz: be97e239ddd7b98c4b96616e456250c2ef624bf33517e02623d69ac1a4f94f64f46ecc1e0bf16afd5c036e36e6b3cba68f872ad261ebce44ef07a3b1661b21b5
7
+ data.tar.gz: 48d54259d8027b81ad8419bef0d66b1f73fa5145df8dd001bab340049b28c331bf7474f3614076b9de2f0626fc80a3da19cd1267519e9857b4f19d93008e416d
@@ -1,5 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ module RGeo
4
+ module ActiveRecord
5
+ ##
6
+ # Extend rgeo-activerecord visitors to use PostGIS specific functionality
7
+ module SpatialToPostGISSql
8
+ def visit_in_spatial_context(node, collector)
9
+ # Use ST_GeomFromEWKT for EWKT geometries
10
+ if node.is_a?(String) && node =~ /SRID=[\d+]{0,};/
11
+ collector << "#{st_func('ST_GeomFromEWKT')}(#{quote(node)})"
12
+ else
13
+ super(node, collector)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ RGeo::ActiveRecord::SpatialToSql.prepend RGeo::ActiveRecord::SpatialToPostGISSql
20
+
3
21
  module Arel # :nodoc:
4
22
  module Visitors # :nodoc:
5
23
  # Different super-class under JRuby JDBC adapter.
@@ -11,22 +29,6 @@ module Arel # :nodoc:
11
29
 
12
30
  class PostGIS < PostGISSuperclass # :nodoc:
13
31
  include RGeo::ActiveRecord::SpatialToSql
14
-
15
- FUNC_MAP = {
16
- "st_wkttosql" => "ST_GeomFromEWKT",
17
- }
18
-
19
- def st_func(standard_name)
20
- FUNC_MAP[standard_name.downcase] || standard_name
21
- end
22
-
23
- def visit_String(node, collector)
24
- collector << "#{st_func('ST_WKTToSQL')}(#{quote(node)})"
25
- end
26
-
27
- def visit_RGeo_ActiveRecord_SpatialNamedFunction(node, collector)
28
- aggregate(st_func(node.name), node, collector)
29
- end
30
32
  end
31
33
  end
32
34
  end
@@ -23,9 +23,7 @@ module ActiveRecord # :nodoc:
23
23
  # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
24
24
  # FULL REPLACEMENT because we need to create a different class.
25
25
  def postgis_connection(config)
26
- conn_params = config.symbolize_keys
27
-
28
- conn_params.delete_if { |_, v| v.nil? }
26
+ conn_params = config.symbolize_keys.compact
29
27
 
30
28
  # Map ActiveRecords param names to PGs.
31
29
  conn_params[:user] = conn_params.delete(:username) if conn_params[:username]
@@ -35,14 +33,12 @@ module ActiveRecord # :nodoc:
35
33
  valid_conn_param_keys = PG::Connection.conndefaults_hash.keys + [:requiressl]
36
34
  conn_params.slice!(*valid_conn_param_keys)
37
35
 
38
- conn = PG.connect(conn_params)
39
- ConnectionAdapters::PostGISAdapter.new(conn, logger, conn_params, config)
40
- rescue ::PG::Error => error
41
- if error.message.include?(conn_params[:dbname])
42
- raise ActiveRecord::NoDatabaseError
43
- else
44
- raise
45
- end
36
+ ConnectionAdapters::PostGISAdapter.new(
37
+ ConnectionAdapters::PostGISAdapter.new_client(conn_params),
38
+ logger,
39
+ conn_params,
40
+ config
41
+ )
46
42
  end
47
43
 
48
44
  end
@@ -49,11 +49,7 @@ module ActiveRecord
49
49
  def spatial_factory
50
50
  @spatial_factory ||=
51
51
  RGeo::ActiveRecord::SpatialFactoryStore.instance.factory(
52
- geo_type: @geo_type,
53
- has_m: @has_m,
54
- has_z: @has_z,
55
- sql_type: @sql_type,
56
- srid: @srid
52
+ factory_attrs
57
53
  )
58
54
  end
59
55
 
@@ -107,6 +103,16 @@ module ActiveRecord
107
103
  RGeo::WKRep::WKTParser.new(spatial_factory, support_ewkt: true, default_srid: @srid)
108
104
  end
109
105
  end
106
+
107
+ def factory_attrs
108
+ {
109
+ geo_type: @geo_type.underscore,
110
+ has_m: @has_m,
111
+ has_z: @has_z,
112
+ srid: @srid,
113
+ sql_type: type.to_s
114
+ }
115
+ end
110
116
  end
111
117
  end
112
118
  end
@@ -4,7 +4,7 @@ module ActiveRecord # :nodoc:
4
4
  module ConnectionAdapters # :nodoc:
5
5
  module PostGIS # :nodoc:
6
6
  class PostGISDatabaseTasks < ::ActiveRecord::Tasks::PostgreSQLDatabaseTasks # :nodoc:
7
- def initialize(config)
7
+ def initialize(db_config)
8
8
  super
9
9
  ensure_installation_configs
10
10
  end
@@ -14,19 +14,19 @@ module ActiveRecord # :nodoc:
14
14
  if extension_names
15
15
  setup_gis_from_extension
16
16
  end
17
- establish_connection(configuration)
17
+ establish_connection(db_config)
18
18
  end
19
19
 
20
20
  # Override to set the database owner and call setup_gis
21
21
  def create(master_established = false)
22
22
  establish_master_connection unless master_established
23
- extra_configs = { "encoding" => encoding }
24
- extra_configs["owner"] = username if has_su?
25
- connection.create_database(configuration["database"], configuration.merge(extra_configs))
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
26
  setup_gis
27
27
  rescue ::ActiveRecord::StatementInvalid => error
28
28
  if /database .* already exists/ === error.message
29
- raise ::ActiveRecord::Tasks::DatabaseAlreadyExists
29
+ raise ::ActiveRecord::DatabaseAlreadyExists
30
30
  else
31
31
  raise
32
32
  end
@@ -36,24 +36,24 @@ module ActiveRecord # :nodoc:
36
36
 
37
37
  # Override to use su_username and su_password
38
38
  def establish_master_connection
39
- establish_connection(configuration.merge(
40
- "database" => "postgres",
41
- "password" => su_password,
42
- "schema_search_path" => "public",
43
- "username" => su_username
39
+ establish_connection(configuration_hash.merge(
40
+ database: "postgres",
41
+ password: su_password,
42
+ schema_search_path: "public",
43
+ username: su_username
44
44
  ))
45
45
  end
46
46
 
47
47
  def establish_su_connection
48
- establish_connection(configuration.merge(
49
- "password" => su_password,
50
- "schema_search_path" => "public",
51
- "username" => su_username
48
+ establish_connection(configuration_hash.merge(
49
+ password: su_password,
50
+ schema_search_path: "public",
51
+ username: su_username
52
52
  ))
53
53
  end
54
54
 
55
55
  def username
56
- @username ||= configuration["username"]
56
+ @username ||= configuration_hash[:username]
57
57
  end
58
58
 
59
59
  def quoted_username
@@ -61,29 +61,30 @@ module ActiveRecord # :nodoc:
61
61
  end
62
62
 
63
63
  def password
64
- @password ||= configuration["password"]
64
+ @password ||= configuration_hash[:password]
65
65
  end
66
66
 
67
67
  def su_username
68
- @su_username ||= configuration["su_username"] || username
68
+ @su_username ||= configuration_hash.fetch(:su_username, username)
69
69
  end
70
70
 
71
71
  def su_password
72
- @su_password ||= configuration["su_password"] || password
72
+ @su_password ||= configuration_hash.fetch(:su_password, password)
73
73
  end
74
74
 
75
75
  def has_su?
76
- @has_su = configuration.include?("su_username") unless defined?(@has_su)
77
- @has_su
76
+ return @has_su if defined?(@has_su)
77
+
78
+ @has_su = configuration_hash.include?(:su_username)
78
79
  end
79
80
 
80
81
  def search_path
81
- @search_path ||= configuration["schema_search_path"].to_s.strip.split(",").map(&:strip)
82
+ @search_path ||= configuration_hash[:schema_search_path].to_s.strip.split(",").map(&:strip)
82
83
  end
83
84
 
84
85
  def extension_names
85
86
  @extension_names ||= begin
86
- extensions = configuration["postgis_extension"]
87
+ extensions = configuration_hash[:postgis_extension]
87
88
  case extensions
88
89
  when ::String
89
90
  extensions.split(",")
@@ -96,11 +97,11 @@ module ActiveRecord # :nodoc:
96
97
  end
97
98
 
98
99
  def ensure_installation_configs
99
- if configuration["setup"] == "default" && !configuration["postgis_extension"]
100
+ if configuration_hash[:setup] == "default" && !configuration_hash[:postgis_extension]
100
101
  share_dir = `pg_config --sharedir`.strip rescue "/usr/share"
101
102
  control_file = ::File.expand_path("extension/postgis.control", share_dir)
102
103
  if ::File.readable?(control_file)
103
- configuration["postgis_extension"] = "postgis"
104
+ @configuration_hash = configuration_hash.merge(postgis_extension: "postgis").freeze
104
105
  end
105
106
  end
106
107
  end
@@ -113,7 +114,7 @@ module ActiveRecord # :nodoc:
113
114
  end
114
115
  connection.execute("CREATE EXTENSION IF NOT EXISTS #{extname} SCHEMA topology")
115
116
  else
116
- if (postgis_schema = configuration["postgis_schema"])
117
+ if (postgis_schema = configuration_hash[:postgis_schema])
117
118
  schema_clause = "WITH SCHEMA #{postgis_schema}"
118
119
  unless schema_exists?(postgis_schema)
119
120
  connection.execute("CREATE SCHEMA #{postgis_schema}")
@@ -3,7 +3,7 @@
3
3
  module ActiveRecord
4
4
  module ConnectionAdapters
5
5
  module PostGIS
6
- VERSION = "6.0.3"
6
+ VERSION = "7.0.0"
7
7
  end
8
8
  end
9
9
  end
@@ -7,18 +7,11 @@
7
7
 
8
8
  require "rgeo/active_record"
9
9
 
10
- # autoload AbstractAdapter to avoid circular require and void context warnings
11
- module ActiveRecord
12
- module ConnectionAdapters
13
- AbstractAdapter
14
- end
15
- end
16
-
10
+ require "active_record/connection_adapters"
17
11
  require "active_record/connection_adapters/postgresql_adapter"
18
12
  require "active_record/connection_adapters/postgis/version"
19
13
  require "active_record/connection_adapters/postgis/column_methods"
20
14
  require "active_record/connection_adapters/postgis/schema_statements"
21
- require "active_record/connection_adapters/postgis/database_statements"
22
15
  require "active_record/connection_adapters/postgis/spatial_column_info"
23
16
  require "active_record/connection_adapters/postgis/spatial_table_definition"
24
17
  require "active_record/connection_adapters/postgis/spatial_column"
@@ -39,7 +32,7 @@ end
39
32
  module ActiveRecord
40
33
  module ConnectionAdapters
41
34
  class PostGISAdapter < PostgreSQLAdapter
42
- ADAPTER_NAME = 'PostGIS'
35
+ ADAPTER_NAME = 'PostGIS'.freeze
43
36
 
44
37
  SPATIAL_COLUMN_OPTIONS =
45
38
  {
@@ -59,7 +52,6 @@ module ActiveRecord
59
52
  DEFAULT_SRID = 0
60
53
 
61
54
  include PostGIS::SchemaStatements
62
- include PostGIS::DatabaseStatements
63
55
 
64
56
  def arel_visitor # :nodoc:
65
57
  Arel::Visitors::PostGIS.new(self)
@@ -95,32 +87,6 @@ module ActiveRecord
95
87
  super
96
88
  end
97
89
  end
98
-
99
- def quote_default_expression(value, column)
100
- if column.type == :geography || column.type == :geometry
101
- quote(value)
102
- else
103
- super
104
- end
105
- end
106
- end
107
- end
108
- end
109
-
110
- # if using JRUBY, create ArJdbc::PostGIS module
111
- # and prepend it to the PostgreSQL adapter since
112
- # it is the default adapter_spec.
113
- # see: https://github.com/jruby/activerecord-jdbc-adapter/blob/60-stable/lib/arjdbc/postgresql/adapter.rb#27
114
- if RUBY_ENGINE == "jruby"
115
- module ArJdbc
116
- module PostGIS
117
- ADAPTER_NAME = 'PostGIS'
118
-
119
- def adapter_name
120
- ADAPTER_NAME
121
- end
122
90
  end
123
91
  end
124
-
125
- ArJdbc::PostgreSQL.prepend(ArJdbc::PostGIS)
126
92
  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: 6.0.3
4
+ version: 7.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: 2021-01-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -17,42 +17,42 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 6.0.0
20
+ version: '6.1'
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.0.0
27
+ version: '6.1'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rgeo-activerecord
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '6.0'
34
+ version: 7.0.0
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '6.0'
41
+ version: 7.0.0
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rake
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '13.0'
48
+ version: '12.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: '13.0'
55
+ version: '12.0'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: minitest
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -110,7 +110,6 @@ files:
110
110
  - lib/active_record/connection_adapters/postgis/arel_tosql.rb
111
111
  - lib/active_record/connection_adapters/postgis/column_methods.rb
112
112
  - lib/active_record/connection_adapters/postgis/create_connection.rb
113
- - lib/active_record/connection_adapters/postgis/database_statements.rb
114
113
  - lib/active_record/connection_adapters/postgis/databases.rake
115
114
  - lib/active_record/connection_adapters/postgis/oid/spatial.rb
116
115
  - lib/active_record/connection_adapters/postgis/postgis_database_tasks.rb
@@ -142,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
141
  - !ruby/object:Gem::Version
143
142
  version: '0'
144
143
  requirements: []
145
- rubygems_version: 3.1.4
144
+ rubygems_version: 3.0.8
146
145
  signing_key:
147
146
  specification_version: 4
148
147
  summary: ActiveRecord adapter for PostGIS, based on RGeo.
@@ -1,14 +0,0 @@
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