activerecord-postgresql-extensions 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +16 -5
- data/activerecord-postgresql-extensions.gemspec +2 -0
- data/lib/active_record/postgresql_extensions/adapter_extensions.rb +14 -2
- data/lib/active_record/postgresql_extensions/constraints.rb +203 -13
- data/lib/active_record/postgresql_extensions/extensions.rb +18 -0
- data/lib/active_record/postgresql_extensions/features.rb +46 -0
- data/lib/active_record/postgresql_extensions/indexes.rb +16 -0
- data/lib/active_record/postgresql_extensions/permissions.rb +47 -22
- data/lib/active_record/postgresql_extensions/postgis.rb +6 -2
- data/lib/active_record/postgresql_extensions/tables.rb +45 -11
- data/lib/active_record/postgresql_extensions/vacuum.rb +101 -0
- data/lib/active_record/postgresql_extensions/version.rb +1 -1
- data/lib/activerecord-postgresql-extensions.rb +12 -0
- data/test/adapter_tests.rb +54 -2
- data/test/constraints_tests.rb +107 -1
- data/test/extensions_tests.rb +27 -1
- data/test/functions_tests.rb +1 -1
- data/test/geometry_tests.rb +180 -154
- data/test/index_tests.rb +12 -2
- data/test/languages_tests.rb +1 -1
- data/test/permissions_tests.rb +19 -7
- data/test/roles_tests.rb +1 -1
- data/test/rules_tests.rb +1 -1
- data/test/schemas_tests.rb +1 -1
- data/test/sequences_tests.rb +1 -1
- data/test/tables_tests.rb +16 -2
- data/test/tablespace_tests.rb +1 -1
- data/test/test_helper.rb +18 -3
- data/test/text_search_tests.rb +7 -7
- data/test/trigger_tests.rb +1 -1
- data/test/vacuum_tests.rb +39 -0
- metadata +38 -2
data/test/constraints_tests.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
$: << File.dirname(__FILE__)
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
|
-
class ConstraintTests <
|
5
|
+
class ConstraintTests < MiniTest::Unit::TestCase
|
6
6
|
include PostgreSQLExtensionsTestHelper
|
7
7
|
|
8
8
|
def setup
|
@@ -250,4 +250,110 @@ EOF
|
|
250
250
|
%{ALTER TABLE "foo" ADD EXCLUDE (length(name) WITH =) WITH (FILLFACTOR=10) USING INDEX TABLESPACE "fubar";}
|
251
251
|
], statements)
|
252
252
|
end
|
253
|
+
|
254
|
+
def test_primary_key_in_column_definition
|
255
|
+
Mig.create_table('foo', :id => false) do |t|
|
256
|
+
t.integer :foo_id, :primary_key => true
|
257
|
+
end
|
258
|
+
|
259
|
+
Mig.create_table('foo', :id => false) do |t|
|
260
|
+
t.integer :foo_id, :primary_key => {
|
261
|
+
:tablespace => 'fubar',
|
262
|
+
:index_parameters => 'FILLFACTOR=10'
|
263
|
+
}
|
264
|
+
end
|
265
|
+
|
266
|
+
assert_equal([
|
267
|
+
%{CREATE TABLE "foo" (
|
268
|
+
"foo_id" integer,
|
269
|
+
PRIMARY KEY ("foo_id")
|
270
|
+
);},
|
271
|
+
|
272
|
+
%{CREATE TABLE "foo" (
|
273
|
+
"foo_id" integer,
|
274
|
+
PRIMARY KEY ("foo_id") WITH (FILLFACTOR=10) USING INDEX TABLESPACE "fubar"
|
275
|
+
);}], statements)
|
276
|
+
end
|
277
|
+
|
278
|
+
|
279
|
+
def test_primary_key_in_table_definition
|
280
|
+
Mig.create_table('foo', :id => false) do |t|
|
281
|
+
t.integer :foo_id
|
282
|
+
t.primary_key_constraint :foo_id
|
283
|
+
end
|
284
|
+
|
285
|
+
Mig.create_table('foo', :id => false) do |t|
|
286
|
+
t.integer :foo_id
|
287
|
+
t.primary_key_constraint :foo_id, {
|
288
|
+
:tablespace => 'fubar',
|
289
|
+
:index_parameters => 'FILLFACTOR=10'
|
290
|
+
}
|
291
|
+
end
|
292
|
+
|
293
|
+
Mig.create_table('foo', :id => false) do |t|
|
294
|
+
t.integer :foo_id
|
295
|
+
t.integer :bar_id
|
296
|
+
t.primary_key_constraint [ :foo_id, :bar_id ], {
|
297
|
+
:tablespace => 'fubar',
|
298
|
+
:index_parameters => 'FILLFACTOR=10'
|
299
|
+
}
|
300
|
+
end
|
301
|
+
|
302
|
+
assert_equal([
|
303
|
+
%{CREATE TABLE "foo" (
|
304
|
+
"foo_id" integer,
|
305
|
+
PRIMARY KEY ("foo_id")
|
306
|
+
);},
|
307
|
+
|
308
|
+
%{CREATE TABLE "foo" (
|
309
|
+
"foo_id" integer,
|
310
|
+
PRIMARY KEY ("foo_id") WITH (FILLFACTOR=10) USING INDEX TABLESPACE "fubar"
|
311
|
+
);},
|
312
|
+
|
313
|
+
%{CREATE TABLE "foo" (
|
314
|
+
"foo_id" integer,
|
315
|
+
"bar_id" integer,
|
316
|
+
PRIMARY KEY ("foo_id", "bar_id") WITH (FILLFACTOR=10) USING INDEX TABLESPACE "fubar"
|
317
|
+
);}], statements)
|
318
|
+
end
|
319
|
+
|
320
|
+
def test_add_primary_key
|
321
|
+
Mig.add_primary_key(:foo, :bar_id)
|
322
|
+
Mig.add_primary_key(:foo, [ :bar_id, :baz_id ])
|
323
|
+
Mig.add_primary_key(:foo, :bar_id, :name => 'foo_pk')
|
324
|
+
Mig.add_primary_key(:foo, :bar_id, :tablespace => 'fubar', :index_parameters => 'FILLFACTOR=10')
|
325
|
+
|
326
|
+
assert_equal([
|
327
|
+
%{ALTER TABLE "foo" ADD PRIMARY KEY ("bar_id");},
|
328
|
+
%{ALTER TABLE "foo" ADD PRIMARY KEY ("bar_id", "baz_id");},
|
329
|
+
%{ALTER TABLE "foo" ADD CONSTRAINT "foo_pk" PRIMARY KEY ("bar_id");},
|
330
|
+
%{ALTER TABLE "foo" ADD PRIMARY KEY ("bar_id") WITH (FILLFACTOR=10) USING INDEX TABLESPACE "fubar";}
|
331
|
+
], statements)
|
332
|
+
end
|
333
|
+
|
334
|
+
def test_not_valid
|
335
|
+
Mig.add_check_constraint(:foo, 'length(name) < 100', :not_valid => true)
|
336
|
+
Mig.add_foreign_key(:foo, :bar_id, :bar, :not_valid => true)
|
337
|
+
|
338
|
+
assert_equal([
|
339
|
+
"ALTER TABLE \"foo\" ADD CHECK (length(name) < 100) NOT VALID;",
|
340
|
+
"ALTER TABLE \"foo\" ADD FOREIGN KEY (\"bar_id\") REFERENCES \"bar\" NOT VALID;"
|
341
|
+
], statements)
|
342
|
+
end
|
343
|
+
|
344
|
+
def test_validate_constraint
|
345
|
+
Mig.validate_constraint(:foo, :foo_constraint)
|
346
|
+
|
347
|
+
assert_equal([
|
348
|
+
"ALTER TABLE \"foo\" VALIDATE CONSTRAINT \"foo_constraint\";"
|
349
|
+
], statements)
|
350
|
+
end
|
351
|
+
|
352
|
+
def test_no_inherit
|
353
|
+
Mig.add_check_constraint(:foo, 'length(name) < 100', :no_inherit => true)
|
354
|
+
|
355
|
+
assert_equal([
|
356
|
+
"ALTER TABLE \"foo\" ADD CHECK (length(name) < 100) NO INHERIT;",
|
357
|
+
], statements)
|
358
|
+
end
|
253
359
|
end
|
data/test/extensions_tests.rb
CHANGED
@@ -2,10 +2,12 @@
|
|
2
2
|
$: << File.dirname(__FILE__)
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
|
-
class ExtensionsTests <
|
5
|
+
class ExtensionsTests < MiniTest::Unit::TestCase
|
6
6
|
include PostgreSQLExtensionsTestHelper
|
7
7
|
|
8
8
|
def test_create_extension
|
9
|
+
skip if !ActiveRecord::PostgreSQLExtensions::Features.extensions?
|
10
|
+
|
9
11
|
ARBC.create_extension(:foo)
|
10
12
|
ARBC.create_extension(:foo, :if_not_exists => true)
|
11
13
|
ARBC.create_extension(:foo, :schema => :bar)
|
@@ -22,6 +24,8 @@ class ExtensionsTests < Test::Unit::TestCase
|
|
22
24
|
end
|
23
25
|
|
24
26
|
def test_drop_extension
|
27
|
+
skip if !ActiveRecord::PostgreSQLExtensions::Features.extensions?
|
28
|
+
|
25
29
|
ARBC.drop_extension(:foo)
|
26
30
|
ARBC.drop_extension(:foo, :if_exists => true)
|
27
31
|
ARBC.drop_extension(:foo, :cascade => true)
|
@@ -36,6 +40,8 @@ class ExtensionsTests < Test::Unit::TestCase
|
|
36
40
|
end
|
37
41
|
|
38
42
|
def test_update_extension
|
43
|
+
skip if !ActiveRecord::PostgreSQLExtensions::Features.extensions?
|
44
|
+
|
39
45
|
ARBC.update_extension(:foo)
|
40
46
|
ARBC.update_extension(:foo, '2.0.0')
|
41
47
|
|
@@ -46,6 +52,8 @@ class ExtensionsTests < Test::Unit::TestCase
|
|
46
52
|
end
|
47
53
|
|
48
54
|
def test_update_schema
|
55
|
+
skip if !ActiveRecord::PostgreSQLExtensions::Features.extensions?
|
56
|
+
|
49
57
|
ARBC.alter_extension_schema(:foo, :bar)
|
50
58
|
|
51
59
|
assert_equal([
|
@@ -54,12 +62,16 @@ class ExtensionsTests < Test::Unit::TestCase
|
|
54
62
|
end
|
55
63
|
|
56
64
|
def test_alter_extension_empty
|
65
|
+
skip if !ActiveRecord::PostgreSQLExtensions::Features.extensions?
|
66
|
+
|
57
67
|
ARBC.alter_extension(:foo)
|
58
68
|
|
59
69
|
assert_equal([], statements)
|
60
70
|
end
|
61
71
|
|
62
72
|
def test_alter_extension_regular_options_with_hashes
|
73
|
+
skip if !ActiveRecord::PostgreSQLExtensions::Features.extensions?
|
74
|
+
|
63
75
|
ARBC.alter_extension(:foo, {
|
64
76
|
:collation => :bar,
|
65
77
|
:conversion => :bar,
|
@@ -174,6 +186,8 @@ class ExtensionsTests < Test::Unit::TestCase
|
|
174
186
|
end
|
175
187
|
|
176
188
|
def test_alter_extension_regular_options_with_block
|
189
|
+
skip if !ActiveRecord::PostgreSQLExtensions::Features.extensions?
|
190
|
+
|
177
191
|
ARBC.alter_extension(:foo) do |e|
|
178
192
|
e.drop_collation :bar
|
179
193
|
e.add_conversion :bar
|
@@ -188,6 +202,8 @@ ALTER EXTENSION "foo" ADD DOMAIN "bar";}
|
|
188
202
|
end
|
189
203
|
|
190
204
|
def test_alter_extension_cast_option
|
205
|
+
skip if !ActiveRecord::PostgreSQLExtensions::Features.extensions?
|
206
|
+
|
191
207
|
ARBC.alter_extension(:foo) do |e|
|
192
208
|
e.cast :hello => :world
|
193
209
|
e.cast [ :hello, :world ]
|
@@ -202,6 +218,8 @@ ALTER EXTENSION "foo" ADD CAST ("hello" AS "world");}
|
|
202
218
|
end
|
203
219
|
|
204
220
|
def test_alter_extension_aggregate_option
|
221
|
+
skip if !ActiveRecord::PostgreSQLExtensions::Features.extensions?
|
222
|
+
|
205
223
|
ARBC.alter_extension(:foo) do |e|
|
206
224
|
e.aggregate :name => :bar, :types => %w{ type_a type_b type_c }
|
207
225
|
e.aggregate :bar, :type_a, :type_b, :type_c
|
@@ -214,6 +232,8 @@ ALTER EXTENSION "foo" ADD AGGREGATE "bar" ("type_a", "type_b", "type_c");}
|
|
214
232
|
end
|
215
233
|
|
216
234
|
def test_alter_extension_operator_option
|
235
|
+
skip if !ActiveRecord::PostgreSQLExtensions::Features.extensions?
|
236
|
+
|
217
237
|
ARBC.alter_extension(:foo) do |e|
|
218
238
|
e.operator :bar, :hello, :world
|
219
239
|
e.operator [ :bar, :hello, :world ]
|
@@ -228,6 +248,8 @@ ALTER EXTENSION "foo" ADD OPERATOR "bar" ("hello", "world");}
|
|
228
248
|
end
|
229
249
|
|
230
250
|
def test_alter_extension_operator_class_option
|
251
|
+
skip if !ActiveRecord::PostgreSQLExtensions::Features.extensions?
|
252
|
+
|
231
253
|
ARBC.alter_extension(:foo) do |e|
|
232
254
|
e.operator_class :hello => :world
|
233
255
|
e.operator_class :hello, :world
|
@@ -244,6 +266,8 @@ ALTER EXTENSION "foo" ADD OPERATOR CLASS "hello" USING "world");}
|
|
244
266
|
end
|
245
267
|
|
246
268
|
def test_alter_extension_operator_family_option
|
269
|
+
skip if !ActiveRecord::PostgreSQLExtensions::Features.extensions?
|
270
|
+
|
247
271
|
ARBC.alter_extension(:foo) do |e|
|
248
272
|
e.operator_family :hello => :world
|
249
273
|
e.operator_family :hello, :world
|
@@ -260,6 +284,8 @@ ALTER EXTENSION "foo" ADD OPERATOR FAMILY "hello" USING "world");}
|
|
260
284
|
end
|
261
285
|
|
262
286
|
def test_alter_extension_function_option
|
287
|
+
skip if !ActiveRecord::PostgreSQLExtensions::Features.extensions?
|
288
|
+
|
263
289
|
ARBC.alter_extension(:foo) do |e|
|
264
290
|
e.function :bar, "VARIADIC hello world"
|
265
291
|
e.function [ :bar, "VARIADIC hello world" ]
|
data/test/functions_tests.rb
CHANGED
data/test/geometry_tests.rb
CHANGED
@@ -2,251 +2,277 @@
|
|
2
2
|
$: << File.dirname(__FILE__)
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
|
-
if ActiveRecord::PostgreSQLExtensions::PostGIS.VERSION
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
5
|
+
if (ActiveRecord::PostgreSQLExtensions::PostGIS.VERSION[:lib] rescue '') >= '2.0'
|
6
|
+
class GeometryTests < MiniTest::Unit::TestCase
|
7
|
+
include PostgreSQLExtensionsTestHelper
|
8
|
+
|
9
|
+
def test_create_geometry
|
10
|
+
skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
|
11
|
+
|
12
|
+
Mig.create_table(:foo) do |t|
|
13
|
+
t.geometry :the_geom, :srid => 4326
|
14
|
+
end
|
15
|
+
|
16
|
+
assert_equal([
|
17
|
+
%{CREATE TABLE "foo" (
|
17
18
|
"id" serial primary key,
|
18
19
|
"the_geom" geometry(GEOMETRY, 4326)
|
19
20
|
);},
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
|
22
|
+
], statements)
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
def test_create_geometry_with_spatial
|
26
|
+
skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
|
27
|
+
|
28
|
+
Mig.create_table(:foo) do |t|
|
29
|
+
t.spatial :the_geom, :srid => 4326
|
30
|
+
end
|
28
31
|
|
29
|
-
|
30
|
-
|
32
|
+
assert_equal([
|
33
|
+
%{CREATE TABLE "foo" (
|
31
34
|
"id" serial primary key,
|
32
35
|
"the_geom" geometry(GEOMETRY, 4326)
|
33
36
|
);},
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
|
38
|
+
], statements)
|
39
|
+
end
|
37
40
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
41
|
+
def test_create_geometry_with_spatial_and_spatial_column_type
|
42
|
+
skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
|
43
|
+
|
44
|
+
Mig.create_table(:foo) do |t|
|
45
|
+
t.spatial :the_geom, :srid => 4326, :spatial_column_type => :geography
|
46
|
+
end
|
42
47
|
|
43
|
-
|
44
|
-
|
48
|
+
assert_equal([
|
49
|
+
%{CREATE TABLE "foo" (
|
45
50
|
"id" serial primary key,
|
46
51
|
"the_geom" geography(GEOMETRY, 4326)
|
47
52
|
);},
|
48
|
-
|
49
|
-
|
50
|
-
|
53
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
|
54
|
+
], statements)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_create_geography
|
58
|
+
skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
|
51
59
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end
|
60
|
+
Mig.create_table(:foo) do |t|
|
61
|
+
t.geography :the_geom, :srid => 4326
|
62
|
+
end
|
56
63
|
|
57
|
-
|
58
|
-
|
64
|
+
assert_equal([
|
65
|
+
%{CREATE TABLE "foo" (
|
59
66
|
"id" serial primary key,
|
60
67
|
"the_geom" geography(GEOMETRY, 4326)
|
61
68
|
);},
|
62
|
-
|
63
|
-
|
64
|
-
|
69
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
|
70
|
+
], statements)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_create_geometry_with_force_constraints
|
74
|
+
skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
|
65
75
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
end
|
76
|
+
Mig.create_table(:foo) do |t|
|
77
|
+
t.geometry :the_geom, :srid => 4326, :force_constraints => true
|
78
|
+
end
|
70
79
|
|
71
|
-
|
72
|
-
|
80
|
+
assert_equal([
|
81
|
+
%{CREATE TABLE "foo" (
|
73
82
|
"id" serial primary key,
|
74
83
|
"the_geom" geometry(GEOMETRY, 4326),
|
75
84
|
CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
|
76
85
|
CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
|
77
86
|
);},
|
78
|
-
|
79
|
-
|
80
|
-
|
87
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
|
88
|
+
], statements)
|
89
|
+
end
|
81
90
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
91
|
+
def test_create_geometry_with_schema
|
92
|
+
Mig.create_table('shabba.foo') do |t|
|
93
|
+
t.geometry :the_geom, :srid => 4326
|
94
|
+
end
|
86
95
|
|
87
|
-
|
88
|
-
|
96
|
+
assert_equal([
|
97
|
+
%{CREATE TABLE "shabba"."foo" (
|
89
98
|
"id" serial primary key,
|
90
99
|
"the_geom" geometry(GEOMETRY, 4326)
|
91
100
|
);},
|
92
|
-
|
93
|
-
|
94
|
-
|
101
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON "shabba"."foo" USING "gist"("the_geom");}
|
102
|
+
], statements)
|
103
|
+
end
|
95
104
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
105
|
+
def test_create_geometry_with_not_null
|
106
|
+
skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
|
107
|
+
|
108
|
+
Mig.create_table(:foo) do |t|
|
109
|
+
t.geometry :the_geom, :srid => 4326, :null => false
|
110
|
+
end
|
100
111
|
|
101
|
-
|
102
|
-
|
112
|
+
assert_equal([
|
113
|
+
%{CREATE TABLE "foo" (
|
103
114
|
"id" serial primary key,
|
104
115
|
"the_geom" geometry(GEOMETRY, 4326) NOT NULL
|
105
116
|
);},
|
106
|
-
|
107
|
-
|
108
|
-
|
117
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
|
118
|
+
], statements)
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_create_geometry_with_null_and_type
|
122
|
+
skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
|
109
123
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
end
|
124
|
+
Mig.create_table(:foo) do |t|
|
125
|
+
t.geometry :the_geom, :srid => 4326, :geometry_type => :polygon
|
126
|
+
end
|
114
127
|
|
115
|
-
|
116
|
-
|
128
|
+
assert_equal([
|
129
|
+
%{CREATE TABLE "foo" (
|
117
130
|
"id" serial primary key,
|
118
131
|
"the_geom" geometry(POLYGON, 4326)
|
119
132
|
);},
|
120
|
-
|
121
|
-
|
122
|
-
end
|
133
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
|
134
|
+
], statements)
|
123
135
|
end
|
124
|
-
|
125
|
-
|
126
|
-
|
136
|
+
end
|
137
|
+
else
|
138
|
+
class GeometryTests < Test::Unit::TestCase
|
139
|
+
include PostgreSQLExtensionsTestHelper
|
140
|
+
|
141
|
+
def test_create_geometry
|
142
|
+
skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
|
127
143
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
end
|
144
|
+
Mig.create_table(:foo) do |t|
|
145
|
+
t.geometry :the_geom, :srid => 4326
|
146
|
+
end
|
132
147
|
|
133
|
-
|
134
|
-
|
148
|
+
assert_equal([
|
149
|
+
%{CREATE TABLE "foo" (
|
135
150
|
"id" serial primary key,
|
136
151
|
"the_geom" geometry,
|
137
152
|
CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
|
138
153
|
CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
|
139
154
|
);},
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
155
|
+
%{DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'public' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';},
|
156
|
+
%{INSERT INTO "geometry_columns" VALUES ('', 'public', 'foo', 'the_geom', 2, 4326, 'GEOMETRY');},
|
157
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
|
158
|
+
], statements)
|
159
|
+
end
|
145
160
|
|
146
|
-
|
147
|
-
|
148
|
-
t.spatial :the_geom, :srid => 4326
|
149
|
-
end
|
161
|
+
def test_create_geometry_with_spatial
|
162
|
+
skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
|
150
163
|
|
151
|
-
|
152
|
-
|
164
|
+
Mig.create_table(:foo) do |t|
|
165
|
+
t.spatial :the_geom, :srid => 4326
|
166
|
+
end
|
167
|
+
|
168
|
+
assert_equal([
|
169
|
+
%{CREATE TABLE "foo" (
|
153
170
|
"id" serial primary key,
|
154
171
|
"the_geom" geometry,
|
155
172
|
CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
|
156
173
|
CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
|
157
174
|
);},
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
175
|
+
%{DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'public' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';},
|
176
|
+
%{INSERT INTO "geometry_columns" VALUES ('', 'public', 'foo', 'the_geom', 2, 4326, 'GEOMETRY');},
|
177
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
|
178
|
+
], statements)
|
179
|
+
end
|
163
180
|
|
164
|
-
|
165
|
-
|
166
|
-
t.spatial :the_geom, :srid => 4326, :spatial_column_type => :geography
|
167
|
-
end
|
181
|
+
def test_create_geometry_with_spatial_and_spatial_column_type
|
182
|
+
skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
|
168
183
|
|
169
|
-
|
170
|
-
|
184
|
+
Mig.create_table(:foo) do |t|
|
185
|
+
t.spatial :the_geom, :srid => 4326, :spatial_column_type => :geography
|
186
|
+
end
|
187
|
+
|
188
|
+
assert_equal([
|
189
|
+
%{CREATE TABLE "foo" (
|
171
190
|
"id" serial primary key,
|
172
191
|
"the_geom" geography,
|
173
192
|
CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
|
174
193
|
CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
|
175
194
|
);},
|
176
|
-
|
177
|
-
|
178
|
-
|
195
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
|
196
|
+
], statements)
|
197
|
+
end
|
179
198
|
|
180
|
-
|
181
|
-
|
182
|
-
t.geography :the_geom, :srid => 4326
|
183
|
-
end
|
199
|
+
def test_create_geography
|
200
|
+
skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
|
184
201
|
|
185
|
-
|
186
|
-
|
202
|
+
Mig.create_table(:foo) do |t|
|
203
|
+
t.geography :the_geom, :srid => 4326
|
204
|
+
end
|
205
|
+
|
206
|
+
assert_equal([
|
207
|
+
%{CREATE TABLE "foo" (
|
187
208
|
"id" serial primary key,
|
188
209
|
"the_geom" geography,
|
189
210
|
CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
|
190
211
|
CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
|
191
212
|
);},
|
192
|
-
|
193
|
-
|
194
|
-
|
213
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
|
214
|
+
], statements)
|
215
|
+
end
|
195
216
|
|
196
|
-
|
197
|
-
|
198
|
-
t.geometry :the_geom, :srid => 4326
|
199
|
-
end
|
217
|
+
def test_create_geometry_with_schema
|
218
|
+
skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
|
200
219
|
|
201
|
-
|
202
|
-
|
220
|
+
Mig.create_table('shabba.foo') do |t|
|
221
|
+
t.geometry :the_geom, :srid => 4326
|
222
|
+
end
|
223
|
+
|
224
|
+
assert_equal([
|
225
|
+
%{CREATE TABLE "shabba"."foo" (
|
203
226
|
"id" serial primary key,
|
204
227
|
"the_geom" geometry,
|
205
228
|
CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
|
206
229
|
CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
|
207
230
|
);},
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
231
|
+
%{DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'shabba' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';},
|
232
|
+
%{INSERT INTO "geometry_columns" VALUES ('', 'shabba', 'foo', 'the_geom', 2, 4326, 'GEOMETRY');},
|
233
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON "shabba"."foo" USING "gist"("the_geom");}
|
234
|
+
], statements)
|
235
|
+
end
|
213
236
|
|
214
|
-
|
215
|
-
|
216
|
-
t.geometry :the_geom, :srid => 4326, :null => false
|
217
|
-
end
|
237
|
+
def test_create_geometry_with_not_null
|
238
|
+
skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
|
218
239
|
|
219
|
-
|
220
|
-
|
240
|
+
Mig.create_table(:foo) do |t|
|
241
|
+
t.geometry :the_geom, :srid => 4326, :null => false
|
242
|
+
end
|
243
|
+
|
244
|
+
assert_equal([
|
245
|
+
%{CREATE TABLE "foo" (
|
221
246
|
"id" serial primary key,
|
222
247
|
"the_geom" geometry NOT NULL,
|
223
248
|
CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
|
224
249
|
CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
|
225
250
|
);},
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
251
|
+
%{DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'public' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';},
|
252
|
+
%{INSERT INTO "geometry_columns" VALUES ('', 'public', 'foo', 'the_geom', 2, 4326, 'GEOMETRY');},
|
253
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
|
254
|
+
], statements)
|
255
|
+
end
|
231
256
|
|
232
|
-
|
233
|
-
|
234
|
-
t.geometry :the_geom, :srid => 4326, :geometry_type => :polygon
|
235
|
-
end
|
257
|
+
def test_create_geometry_with_null_and_type
|
258
|
+
skip if !ActiveRecord::PostgreSQLExtensions::Features.postgis?
|
236
259
|
|
237
|
-
|
238
|
-
|
260
|
+
Mig.create_table(:foo) do |t|
|
261
|
+
t.geometry :the_geom, :srid => 4326, :geometry_type => :polygon
|
262
|
+
end
|
263
|
+
|
264
|
+
assert_equal([
|
265
|
+
%{CREATE TABLE "foo" (
|
239
266
|
"id" serial primary key,
|
240
267
|
"the_geom" geometry,
|
241
268
|
CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
|
242
269
|
CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2),
|
243
270
|
CONSTRAINT "enforce_geotype_the_geom" CHECK (geometrytype("the_geom") = 'POLYGON'::text OR "the_geom" IS NULL)
|
244
271
|
);},
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
end
|
272
|
+
%{DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'public' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';},
|
273
|
+
%{INSERT INTO "geometry_columns" VALUES ('', 'public', 'foo', 'the_geom', 2, 4326, 'POLYGON');},
|
274
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
|
275
|
+
], statements)
|
250
276
|
end
|
251
277
|
end
|
252
278
|
end
|