activerecord-postgresql-extensions 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -203,30 +203,27 @@ module ActiveRecord
|
|
203
203
|
end
|
204
204
|
|
205
205
|
def extract_schema_name(name)
|
206
|
-
schema,
|
207
|
-
schema if
|
206
|
+
schema, _ = extract_schema_and_table_names(name)
|
207
|
+
schema if schema
|
208
208
|
end
|
209
209
|
|
210
210
|
def extract_table_name(name)
|
211
|
-
|
212
|
-
|
213
|
-
unless name_part
|
214
|
-
schema
|
215
|
-
else
|
216
|
-
table_name, name_part = extract_pg_identifier_from_name(name_part)
|
217
|
-
table_name
|
218
|
-
end
|
211
|
+
_, name_part = extract_schema_and_table_names(name)
|
212
|
+
name_part if name_part
|
219
213
|
end
|
220
214
|
|
221
215
|
def extract_schema_and_table_names(name)
|
222
|
-
|
223
|
-
|
224
|
-
unless name_part
|
225
|
-
quote_column_name(schema)
|
226
|
-
[ nil, schema ]
|
216
|
+
if name.is_a?(Hash)
|
217
|
+
[ name.keys.first.to_s, name.values.first.to_s ]
|
227
218
|
else
|
228
|
-
|
229
|
-
|
219
|
+
schema, name_part = extract_pg_identifier_from_name(name.to_s)
|
220
|
+
|
221
|
+
unless name_part
|
222
|
+
[ nil, schema.to_s ]
|
223
|
+
else
|
224
|
+
table_name, name_part = extract_pg_identifier_from_name(name_part)
|
225
|
+
[ schema.to_s, table_name.to_s ]
|
226
|
+
end
|
230
227
|
end
|
231
228
|
end
|
232
229
|
|
@@ -27,6 +27,21 @@ module ActiveRecord
|
|
27
27
|
})
|
28
28
|
end
|
29
29
|
alias_method_chain :native_database_types, :spatial_types
|
30
|
+
|
31
|
+
# Updates the definition of a geometry field to a new SRID value.
|
32
|
+
def update_geometry_srid(table_name, column_name, srid)
|
33
|
+
schema, table = extract_schema_and_table_names(table_name)
|
34
|
+
|
35
|
+
args = [
|
36
|
+
quote(table),
|
37
|
+
quote(column_name),
|
38
|
+
quote(srid)
|
39
|
+
]
|
40
|
+
|
41
|
+
args.unshift(quote(schema)) if schema
|
42
|
+
|
43
|
+
execute(%{SELECT UpdateGeometrySRID(#{args.join(', ')});})
|
44
|
+
end
|
30
45
|
end
|
31
46
|
|
32
47
|
class PostgreSQLGeometryColumnDefinition
|
@@ -300,4 +300,24 @@ class AdapterExtensionTests < PostgreSQLExtensionsTestCase
|
|
300
300
|
%{CLUSTER "foo"."bar";}
|
301
301
|
], statements)
|
302
302
|
end
|
303
|
+
|
304
|
+
def test_extract_schema_name
|
305
|
+
assert_equal("foo", ARBC.extract_schema_name(:foo => :bar))
|
306
|
+
assert_equal("foo", ARBC.extract_schema_name(%{foo.bar}))
|
307
|
+
assert_equal("foo", ARBC.extract_schema_name(%{"foo"."bar"}))
|
308
|
+
assert_nil(ARBC.extract_schema_name(%{"bar"}))
|
309
|
+
end
|
310
|
+
|
311
|
+
def test_extract_table_name
|
312
|
+
assert_equal("bar", ARBC.extract_table_name(:foo => :bar))
|
313
|
+
assert_equal("bar", ARBC.extract_table_name(%{foo.bar}))
|
314
|
+
assert_equal("bar", ARBC.extract_table_name(%{"foo"."bar"}))
|
315
|
+
end
|
316
|
+
|
317
|
+
def test_extract_schema_and_table_names
|
318
|
+
assert_equal([ "foo", "bar" ], ARBC.extract_schema_and_table_names(:foo => :bar))
|
319
|
+
assert_equal([ "foo", "bar" ], ARBC.extract_schema_and_table_names(%{foo.bar}))
|
320
|
+
assert_equal([ "foo", "bar" ], ARBC.extract_schema_and_table_names(%{"foo"."bar"}))
|
321
|
+
assert_equal([ nil, "bar" ], ARBC.extract_schema_and_table_names(%{"bar"}))
|
322
|
+
end
|
303
323
|
end
|
data/test/geometry_tests.rb
CHANGED
@@ -2,11 +2,32 @@
|
|
2
2
|
$: << File.dirname(__FILE__)
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
|
+
class GeometryTests < PostgreSQLExtensionsTestCase
|
6
|
+
include PostgreSQLExtensionsTestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_update_geometry_srid
|
14
|
+
ARBC.update_geometry_srid(:foo, :the_geom, 4326)
|
15
|
+
ARBC.update_geometry_srid("foo.bar", :the_geom, 4326)
|
16
|
+
ARBC.update_geometry_srid({ :foo => :bar }, :the_geom, 4326)
|
17
|
+
|
18
|
+
expected = [
|
19
|
+
%{SELECT UpdateGeometrySRID('foo', 'the_geom', 4326);},
|
20
|
+
%{SELECT UpdateGeometrySRID('foo', 'bar', 'the_geom', 4326);},
|
21
|
+
%{SELECT UpdateGeometrySRID('foo', 'bar', 'the_geom', 4326);}
|
22
|
+
]
|
23
|
+
|
24
|
+
assert_equal(expected, statements)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
5
28
|
if (ActiveRecord::PostgreSQLExtensions::PostGIS.VERSION[:lib] rescue '') >= '2.0'
|
6
29
|
class GeometryTests < PostgreSQLExtensionsTestCase
|
7
30
|
def test_create_geometry
|
8
|
-
skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
|
9
|
-
|
10
31
|
Mig.create_table(:foo) do |t|
|
11
32
|
t.geometry :the_geom, :srid => 4326
|
12
33
|
end
|
@@ -28,8 +49,6 @@ if (ActiveRecord::PostgreSQLExtensions::PostGIS.VERSION[:lib] rescue '') >= '2.0
|
|
28
49
|
end
|
29
50
|
|
30
51
|
def test_create_geometry_with_spatial
|
31
|
-
skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
|
32
|
-
|
33
52
|
Mig.create_table(:foo) do |t|
|
34
53
|
t.spatial :the_geom, :srid => 4326
|
35
54
|
end
|
@@ -51,8 +70,6 @@ if (ActiveRecord::PostgreSQLExtensions::PostGIS.VERSION[:lib] rescue '') >= '2.0
|
|
51
70
|
end
|
52
71
|
|
53
72
|
def test_create_geometry_with_spatial_and_spatial_column_type
|
54
|
-
skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
|
55
|
-
|
56
73
|
Mig.create_table(:foo) do |t|
|
57
74
|
t.spatial :the_geom, :srid => 4326, :spatial_column_type => :geography
|
58
75
|
end
|
@@ -74,8 +91,6 @@ if (ActiveRecord::PostgreSQLExtensions::PostGIS.VERSION[:lib] rescue '') >= '2.0
|
|
74
91
|
end
|
75
92
|
|
76
93
|
def test_create_geography
|
77
|
-
skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
|
78
|
-
|
79
94
|
Mig.create_table(:foo) do |t|
|
80
95
|
t.geography :the_geom, :srid => 4326
|
81
96
|
end
|
@@ -97,8 +112,6 @@ if (ActiveRecord::PostgreSQLExtensions::PostGIS.VERSION[:lib] rescue '') >= '2.0
|
|
97
112
|
end
|
98
113
|
|
99
114
|
def test_create_geometry_with_force_constraints
|
100
|
-
skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
|
101
|
-
|
102
115
|
Mig.create_table(:foo) do |t|
|
103
116
|
t.geometry :the_geom, :srid => 4326, :force_constraints => true
|
104
117
|
end
|
@@ -143,8 +156,6 @@ if (ActiveRecord::PostgreSQLExtensions::PostGIS.VERSION[:lib] rescue '') >= '2.0
|
|
143
156
|
end
|
144
157
|
|
145
158
|
def test_create_geometry_with_not_null
|
146
|
-
skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
|
147
|
-
|
148
159
|
Mig.create_table(:foo) do |t|
|
149
160
|
t.geometry :the_geom, :srid => 4326, :null => false
|
150
161
|
end
|
@@ -166,8 +177,6 @@ if (ActiveRecord::PostgreSQLExtensions::PostGIS.VERSION[:lib] rescue '') >= '2.0
|
|
166
177
|
end
|
167
178
|
|
168
179
|
def test_create_geometry_with_null_and_type
|
169
|
-
skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
|
170
|
-
|
171
180
|
Mig.create_table(:foo) do |t|
|
172
181
|
t.geometry :the_geom, :srid => 4326, :geometry_type => :polygon
|
173
182
|
end
|
@@ -190,11 +199,7 @@ if (ActiveRecord::PostgreSQLExtensions::PostGIS.VERSION[:lib] rescue '') >= '2.0
|
|
190
199
|
end
|
191
200
|
else
|
192
201
|
class GeometryTests < Test::Unit::TestCase
|
193
|
-
include PostgreSQLExtensionsTestHelper
|
194
|
-
|
195
202
|
def test_create_geometry
|
196
|
-
skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
|
197
|
-
|
198
203
|
Mig.create_table(:foo) do |t|
|
199
204
|
t.geometry :the_geom, :srid => 4326
|
200
205
|
end
|
@@ -226,8 +231,6 @@ else
|
|
226
231
|
end
|
227
232
|
|
228
233
|
def test_create_geometry_with_spatial
|
229
|
-
skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
|
230
|
-
|
231
234
|
Mig.create_table(:foo) do |t|
|
232
235
|
t.spatial :the_geom, :srid => 4326
|
233
236
|
end
|
@@ -259,8 +262,6 @@ else
|
|
259
262
|
end
|
260
263
|
|
261
264
|
def test_create_geometry_with_spatial_and_spatial_column_type
|
262
|
-
skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
|
263
|
-
|
264
265
|
Mig.create_table(:foo) do |t|
|
265
266
|
t.spatial :the_geom, :srid => 4326, :spatial_column_type => :geography
|
266
267
|
end
|
@@ -284,8 +285,6 @@ else
|
|
284
285
|
end
|
285
286
|
|
286
287
|
def test_create_geography
|
287
|
-
skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
|
288
|
-
|
289
288
|
Mig.create_table(:foo) do |t|
|
290
289
|
t.geography :the_geom, :srid => 4326
|
291
290
|
end
|
@@ -309,8 +308,6 @@ else
|
|
309
308
|
end
|
310
309
|
|
311
310
|
def test_create_geometry_with_schema
|
312
|
-
skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
|
313
|
-
|
314
311
|
Mig.create_table('shabba.foo') do |t|
|
315
312
|
t.geometry :the_geom, :srid => 4326
|
316
313
|
end
|
@@ -342,8 +339,6 @@ else
|
|
342
339
|
end
|
343
340
|
|
344
341
|
def test_create_geometry_with_not_null
|
345
|
-
skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
|
346
|
-
|
347
342
|
Mig.create_table(:foo) do |t|
|
348
343
|
t.geometry :the_geom, :srid => 4326, :null => false
|
349
344
|
end
|
@@ -375,8 +370,6 @@ else
|
|
375
370
|
end
|
376
371
|
|
377
372
|
def test_create_geometry_with_null_and_type
|
378
|
-
skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
|
379
|
-
|
380
373
|
Mig.create_table(:foo) do |t|
|
381
374
|
t.geometry :the_geom, :srid => 4326, :geometry_type => :polygon
|
382
375
|
end
|
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: activerecord-postgresql-extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.6.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- J Smith
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-12-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -104,7 +104,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
104
104
|
- !ruby/object:Gem::Version
|
105
105
|
segments:
|
106
106
|
- 0
|
107
|
-
hash:
|
107
|
+
hash: -2185802577024505074
|
108
108
|
version: '0'
|
109
109
|
none: false
|
110
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|