activerecord-postgis-adapter 2.0.1 → 2.0.2
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_adapter/main_adapter.rb +31 -31
- data/lib/active_record/connection_adapters/postgis_adapter/postgis_database_tasks.rb +2 -17
- data/lib/active_record/connection_adapters/postgis_adapter/version.rb +1 -1
- data/test/basic_test.rb +1 -1
- data/test/ddl_test.rb +1 -57
- data/test/nested_class_test.rb +1 -1
- data/test/setup_test.rb +1 -1
- data/test/spatial_queries_test.rb +1 -1
- data/test/tasks_test.rb +23 -1
- data/test/test_helper.rb +0 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84cec176fe58c09c168a2e70ded5aa3c6cd340bc
|
4
|
+
data.tar.gz: feb4f2299f2031b0f8f3f5750225600b4f1f8f29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd646dad76070fb45abc821d56d5945cf28d76e967f9a479d11bc81d1fe2a4e1cc33c98d7e346eec3a7546f2207d09b3f427f0f3a87a529a12f294cc21701d6b
|
7
|
+
data.tar.gz: 1b916339a0926ced1441a14aecc8f68e21f5bffbf196c64f677f975121622b554bfe178d3819e0eeb2bd78d8d8c878011b819ab97694d74e298d7f3262872748
|
@@ -116,9 +116,7 @@ module ActiveRecord # :nodoc:
|
|
116
116
|
has_z = col.has_z?
|
117
117
|
has_m = col.has_m?
|
118
118
|
type = "#{type}M" if has_m && !has_z
|
119
|
-
dimensions_ =
|
120
|
-
dimensions_ += 1 if has_z
|
121
|
-
dimensions_ += 1 if has_m
|
119
|
+
dimensions_ = set_dimensions(has_m, has_z)
|
122
120
|
execute("SELECT AddGeometryColumn('#{quote_string(table_name)}', '#{quote_string(col.name.to_s)}', #{col.srid}, '#{quote_string(type)}', #{dimensions_})")
|
123
121
|
end
|
124
122
|
end
|
@@ -127,32 +125,7 @@ module ActiveRecord # :nodoc:
|
|
127
125
|
table_name = table_name.to_s
|
128
126
|
column_name = column_name.to_s
|
129
127
|
if (info = spatial_column_constructor(type.to_sym))
|
130
|
-
|
131
|
-
if type.to_s == 'geometry' &&
|
132
|
-
(options[:no_constraints] || limit.is_a?(::Hash) && limit[:no_constraints])
|
133
|
-
then
|
134
|
-
options.delete(:limit)
|
135
|
-
super
|
136
|
-
else
|
137
|
-
options.merge!(limit) if limit.is_a?(::Hash)
|
138
|
-
type = (options[:type] || info[:type] || type).to_s.gsub('_', '').upcase
|
139
|
-
has_z = options[:has_z]
|
140
|
-
has_m = options[:has_m]
|
141
|
-
srid = (options[:srid] || PostGISAdapter::DEFAULT_SRID).to_i
|
142
|
-
if options[:geographic]
|
143
|
-
type << 'Z' if has_z
|
144
|
-
type << 'M' if has_m
|
145
|
-
execute("ALTER TABLE #{quote_table_name(table_name)} ADD COLUMN #{quote_column_name(column_name)} GEOGRAPHY(#{type},#{srid})")
|
146
|
-
change_column_default(table_name, column_name, options[:default]) if options_include_default?(options)
|
147
|
-
change_column_null(table_name, column_name, false, options[:default]) if options[:null] == false
|
148
|
-
else
|
149
|
-
type = "#{type}M" if has_m && !has_z
|
150
|
-
dimensions = 2
|
151
|
-
dimensions += 1 if has_z
|
152
|
-
dimensions += 1 if has_m
|
153
|
-
execute("SELECT AddGeometryColumn('#{quote_string(table_name)}', '#{quote_string(column_name)}', #{srid}, '#{quote_string(type)}', #{dimensions})")
|
154
|
-
end
|
155
|
-
end
|
128
|
+
add_spatial_column(column_name, table_name, info, type, options)
|
156
129
|
else
|
157
130
|
super
|
158
131
|
end
|
@@ -172,8 +145,8 @@ module ActiveRecord # :nodoc:
|
|
172
145
|
# FULL REPLACEMENT. RE-CHECK ON NEW VERSIONS
|
173
146
|
# https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
|
174
147
|
def add_index(table_name, column_name, options = {})
|
175
|
-
# We have to fully
|
176
|
-
|
148
|
+
# We have to fully replace to add the gist clause.
|
149
|
+
options ||= {} # in case nil explicitly passed
|
177
150
|
gist = options.delete(:spatial)
|
178
151
|
index_name, index_type, index_columns, index_options, index_algorithm, index_using = add_index_options(table_name, column_name, options)
|
179
152
|
index_using = 'USING GIST' if gist
|
@@ -204,6 +177,26 @@ module ActiveRecord # :nodoc:
|
|
204
177
|
|
205
178
|
private
|
206
179
|
|
180
|
+
def add_spatial_column(column_name, table_name, info, type, options)
|
181
|
+
limit = options[:limit]
|
182
|
+
options.merge!(limit) if limit.is_a?(::Hash)
|
183
|
+
type = (options[:type] || info[:type] || type).to_s.gsub('_', '').upcase
|
184
|
+
has_z = options[:has_z]
|
185
|
+
has_m = options[:has_m]
|
186
|
+
srid = (options[:srid] || PostGISAdapter::DEFAULT_SRID).to_i
|
187
|
+
if options[:geographic]
|
188
|
+
type << 'Z' if has_z
|
189
|
+
type << 'M' if has_m
|
190
|
+
execute("ALTER TABLE #{quote_table_name(table_name)} ADD COLUMN #{quote_column_name(column_name)} GEOGRAPHY(#{type},#{srid})")
|
191
|
+
change_column_default(table_name, column_name, options[:default]) if options_include_default?(options)
|
192
|
+
change_column_null(table_name, column_name, false, options[:default]) if options[:null] == false
|
193
|
+
else
|
194
|
+
type = "#{type}M" if has_m && !has_z
|
195
|
+
dimensions = set_dimensions(has_m, has_z)
|
196
|
+
execute("SELECT AddGeometryColumn('#{quote_string(table_name)}', '#{quote_string(column_name)}', #{srid}, '#{quote_string(type)}', #{dimensions})")
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
207
200
|
def column_type_map
|
208
201
|
if defined?(type_map) # ActiveRecord 4.1+
|
209
202
|
type_map
|
@@ -212,6 +205,13 @@ module ActiveRecord # :nodoc:
|
|
212
205
|
end
|
213
206
|
end
|
214
207
|
|
208
|
+
def set_dimensions(has_m, has_z)
|
209
|
+
dimensions = 2
|
210
|
+
dimensions += 1 if has_z
|
211
|
+
dimensions += 1 if has_m
|
212
|
+
dimensions
|
213
|
+
end
|
214
|
+
|
215
215
|
end
|
216
216
|
end
|
217
217
|
end
|
@@ -10,9 +10,7 @@ module ActiveRecord # :nodoc:
|
|
10
10
|
|
11
11
|
def setup_gis
|
12
12
|
establish_su_connection
|
13
|
-
if
|
14
|
-
setup_gis_from_script_dir
|
15
|
-
elsif extension_names
|
13
|
+
if extension_names
|
16
14
|
setup_gis_from_extension
|
17
15
|
end
|
18
16
|
establish_connection(configuration)
|
@@ -80,11 +78,6 @@ module ActiveRecord # :nodoc:
|
|
80
78
|
@search_path ||= configuration['schema_search_path'].to_s.strip.split(',').map(&:strip)
|
81
79
|
end
|
82
80
|
|
83
|
-
def script_dir
|
84
|
-
@script_dir = configuration['script_dir'] unless defined?(@script_dir)
|
85
|
-
@script_dir
|
86
|
-
end
|
87
|
-
|
88
81
|
def extension_names
|
89
82
|
@extension_names ||= begin
|
90
83
|
ext_ = configuration['postgis_extension']
|
@@ -100,14 +93,11 @@ module ActiveRecord # :nodoc:
|
|
100
93
|
end
|
101
94
|
|
102
95
|
def ensure_installation_configs
|
103
|
-
if configuration['setup'] == 'default' && !configuration['
|
96
|
+
if configuration['setup'] == 'default' && !configuration['postgis_extension']
|
104
97
|
share_dir_ = `pg_config --sharedir`.strip rescue '/usr/share'
|
105
|
-
script_dir_ = ::File.expand_path('contrib/postgis-1.5', share_dir_)
|
106
98
|
control_file_ = ::File.expand_path('extension/postgis.control', share_dir_)
|
107
99
|
if ::File.readable?(control_file_)
|
108
100
|
configuration['postgis_extension'] = 'postgis'
|
109
|
-
elsif ::File.directory?(script_dir_)
|
110
|
-
configuration['script_dir'] = script_dir_
|
111
101
|
end
|
112
102
|
end
|
113
103
|
end
|
@@ -122,11 +112,6 @@ module ActiveRecord # :nodoc:
|
|
122
112
|
end
|
123
113
|
end
|
124
114
|
end
|
125
|
-
|
126
|
-
def setup_gis_from_script_dir
|
127
|
-
connection.execute(::File.read(::File.expand_path('postgis.sql', script_dir)))
|
128
|
-
connection.execute(::File.read(::File.expand_path('spatial_ref_sys.sql', script_dir)))
|
129
|
-
end
|
130
115
|
end
|
131
116
|
|
132
117
|
::ActiveRecord::Tasks::DatabaseTasks.register_task(/postgis/, PostGISDatabaseTasks)
|
data/test/basic_test.rb
CHANGED
@@ -4,7 +4,7 @@ module RGeo
|
|
4
4
|
module ActiveRecord # :nodoc:
|
5
5
|
module PostGISAdapter # :nodoc:
|
6
6
|
module Tests # :nodoc:
|
7
|
-
class BasicTest <
|
7
|
+
class BasicTest < ActiveSupport::TestCase # :nodoc:
|
8
8
|
DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database.yml'
|
9
9
|
OVERRIDE_DATABASE_CONFIG_PATH = ::File.dirname(__FILE__)+'/database_local.yml'
|
10
10
|
|
data/test/ddl_test.rb
CHANGED
@@ -4,7 +4,7 @@ module RGeo
|
|
4
4
|
module ActiveRecord # :nodoc:
|
5
5
|
module PostGISAdapter # :nodoc:
|
6
6
|
module Tests # :nodoc:
|
7
|
-
class DDLTest <
|
7
|
+
class DDLTest < ActiveSupport::TestCase # :nodoc:
|
8
8
|
DATABASE_CONFIG_PATH = ::File.dirname(__FILE__) + '/database.yml'
|
9
9
|
OVERRIDE_DATABASE_CONFIG_PATH = ::File.dirname(__FILE__) + '/database_local.yml'
|
10
10
|
|
@@ -27,23 +27,6 @@ module RGeo
|
|
27
27
|
assert_equal(0, klass.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
28
28
|
end
|
29
29
|
|
30
|
-
# no_constraints no longer supported in PostGIS 2.0
|
31
|
-
def _test_create_no_constraints_geometry
|
32
|
-
klass = create_ar_class
|
33
|
-
klass.connection.create_table(:spatial_test) do |t|
|
34
|
-
t.column 'geom', :geometry, :limit => {:no_constraints => true}
|
35
|
-
end
|
36
|
-
assert_equal(0, klass.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
37
|
-
col = klass.columns.last
|
38
|
-
assert_equal(::RGeo::Feature::Geometry, col.geometric_type)
|
39
|
-
assert_equal(false, col.geographic?)
|
40
|
-
assert_equal(false, col.has_spatial_constraints?)
|
41
|
-
assert_nil(col.srid)
|
42
|
-
assert(klass.cached_attributes.include?('geom'))
|
43
|
-
klass.connection.drop_table(:spatial_test)
|
44
|
-
assert_equal(0, klass.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
45
|
-
end
|
46
|
-
|
47
30
|
def test_create_simple_geography
|
48
31
|
klass = create_ar_class
|
49
32
|
klass.connection.create_table(:spatial_test) do |t|
|
@@ -100,29 +83,6 @@ module RGeo
|
|
100
83
|
assert_equal(false, cols_[-1].has_spatial_constraints?)
|
101
84
|
end
|
102
85
|
|
103
|
-
# no_constraints no longer supported in PostGIS 2.0
|
104
|
-
def _test_add_no_constraints_geometry_column
|
105
|
-
klass = create_ar_class
|
106
|
-
klass.connection.create_table(:spatial_test) do |t|
|
107
|
-
t.column('latlon', :geometry)
|
108
|
-
end
|
109
|
-
klass.connection.change_table(:spatial_test) do |t|
|
110
|
-
t.column('geom2', :geometry, :no_constraints => true)
|
111
|
-
t.column('name', :string)
|
112
|
-
end
|
113
|
-
assert_equal(1, klass.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
114
|
-
cols_ = klass.columns
|
115
|
-
assert_equal(::RGeo::Feature::Geometry, cols_[-3].geometric_type)
|
116
|
-
assert_equal(0, cols_[-3].srid)
|
117
|
-
assert_equal(true, cols_[-3].has_spatial_constraints?)
|
118
|
-
assert_equal(::RGeo::Feature::Geometry, cols_[-2].geometric_type)
|
119
|
-
assert_nil(cols_[-2].srid)
|
120
|
-
assert_equal(false, cols_[-2].geographic?)
|
121
|
-
assert_equal(false, cols_[-2].has_spatial_constraints?)
|
122
|
-
assert_nil(cols_[-1].geometric_type)
|
123
|
-
assert_equal(false, cols_[-1].has_spatial_constraints?)
|
124
|
-
end
|
125
|
-
|
126
86
|
def test_add_geography_column
|
127
87
|
klass = create_ar_class
|
128
88
|
klass.connection.create_table(:spatial_test) do |t|
|
@@ -197,22 +157,6 @@ module RGeo
|
|
197
157
|
assert_equal(0, klass.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
198
158
|
end
|
199
159
|
|
200
|
-
# no_constraints no longer supported in PostGIS 2.0
|
201
|
-
def _test_create_no_constraints_geometry_using_shortcut
|
202
|
-
klass = create_ar_class
|
203
|
-
klass.connection.create_table(:spatial_test) do |t|
|
204
|
-
t.spatial 'geom', :no_constraints => true
|
205
|
-
end
|
206
|
-
assert_equal(0, klass.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
207
|
-
col = klass.columns.last
|
208
|
-
assert_equal(::RGeo::Feature::Geometry, col.geometric_type)
|
209
|
-
assert_equal(false, col.geographic?)
|
210
|
-
assert_nil(col.srid)
|
211
|
-
assert(klass.cached_attributes.include?('geom'))
|
212
|
-
klass.connection.drop_table(:spatial_test)
|
213
|
-
assert_equal(0, klass.connection.select_value("SELECT COUNT(*) FROM geometry_columns WHERE f_table_name='spatial_test'").to_i)
|
214
|
-
end
|
215
|
-
|
216
160
|
def test_create_simple_geography_using_shortcut
|
217
161
|
klass = create_ar_class
|
218
162
|
klass.connection.create_table(:spatial_test) do |t|
|
data/test/nested_class_test.rb
CHANGED
@@ -4,7 +4,7 @@ module RGeo
|
|
4
4
|
module ActiveRecord # :nodoc:
|
5
5
|
module PostGISAdapter # :nodoc:
|
6
6
|
module Tests # :nodoc:
|
7
|
-
class NestedClassTest <
|
7
|
+
class NestedClassTest < ActiveSupport::TestCase # :nodoc:
|
8
8
|
DATABASE_CONFIG_PATH = ::File.dirname(__FILE__) + '/database.yml'
|
9
9
|
OVERRIDE_DATABASE_CONFIG_PATH = ::File.dirname(__FILE__) + '/database_local.yml'
|
10
10
|
|
data/test/setup_test.rb
CHANGED
@@ -4,7 +4,7 @@ module RGeo
|
|
4
4
|
module ActiveRecord # :nodoc:
|
5
5
|
module PostGISAdapter # :nodoc:
|
6
6
|
module Tests # :nodoc:
|
7
|
-
class SpatialQueriesTest <
|
7
|
+
class SpatialQueriesTest < ActiveSupport::TestCase # :nodoc:
|
8
8
|
|
9
9
|
def test_ignore_tables
|
10
10
|
assert_equal %w(geometry_columns spatial_ref_sys layer topology), ::ActiveRecord::SchemaDumper.ignore_tables
|
@@ -4,7 +4,7 @@ module RGeo
|
|
4
4
|
module ActiveRecord # :nodoc:
|
5
5
|
module PostGISAdapter # :nodoc:
|
6
6
|
module Tests # :nodoc:
|
7
|
-
class SpatialQueriesTest <
|
7
|
+
class SpatialQueriesTest < ActiveSupport::TestCase # :nodoc:
|
8
8
|
|
9
9
|
DATABASE_CONFIG_PATH = ::File.dirname(__FILE__) + '/database.yml'
|
10
10
|
OVERRIDE_DATABASE_CONFIG_PATH = ::File.dirname(__FILE__) + '/database_local.yml'
|
data/test/tasks_test.rb
CHANGED
@@ -5,7 +5,7 @@ module RGeo
|
|
5
5
|
module ActiveRecord # :nodoc:
|
6
6
|
module PostGISAdapter # :nodoc:
|
7
7
|
module Tests # :nodoc:
|
8
|
-
class TasksTest <
|
8
|
+
class TasksTest < ActiveSupport::TestCase # :nodoc:
|
9
9
|
DATABASE_CONFIG_PATH = ::File.dirname(__FILE__) + '/database.yml'
|
10
10
|
OVERRIDE_DATABASE_CONFIG_PATH = ::File.dirname(__FILE__) + '/database_local.yml'
|
11
11
|
|
@@ -113,6 +113,28 @@ module RGeo
|
|
113
113
|
assert data.index('t.spatial "latlon", limit: {:srid=>4326, :type=>"point", :geographic=>true}')
|
114
114
|
assert data.index('add_index "spatial_test", ["latlon"], :name => "index_spatial_test_on_latlon", :spatial => true')
|
115
115
|
end
|
116
|
+
|
117
|
+
def test_add_index_with_nil_options
|
118
|
+
setup_database_tasks
|
119
|
+
connection.create_table(:test) do |t|
|
120
|
+
t.string "name"
|
121
|
+
end
|
122
|
+
connection.add_index :test, :name, nil
|
123
|
+
::ActiveRecord::Tasks::DatabaseTasks.structure_dump(TasksTest.new_database_config, tmp_sql_filename)
|
124
|
+
data = ::File.read(tmp_sql_filename)
|
125
|
+
assert data.index('CREATE INDEX index_test_on_name ON test USING btree (name);')
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_add_index_via_references
|
129
|
+
setup_database_tasks
|
130
|
+
connection.create_table(:cats)
|
131
|
+
connection.create_table(:dogs) do |t|
|
132
|
+
t.references :cats, index: true
|
133
|
+
end
|
134
|
+
::ActiveRecord::Tasks::DatabaseTasks.structure_dump(TasksTest.new_database_config, tmp_sql_filename)
|
135
|
+
data = ::File.read(tmp_sql_filename)
|
136
|
+
assert data.index('CREATE INDEX index_dogs_on_cats_id ON dogs USING btree (cats_id);')
|
137
|
+
end
|
116
138
|
end
|
117
139
|
|
118
140
|
private
|
data/test/test_helper.rb
CHANGED
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: 2.0.
|
4
|
+
version: 2.0.2
|
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: 2014-
|
11
|
+
date: 2014-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|