activerecord-postgis-adapter 5.2.3 → 6.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_record/connection_adapters/postgis/column_methods.rb +10 -10
- data/lib/active_record/connection_adapters/postgis/create_connection.rb +9 -4
- data/lib/active_record/connection_adapters/postgis/database_statements.rb +14 -0
- data/lib/active_record/connection_adapters/postgis/databases.rake +8 -7
- data/lib/active_record/connection_adapters/postgis/schema_statements.rb +34 -43
- data/lib/active_record/connection_adapters/postgis/spatial_column.rb +13 -18
- data/lib/active_record/connection_adapters/postgis/spatial_table_definition.rb +3 -3
- data/lib/active_record/connection_adapters/postgis/version.rb +1 -1
- data/lib/active_record/connection_adapters/postgis_adapter.rb +32 -16
- metadata +14 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69cf59b00676a1afdd07f0f6569b267995f5a5a3587fdf52a706876d5e4a1f87
|
4
|
+
data.tar.gz: d678ad7901ed89fae596ebfef4a48d2f04231a085da840c7fa2c4714f0aca534
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 355f65508295569307ac86dba4970477eb6d41f1f48484bb203a61ff31b7a3ec827b9eea321441c24a83f8706ceead8c916cb833947074b2463e8ffdf0060050
|
7
|
+
data.tar.gz: ea179ffdf8d4d31a0065001ae396e552732679c7048e48994ef503c8e8ff206e7aa2140f07ffe31f67be5a046f3ee679ba3e8d50e993f54a08512bf214ccceed
|
@@ -6,43 +6,43 @@ module ActiveRecord
|
|
6
6
|
module ColumnMethods
|
7
7
|
def spatial(name, options = {})
|
8
8
|
raise "You must set a type. For example: 't.spatial type: :st_point'" unless options[:type]
|
9
|
-
column(name, options[:type], options)
|
9
|
+
column(name, options[:type], **options)
|
10
10
|
end
|
11
11
|
|
12
12
|
def geography(name, options = {})
|
13
|
-
column(name, :geography, options)
|
13
|
+
column(name, :geography, **options)
|
14
14
|
end
|
15
15
|
|
16
16
|
def geometry(name, options = {})
|
17
|
-
column(name, :geometry, options)
|
17
|
+
column(name, :geometry, **options)
|
18
18
|
end
|
19
19
|
|
20
20
|
def geometry_collection(name, options = {})
|
21
|
-
column(name, :geometry_collection, options)
|
21
|
+
column(name, :geometry_collection, **options)
|
22
22
|
end
|
23
23
|
|
24
24
|
def line_string(name, options = {})
|
25
|
-
column(name, :line_string, options)
|
25
|
+
column(name, :line_string, **options)
|
26
26
|
end
|
27
27
|
|
28
28
|
def multi_line_string(name, options = {})
|
29
|
-
column(name, :multi_line_string, options)
|
29
|
+
column(name, :multi_line_string, **options)
|
30
30
|
end
|
31
31
|
|
32
32
|
def multi_point(name, options = {})
|
33
|
-
column(name, :multi_point, options)
|
33
|
+
column(name, :multi_point, **options)
|
34
34
|
end
|
35
35
|
|
36
36
|
def multi_polygon(name, options = {})
|
37
|
-
column(name, :multi_polygon, options)
|
37
|
+
column(name, :multi_polygon, **options)
|
38
38
|
end
|
39
39
|
|
40
40
|
def st_point(name, options = {})
|
41
|
-
column(name, :st_point, options)
|
41
|
+
column(name, :st_point, **options)
|
42
42
|
end
|
43
43
|
|
44
44
|
def st_polygon(name, options = {})
|
45
|
-
column(name, :st_polygon, options)
|
45
|
+
column(name, :st_polygon, **options)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -31,13 +31,18 @@ module ActiveRecord # :nodoc:
|
|
31
31
|
conn_params[:user] = conn_params.delete(:username) if conn_params[:username]
|
32
32
|
conn_params[:dbname] = conn_params.delete(:database) if conn_params[:database]
|
33
33
|
|
34
|
-
# Forward only valid config params to
|
34
|
+
# Forward only valid config params to PG.connect
|
35
35
|
valid_conn_param_keys = PG::Connection.conndefaults_hash.keys + [:requiressl]
|
36
36
|
conn_params.slice!(*valid_conn_param_keys)
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
41
46
|
end
|
42
47
|
|
43
48
|
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
|
@@ -6,13 +6,14 @@ namespace :db do
|
|
6
6
|
task setup: [:load_config] do
|
7
7
|
environments = [Rails.env]
|
8
8
|
environments << "test" if Rails.env.development?
|
9
|
-
|
10
|
-
.
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
16
17
|
end
|
17
18
|
end
|
18
19
|
end
|
@@ -5,46 +5,37 @@ module ActiveRecord
|
|
5
5
|
module PostGIS
|
6
6
|
module SchemaStatements
|
7
7
|
# override
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
cast_type = get_oid_type(oid.to_i, fmod.to_i, column_name, type)
|
16
|
-
default_value = extract_value_from_default(default)
|
8
|
+
# https://github.com/rails/rails/blob/6-0-stable/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L624
|
9
|
+
# Create a SpatialColumn instead of a PostgreSQL::Column
|
10
|
+
def new_column_from_field(table_name, field)
|
11
|
+
column_name, type, default, notnull, oid, fmod, collation, comment = field
|
12
|
+
type_metadata = fetch_type_metadata(column_name, type, oid.to_i, fmod.to_i)
|
13
|
+
default_value = extract_value_from_default(default)
|
14
|
+
default_function = extract_default_function(default_value, default)
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
# override
|
25
|
-
def new_column(table_name, column_name, default, cast_type, sql_type_metadata = nil,
|
26
|
-
null = true, default_function = nil, collation = nil, comment = nil)
|
27
|
-
# JDBC gets true/false in Rails 4, where other platforms get 't'/'f' strings.
|
28
|
-
if null.is_a?(String)
|
29
|
-
null = (null == "t")
|
30
|
-
end
|
16
|
+
serial =
|
17
|
+
if (match = default_function&.match(/\Anextval\('"?(?<sequence_name>.+_(?<suffix>seq\d*))"?'::regclass\)\z/))
|
18
|
+
sequence_name_from_parts(table_name, column_name, match[:suffix]) == match[:sequence_name]
|
19
|
+
end
|
31
20
|
|
32
|
-
|
21
|
+
# {:dimension=>2, :has_m=>false, :has_z=>false, :name=>"latlon", :srid=>0, :type=>"GEOMETRY"}
|
22
|
+
spatial = spatial_column_info(table_name).get(column_name, type_metadata.sql_type)
|
33
23
|
|
34
|
-
SpatialColumn.new(
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
24
|
+
SpatialColumn.new(
|
25
|
+
column_name,
|
26
|
+
default_value,
|
27
|
+
type_metadata,
|
28
|
+
!notnull,
|
29
|
+
default_function,
|
30
|
+
collation: collation,
|
31
|
+
comment: comment.presence,
|
32
|
+
serial: serial,
|
33
|
+
spatial: spatial
|
34
|
+
)
|
44
35
|
end
|
45
36
|
|
46
37
|
# override
|
47
|
-
# https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#
|
38
|
+
# https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L544
|
48
39
|
#
|
49
40
|
# returns Postgresql sql type string
|
50
41
|
# examples:
|
@@ -54,12 +45,12 @@ module ActiveRecord
|
|
54
45
|
# note: type alone is not enough to detect the sql type,
|
55
46
|
# so `limit` is used to pass the additional information. :(
|
56
47
|
#
|
57
|
-
# type_to_sql(:geography, "Point,4326")
|
48
|
+
# type_to_sql(:geography, limit: "Point,4326")
|
58
49
|
# => "geography(Point,4326)"
|
59
|
-
def type_to_sql(type,
|
60
|
-
case type
|
61
|
-
when
|
62
|
-
"#{type}(#{
|
50
|
+
def type_to_sql(type, limit: nil, precision: nil, scale: nil, array: nil, **)
|
51
|
+
case type.to_s
|
52
|
+
when "geometry", "geography"
|
53
|
+
"#{type}(#{limit})"
|
63
54
|
else
|
64
55
|
super
|
65
56
|
end
|
@@ -83,8 +74,8 @@ module ActiveRecord
|
|
83
74
|
end
|
84
75
|
|
85
76
|
# override
|
86
|
-
def create_table_definition(*args)
|
87
|
-
PostGIS::TableDefinition.new(*args)
|
77
|
+
def create_table_definition(*args, **kwargs)
|
78
|
+
PostGIS::TableDefinition.new(self, *args, **kwargs)
|
88
79
|
end
|
89
80
|
|
90
81
|
# memoize hash of column infos for tables
|
@@ -94,8 +85,6 @@ module ActiveRecord
|
|
94
85
|
end
|
95
86
|
|
96
87
|
def initialize_type_map(map = type_map)
|
97
|
-
super
|
98
|
-
|
99
88
|
%w(
|
100
89
|
geography
|
101
90
|
geometry
|
@@ -111,6 +100,8 @@ module ActiveRecord
|
|
111
100
|
OID::Spatial.new(oid, sql_type)
|
112
101
|
end
|
113
102
|
end
|
103
|
+
|
104
|
+
super
|
114
105
|
end
|
115
106
|
end
|
116
107
|
end
|
@@ -7,19 +7,17 @@ module ActiveRecord # :nodoc:
|
|
7
7
|
# sql_type examples:
|
8
8
|
# "Geometry(Point,4326)"
|
9
9
|
# "Geography(Point,4326)"
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
default_function = nil, collation = nil, comment = nil, cast_type = nil, opts = nil)
|
15
|
-
@cast_type = cast_type
|
10
|
+
def initialize(name, default, sql_type_metadata = nil, null = true,
|
11
|
+
default_function = nil, collation: nil, comment: nil,
|
12
|
+
serial: nil, spatial: nil)
|
13
|
+
@sql_type_metadata = sql_type_metadata
|
16
14
|
@geographic = !!(sql_type_metadata.sql_type =~ /geography\(/i)
|
17
|
-
if
|
15
|
+
if spatial
|
18
16
|
# This case comes from an entry in the geometry_columns table
|
19
|
-
set_geometric_type_from_name(
|
20
|
-
@srid =
|
21
|
-
@has_z = !!
|
22
|
-
@has_m = !!
|
17
|
+
set_geometric_type_from_name(spatial[:type])
|
18
|
+
@srid = spatial[:srid].to_i
|
19
|
+
@has_z = !!spatial[:has_z]
|
20
|
+
@has_m = !!spatial[:has_m]
|
23
21
|
elsif @geographic
|
24
22
|
# Geographic type information is embedded in the SQL type
|
25
23
|
@srid = 4326
|
@@ -32,7 +30,8 @@ module ActiveRecord # :nodoc:
|
|
32
30
|
# @geometric_type = geo_type_from_sql_type(sql_type)
|
33
31
|
build_from_sql_type(sql_type_metadata.sql_type)
|
34
32
|
end
|
35
|
-
super(name, default, sql_type_metadata, null,
|
33
|
+
super(name, default, sql_type_metadata, null, default_function,
|
34
|
+
collation: collation, comment: comment, serial: serial)
|
36
35
|
if spatial?
|
37
36
|
if @srid
|
38
37
|
@limit = { srid: @srid, type: to_type_name(geometric_type) }
|
@@ -54,15 +53,11 @@ module ActiveRecord # :nodoc:
|
|
54
53
|
alias :has_m? :has_m
|
55
54
|
|
56
55
|
def limit
|
57
|
-
|
58
|
-
@limit
|
59
|
-
else
|
60
|
-
super
|
61
|
-
end
|
56
|
+
spatial? ? @limit : super
|
62
57
|
end
|
63
58
|
|
64
59
|
def spatial?
|
65
|
-
|
60
|
+
%i[geometry geography].include?(@sql_type_metadata.type)
|
66
61
|
end
|
67
62
|
|
68
63
|
private
|
@@ -7,7 +7,7 @@ module ActiveRecord # :nodoc:
|
|
7
7
|
include ColumnMethods
|
8
8
|
|
9
9
|
# super: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
|
10
|
-
def new_column_definition(name, type, options)
|
10
|
+
def new_column_definition(name, type, **options)
|
11
11
|
if (info = PostGISAdapter.spatial_column_options(type.to_sym))
|
12
12
|
if (limit = options.delete(:limit))
|
13
13
|
options.merge!(limit) if limit.is_a?(::Hash)
|
@@ -18,9 +18,9 @@ module ActiveRecord # :nodoc:
|
|
18
18
|
|
19
19
|
options[:limit] = ColumnDefinitionUtils.limit_from_options(geo_type, options)
|
20
20
|
options[:spatial_type] = geo_type
|
21
|
-
column = super(name, base_type, options)
|
21
|
+
column = super(name, base_type, **options)
|
22
22
|
else
|
23
|
-
column = super(name, type, options)
|
23
|
+
column = super(name, type, **options)
|
24
24
|
end
|
25
25
|
|
26
26
|
column
|
@@ -18,6 +18,7 @@ require "active_record/connection_adapters/postgresql_adapter"
|
|
18
18
|
require "active_record/connection_adapters/postgis/version"
|
19
19
|
require "active_record/connection_adapters/postgis/column_methods"
|
20
20
|
require "active_record/connection_adapters/postgis/schema_statements"
|
21
|
+
require "active_record/connection_adapters/postgis/database_statements"
|
21
22
|
require "active_record/connection_adapters/postgis/spatial_column_info"
|
22
23
|
require "active_record/connection_adapters/postgis/spatial_table_definition"
|
23
24
|
require "active_record/connection_adapters/postgis/spatial_column"
|
@@ -38,7 +39,7 @@ end
|
|
38
39
|
module ActiveRecord
|
39
40
|
module ConnectionAdapters
|
40
41
|
class PostGISAdapter < PostgreSQLAdapter
|
41
|
-
|
42
|
+
ADAPTER_NAME = 'PostGIS'
|
42
43
|
|
43
44
|
SPATIAL_COLUMN_OPTIONS =
|
44
45
|
{
|
@@ -57,22 +58,11 @@ module ActiveRecord
|
|
57
58
|
# http://postgis.17.x6.nabble.com/Default-SRID-td5001115.html
|
58
59
|
DEFAULT_SRID = 0
|
59
60
|
|
60
|
-
|
61
|
-
|
62
|
-
super
|
63
|
-
|
64
|
-
@visitor = Arel::Visitors::PostGIS.new(self)
|
65
|
-
# copy from https://github.com/rails/rails/blob/6ece7df8d80c6d93db43878fa4c0278a0204072c/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb#L199
|
66
|
-
if self.class.type_cast_config_to_boolean(config.fetch(:prepared_statements) { true })
|
67
|
-
@prepared_statements = true
|
68
|
-
@visitor.extend(DetermineIfPreparableVisitor)
|
69
|
-
else
|
70
|
-
@prepared_statements = false
|
71
|
-
end
|
72
|
-
end
|
61
|
+
include PostGIS::SchemaStatements
|
62
|
+
include PostGIS::DatabaseStatements
|
73
63
|
|
74
|
-
def
|
75
|
-
|
64
|
+
def arel_visitor # :nodoc:
|
65
|
+
Arel::Visitors::PostGIS.new(self)
|
76
66
|
end
|
77
67
|
|
78
68
|
def self.spatial_column_options(key)
|
@@ -105,6 +95,32 @@ module ActiveRecord
|
|
105
95
|
super
|
106
96
|
end
|
107
97
|
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
|
108
122
|
end
|
109
123
|
end
|
124
|
+
|
125
|
+
ArJdbc::PostgreSQL.prepend(ArJdbc::PostGIS)
|
110
126
|
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-postgis-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Daniel Azuma
|
7
|
+
- Daniel Azuma
|
8
|
+
- Tee Parham
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2021-
|
12
|
+
date: 2021-08-17 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: activerecord
|
@@ -16,14 +17,14 @@ dependencies:
|
|
16
17
|
requirements:
|
17
18
|
- - "~>"
|
18
19
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
+
version: 6.0.0
|
20
21
|
type: :runtime
|
21
22
|
prerelease: false
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
23
24
|
requirements:
|
24
25
|
- - "~>"
|
25
26
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
27
|
+
version: 6.0.0
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
29
|
name: rgeo-activerecord
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -97,7 +98,10 @@ dependencies:
|
|
97
98
|
description: ActiveRecord connection adapter for PostGIS. It is based on the stock
|
98
99
|
PostgreSQL adapter, and adds built-in support for the spatial extensions provided
|
99
100
|
by PostGIS. It uses the RGeo library to represent spatial data in Ruby.
|
100
|
-
email:
|
101
|
+
email:
|
102
|
+
- dazuma@gmail.com
|
103
|
+
- parhameter@gmail.com
|
104
|
+
- kfdoggett@gmail.com
|
101
105
|
executables: []
|
102
106
|
extensions: []
|
103
107
|
extra_rdoc_files: []
|
@@ -106,6 +110,7 @@ files:
|
|
106
110
|
- lib/active_record/connection_adapters/postgis/arel_tosql.rb
|
107
111
|
- lib/active_record/connection_adapters/postgis/column_methods.rb
|
108
112
|
- lib/active_record/connection_adapters/postgis/create_connection.rb
|
113
|
+
- lib/active_record/connection_adapters/postgis/database_statements.rb
|
109
114
|
- lib/active_record/connection_adapters/postgis/databases.rake
|
110
115
|
- lib/active_record/connection_adapters/postgis/oid/spatial.rb
|
111
116
|
- lib/active_record/connection_adapters/postgis/postgis_database_tasks.rb
|
@@ -120,7 +125,7 @@ files:
|
|
120
125
|
- lib/activerecord-postgis-adapter.rb
|
121
126
|
homepage: http://github.com/rgeo/activerecord-postgis-adapter
|
122
127
|
licenses:
|
123
|
-
- BSD
|
128
|
+
- BSD-3-Clause
|
124
129
|
metadata: {}
|
125
130
|
post_install_message:
|
126
131
|
rdoc_options: []
|
@@ -130,14 +135,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
130
135
|
requirements:
|
131
136
|
- - ">="
|
132
137
|
- !ruby/object:Gem::Version
|
133
|
-
version: 2.
|
138
|
+
version: 2.5.0
|
134
139
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
140
|
requirements:
|
136
141
|
- - ">="
|
137
142
|
- !ruby/object:Gem::Version
|
138
143
|
version: '0'
|
139
144
|
requirements: []
|
140
|
-
rubygems_version: 3.
|
145
|
+
rubygems_version: 3.1.4
|
141
146
|
signing_key:
|
142
147
|
specification_version: 4
|
143
148
|
summary: ActiveRecord adapter for PostGIS, based on RGeo.
|