activerecord-postgis-adapter 5.2.3 → 6.0.0
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/create_connection.rb +9 -4
- data/lib/active_record/connection_adapters/postgis/databases.rake +8 -7
- data/lib/active_record/connection_adapters/postgis/schema_statements.rb +31 -40
- data/lib/active_record/connection_adapters/postgis/spatial_column.rb +13 -18
- data/lib/active_record/connection_adapters/postgis/version.rb +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a833d2d7fa9bba57717556d4f0caf2999acd233bfc5bbee07a83a3fa611d5027
|
4
|
+
data.tar.gz: 1f5c2155f745932c8f33cf6fed32063078963f026acadd117af60b4ea6a03ec2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0996d86cd8ca024fa121f2396be5fb13bd0da6e04a6fc2ea41cbc3ea5afdb49b03308b7bb90331ff347924b0bc81d624655bc31e6d83d218ef941c06f2ff5285'
|
7
|
+
data.tar.gz: 281e1d2f486993b31636d163d449c901e4dd4d67eb872fd33a0f403ea05001b554980bd621e3fcdd74a0b56b126e3f9e063de5499b93981b07fadb41d08158d6
|
@@ -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
|
@@ -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#L523
|
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
|
@@ -84,7 +75,7 @@ module ActiveRecord
|
|
84
75
|
|
85
76
|
# override
|
86
77
|
def create_table_definition(*args)
|
87
|
-
PostGIS::TableDefinition.new(*args)
|
78
|
+
PostGIS::TableDefinition.new(self, *args)
|
88
79
|
end
|
89
80
|
|
90
81
|
# memoize hash of column infos for tables
|
@@ -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
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Azuma, Tee Parham
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '6.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '6.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rgeo-activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '12.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '12.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: minitest
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,14 +130,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
130
130
|
requirements:
|
131
131
|
- - ">="
|
132
132
|
- !ruby/object:Gem::Version
|
133
|
-
version: 2.
|
133
|
+
version: 2.5.0
|
134
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
requirements: []
|
140
|
-
rubygems_version: 3.0.
|
140
|
+
rubygems_version: 3.0.4
|
141
141
|
signing_key:
|
142
142
|
specification_version: 4
|
143
143
|
summary: ActiveRecord adapter for PostGIS, based on RGeo.
|