activerecord-postgresql-extensions 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/MIT-LICENSE +1 -1
- data/lib/active_record/postgresql_extensions/constraints.rb +10 -15
- data/lib/active_record/postgresql_extensions/geometry.rb +198 -134
- data/lib/active_record/postgresql_extensions/tables.rb +24 -0
- data/lib/active_record/postgresql_extensions/version.rb +1 -1
- data/test/constraints_tests.rb +27 -0
- data/test/geometry_tests.rb +2 -374
- data/test/geometry_tests_legacy_postgis.rb +338 -0
- data/test/geometry_tests_modern_postgis.rb +279 -0
- metadata +7 -3
@@ -0,0 +1,338 @@
|
|
1
|
+
|
2
|
+
class GeometryTests < PostgreSQLExtensionsTestCase
|
3
|
+
def test_create_geometry
|
4
|
+
Mig.create_table(:foo) do |t|
|
5
|
+
t.geometry :the_geom, :srid => 4326
|
6
|
+
end
|
7
|
+
|
8
|
+
expected = []
|
9
|
+
|
10
|
+
expected << strip_heredoc(<<-SQL)
|
11
|
+
CREATE TABLE "foo" (
|
12
|
+
"id" serial primary key,
|
13
|
+
"the_geom" geometry,
|
14
|
+
CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
|
15
|
+
CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
|
16
|
+
);
|
17
|
+
SQL
|
18
|
+
|
19
|
+
expected << strip_heredoc(<<-SQL)
|
20
|
+
DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'public' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';
|
21
|
+
SQL
|
22
|
+
|
23
|
+
expected << strip_heredoc(<<-SQL)
|
24
|
+
INSERT INTO "geometry_columns" VALUES ('', 'public', 'foo', 'the_geom', 2, 4326, 'GEOMETRY');
|
25
|
+
SQL
|
26
|
+
|
27
|
+
expected << strip_heredoc(<<-SQL)
|
28
|
+
CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");
|
29
|
+
SQL
|
30
|
+
|
31
|
+
assert_equal(expected, statements)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_create_geometry_with_spatial
|
35
|
+
Mig.create_table(:foo) do |t|
|
36
|
+
t.spatial :the_geom, :srid => 4326
|
37
|
+
end
|
38
|
+
|
39
|
+
expected = []
|
40
|
+
|
41
|
+
expected << strip_heredoc(<<-SQL)
|
42
|
+
CREATE TABLE "foo" (
|
43
|
+
"id" serial primary key,
|
44
|
+
"the_geom" geometry,
|
45
|
+
CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
|
46
|
+
CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
|
47
|
+
);
|
48
|
+
SQL
|
49
|
+
|
50
|
+
expected << strip_heredoc(<<-SQL)
|
51
|
+
DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'public' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';
|
52
|
+
SQL
|
53
|
+
|
54
|
+
expected << strip_heredoc(<<-SQL)
|
55
|
+
INSERT INTO "geometry_columns" VALUES ('', 'public', 'foo', 'the_geom', 2, 4326, 'GEOMETRY');
|
56
|
+
SQL
|
57
|
+
|
58
|
+
expected << strip_heredoc(<<-SQL)
|
59
|
+
CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");
|
60
|
+
SQL
|
61
|
+
|
62
|
+
assert_equal(expected, statements)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_create_geometry_with_spatial_and_spatial_column_type
|
66
|
+
Mig.create_table(:foo) do |t|
|
67
|
+
t.spatial :the_geom, :srid => 4326, :spatial_column_type => :geography
|
68
|
+
end
|
69
|
+
|
70
|
+
expected = []
|
71
|
+
|
72
|
+
expected << strip_heredoc(<<-SQL)
|
73
|
+
CREATE TABLE "foo" (
|
74
|
+
"id" serial primary key,
|
75
|
+
"the_geom" geography,
|
76
|
+
CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
|
77
|
+
CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
|
78
|
+
);
|
79
|
+
SQL
|
80
|
+
|
81
|
+
expected << strip_heredoc(<<-SQL)
|
82
|
+
CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");
|
83
|
+
SQL
|
84
|
+
|
85
|
+
assert_equal(expected, statements)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_create_geography
|
89
|
+
Mig.create_table(:foo) do |t|
|
90
|
+
t.geography :the_geom, :srid => 4326
|
91
|
+
end
|
92
|
+
|
93
|
+
expected = []
|
94
|
+
|
95
|
+
expected << strip_heredoc(<<-SQL)
|
96
|
+
CREATE TABLE "foo" (
|
97
|
+
"id" serial primary key,
|
98
|
+
"the_geom" geography,
|
99
|
+
CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
|
100
|
+
CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
|
101
|
+
);
|
102
|
+
SQL
|
103
|
+
|
104
|
+
expected << strip_heredoc(<<-SQL)
|
105
|
+
CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");
|
106
|
+
SQL
|
107
|
+
|
108
|
+
assert_equal(expected, statements)
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_create_geometry_with_schema
|
112
|
+
Mig.create_table('shabba.foo') do |t|
|
113
|
+
t.geometry :the_geom, :srid => 4326
|
114
|
+
end
|
115
|
+
|
116
|
+
expected = []
|
117
|
+
|
118
|
+
expected << strip_heredoc(<<-SQL)
|
119
|
+
CREATE TABLE "shabba"."foo" (
|
120
|
+
"id" serial primary key,
|
121
|
+
"the_geom" geometry,
|
122
|
+
CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
|
123
|
+
CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
|
124
|
+
);
|
125
|
+
SQL
|
126
|
+
|
127
|
+
expected << strip_heredoc(<<-SQL)
|
128
|
+
DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'shabba' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';
|
129
|
+
SQL
|
130
|
+
|
131
|
+
expected << strip_heredoc(<<-SQL)
|
132
|
+
INSERT INTO "geometry_columns" VALUES ('', 'shabba', 'foo', 'the_geom', 2, 4326, 'GEOMETRY');
|
133
|
+
SQL
|
134
|
+
|
135
|
+
expected << strip_heredoc(<<-SQL)
|
136
|
+
CREATE INDEX "foo_the_geom_gist_index" ON "shabba"."foo" USING "gist"("the_geom");
|
137
|
+
SQL
|
138
|
+
|
139
|
+
assert_equal(expected, statements)
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_create_geometry_with_not_null
|
143
|
+
Mig.create_table(:foo) do |t|
|
144
|
+
t.geometry :the_geom, :srid => 4326, :null => false
|
145
|
+
end
|
146
|
+
|
147
|
+
expected = []
|
148
|
+
|
149
|
+
expected << strip_heredoc(<<-SQL)
|
150
|
+
CREATE TABLE "foo" (
|
151
|
+
"id" serial primary key,
|
152
|
+
"the_geom" geometry NOT NULL,
|
153
|
+
CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
|
154
|
+
CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
|
155
|
+
);
|
156
|
+
SQL
|
157
|
+
|
158
|
+
expected << strip_heredoc(<<-SQL)
|
159
|
+
DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'public' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';
|
160
|
+
SQL
|
161
|
+
|
162
|
+
expected << strip_heredoc(<<-SQL)
|
163
|
+
INSERT INTO "geometry_columns" VALUES ('', 'public', 'foo', 'the_geom', 2, 4326, 'GEOMETRY');
|
164
|
+
SQL
|
165
|
+
|
166
|
+
expected << strip_heredoc(<<-SQL)
|
167
|
+
CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");
|
168
|
+
SQL
|
169
|
+
|
170
|
+
assert_equal(expected, statements)
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_create_geometry_with_null_and_type
|
174
|
+
Mig.create_table(:foo) do |t|
|
175
|
+
t.geometry :the_geom, :srid => 4326, :geometry_type => :polygon
|
176
|
+
end
|
177
|
+
|
178
|
+
expected = []
|
179
|
+
|
180
|
+
expected << strip_heredoc(<<-SQL)
|
181
|
+
CREATE TABLE "foo" (
|
182
|
+
"id" serial primary key,
|
183
|
+
"the_geom" geometry,
|
184
|
+
CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
|
185
|
+
CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2),
|
186
|
+
CONSTRAINT "enforce_geotype_the_geom" CHECK (geometrytype("the_geom") = 'POLYGON'::text OR "the_geom" IS NULL)
|
187
|
+
);
|
188
|
+
SQL
|
189
|
+
|
190
|
+
expected << strip_heredoc(<<-SQL)
|
191
|
+
DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'public' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';
|
192
|
+
SQL
|
193
|
+
|
194
|
+
expected << strip_heredoc(<<-SQL)
|
195
|
+
INSERT INTO "geometry_columns" VALUES ('', 'public', 'foo', 'the_geom', 2, 4326, 'POLYGON');
|
196
|
+
SQL
|
197
|
+
|
198
|
+
expected << strip_heredoc(<<-SQL)
|
199
|
+
CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");
|
200
|
+
SQL
|
201
|
+
|
202
|
+
assert_equal(expected, statements)
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_change_table_add_geometry
|
206
|
+
Mig.change_table(:foo) do |t|
|
207
|
+
t.geometry :the_geom, :srid => 4326
|
208
|
+
end
|
209
|
+
|
210
|
+
expected = [
|
211
|
+
%{ALTER TABLE "foo" ADD COLUMN "the_geom" geometry},
|
212
|
+
%{ALTER TABLE "foo" ADD CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326));},
|
213
|
+
%{ALTER TABLE "foo" ADD CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2);},
|
214
|
+
%{DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'public' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';},
|
215
|
+
%{INSERT INTO "geometry_columns" VALUES ('', 'public', 'foo', 'the_geom', 2, 4326, 'GEOMETRY');},
|
216
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
|
217
|
+
]
|
218
|
+
|
219
|
+
assert_equal(expected, statements)
|
220
|
+
end
|
221
|
+
|
222
|
+
def test_change_table_add_geometry_with_spatial
|
223
|
+
Mig.change_table(:foo) do |t|
|
224
|
+
t.spatial :the_geom, :srid => 4326
|
225
|
+
end
|
226
|
+
|
227
|
+
expected = [
|
228
|
+
%{ALTER TABLE "foo" ADD COLUMN "the_geom" geometry},
|
229
|
+
%{ALTER TABLE "foo" ADD CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326));},
|
230
|
+
%{ALTER TABLE "foo" ADD CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2);},
|
231
|
+
%{DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'public' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';},
|
232
|
+
%{INSERT INTO "geometry_columns" VALUES ('', 'public', 'foo', 'the_geom', 2, 4326, 'GEOMETRY');},
|
233
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
|
234
|
+
]
|
235
|
+
|
236
|
+
assert_equal(expected, statements)
|
237
|
+
end
|
238
|
+
|
239
|
+
def test_change_table_geometry_with_spatial_and_spatial_column_type
|
240
|
+
Mig.change_table(:foo) do |t|
|
241
|
+
t.spatial :the_geom, :srid => 4326, :spatial_column_type => :geography
|
242
|
+
end
|
243
|
+
|
244
|
+
expected = [
|
245
|
+
%{ALTER TABLE "foo" ADD COLUMN "the_geom" geography},
|
246
|
+
%{ALTER TABLE "foo" ADD CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326));},
|
247
|
+
%{ALTER TABLE "foo" ADD CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2);},
|
248
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
|
249
|
+
]
|
250
|
+
|
251
|
+
assert_equal(expected, statements)
|
252
|
+
end
|
253
|
+
|
254
|
+
def test_change_table_geography
|
255
|
+
Mig.change_table(:foo) do |t|
|
256
|
+
t.geography :the_geom, :srid => 4326
|
257
|
+
end
|
258
|
+
|
259
|
+
expected = [
|
260
|
+
%{ALTER TABLE "foo" ADD COLUMN "the_geom" geography},
|
261
|
+
%{ALTER TABLE "foo" ADD CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326));},
|
262
|
+
%{ALTER TABLE "foo" ADD CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2);},
|
263
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
|
264
|
+
]
|
265
|
+
|
266
|
+
assert_equal(expected, statements)
|
267
|
+
end
|
268
|
+
|
269
|
+
def test_change_table_geometry_with_force_constraints
|
270
|
+
Mig.change_table(:foo) do |t|
|
271
|
+
t.geometry :the_geom, :srid => 4326, :force_constraints => true
|
272
|
+
end
|
273
|
+
|
274
|
+
expected = [
|
275
|
+
%{ALTER TABLE "foo" ADD COLUMN "the_geom" geometry},
|
276
|
+
%{ALTER TABLE "foo" ADD CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326));},
|
277
|
+
%{ALTER TABLE "foo" ADD CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2);},
|
278
|
+
%{DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'public' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';},
|
279
|
+
%{INSERT INTO "geometry_columns" VALUES ('', 'public', 'foo', 'the_geom', 2, 4326, 'GEOMETRY');},
|
280
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
|
281
|
+
]
|
282
|
+
|
283
|
+
assert_equal(expected, statements)
|
284
|
+
end
|
285
|
+
|
286
|
+
def test_change_table_geometry_with_schema
|
287
|
+
Mig.change_table('shabba.foo') do |t|
|
288
|
+
t.geometry :the_geom, :srid => 4326
|
289
|
+
end
|
290
|
+
|
291
|
+
expected = [
|
292
|
+
%{ALTER TABLE "shabba"."foo" ADD COLUMN "the_geom" geometry},
|
293
|
+
%{ALTER TABLE "shabba"."foo" ADD CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326));},
|
294
|
+
%{ALTER TABLE "shabba"."foo" ADD CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2);},
|
295
|
+
%{DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'shabba' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';},
|
296
|
+
%{INSERT INTO "geometry_columns" VALUES ('', 'shabba', 'foo', 'the_geom', 2, 4326, 'GEOMETRY');},
|
297
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON "shabba"."foo" USING "gist"("the_geom");}
|
298
|
+
]
|
299
|
+
|
300
|
+
assert_equal(expected, statements)
|
301
|
+
end
|
302
|
+
|
303
|
+
def test_change_table_geometry_with_not_null
|
304
|
+
Mig.change_table(:foo) do |t|
|
305
|
+
t.geometry :the_geom, :srid => 4326, :null => false
|
306
|
+
end
|
307
|
+
|
308
|
+
expected = [
|
309
|
+
%{ALTER TABLE "foo" ADD COLUMN "the_geom" geometry NOT NULL},
|
310
|
+
%{ALTER TABLE "foo" ADD CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326));},
|
311
|
+
%{ALTER TABLE "foo" ADD CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2);},
|
312
|
+
%{DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'public' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';},
|
313
|
+
%{INSERT INTO "geometry_columns" VALUES ('', 'public', 'foo', 'the_geom', 2, 4326, 'GEOMETRY');},
|
314
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
|
315
|
+
]
|
316
|
+
|
317
|
+
assert_equal(expected, statements)
|
318
|
+
end
|
319
|
+
|
320
|
+
def test_change_table_geometry_with_null_and_type
|
321
|
+
Mig.change_table(:foo) do |t|
|
322
|
+
t.geometry :the_geom, :srid => 4326, :geometry_type => :polygon
|
323
|
+
end
|
324
|
+
|
325
|
+
expected = [
|
326
|
+
%{ALTER TABLE "foo" ADD COLUMN "the_geom" geometry},
|
327
|
+
%{ALTER TABLE "foo" ADD CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326));},
|
328
|
+
%{ALTER TABLE "foo" ADD CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2);},
|
329
|
+
%{ALTER TABLE "foo" ADD CONSTRAINT "enforce_geotype_the_geom" CHECK (geometrytype("the_geom") = 'POLYGON'::text OR "the_geom" IS NULL);},
|
330
|
+
%{DELETE FROM "geometry_columns" WHERE f_table_catalog = '' AND f_table_schema = 'public' AND f_table_name = 'foo' AND f_geometry_column = 'the_geom';},
|
331
|
+
%{INSERT INTO "geometry_columns" VALUES ('', 'public', 'foo', 'the_geom', 2, 4326, 'POLYGON');},
|
332
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
|
333
|
+
]
|
334
|
+
|
335
|
+
assert_equal(expected, statements)
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
@@ -0,0 +1,279 @@
|
|
1
|
+
|
2
|
+
class GeometryTests < PostgreSQLExtensionsTestCase
|
3
|
+
def test_create_geometry
|
4
|
+
Mig.create_table(:foo) do |t|
|
5
|
+
t.geometry :the_geom, :srid => 4326
|
6
|
+
end
|
7
|
+
|
8
|
+
expected = []
|
9
|
+
|
10
|
+
expected << strip_heredoc(<<-SQL)
|
11
|
+
CREATE TABLE "foo" (
|
12
|
+
"id" serial primary key,
|
13
|
+
"the_geom" geometry(GEOMETRY, 4326)
|
14
|
+
);
|
15
|
+
SQL
|
16
|
+
|
17
|
+
expected << strip_heredoc(<<-SQL)
|
18
|
+
CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");
|
19
|
+
SQL
|
20
|
+
|
21
|
+
assert_equal(expected, statements)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_create_geometry_with_spatial
|
25
|
+
Mig.create_table(:foo) do |t|
|
26
|
+
t.spatial :the_geom, :srid => 4326
|
27
|
+
end
|
28
|
+
|
29
|
+
expected = []
|
30
|
+
|
31
|
+
expected << strip_heredoc(<<-SQL)
|
32
|
+
CREATE TABLE "foo" (
|
33
|
+
"id" serial primary key,
|
34
|
+
"the_geom" geometry(GEOMETRY, 4326)
|
35
|
+
);
|
36
|
+
SQL
|
37
|
+
|
38
|
+
expected << strip_heredoc(<<-SQL)
|
39
|
+
CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");
|
40
|
+
SQL
|
41
|
+
|
42
|
+
assert_equal(expected, statements)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_create_geometry_with_spatial_and_spatial_column_type
|
46
|
+
Mig.create_table(:foo) do |t|
|
47
|
+
t.spatial :the_geom, :srid => 4326, :spatial_column_type => :geography
|
48
|
+
end
|
49
|
+
|
50
|
+
expected = []
|
51
|
+
|
52
|
+
expected << strip_heredoc(<<-SQL)
|
53
|
+
CREATE TABLE "foo" (
|
54
|
+
"id" serial primary key,
|
55
|
+
"the_geom" geography(GEOMETRY, 4326)
|
56
|
+
);
|
57
|
+
SQL
|
58
|
+
|
59
|
+
expected << strip_heredoc(<<-SQL)
|
60
|
+
CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");
|
61
|
+
SQL
|
62
|
+
|
63
|
+
assert_equal(expected, statements)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_create_geography
|
67
|
+
Mig.create_table(:foo) do |t|
|
68
|
+
t.geography :the_geom, :srid => 4326
|
69
|
+
end
|
70
|
+
|
71
|
+
expected = []
|
72
|
+
|
73
|
+
expected << strip_heredoc(<<-SQL)
|
74
|
+
CREATE TABLE "foo" (
|
75
|
+
"id" serial primary key,
|
76
|
+
"the_geom" geography(GEOMETRY, 4326)
|
77
|
+
);
|
78
|
+
SQL
|
79
|
+
|
80
|
+
expected << strip_heredoc(<<-SQL)
|
81
|
+
CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");
|
82
|
+
SQL
|
83
|
+
|
84
|
+
assert_equal(expected, statements)
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_create_geometry_with_force_constraints
|
88
|
+
Mig.create_table(:foo) do |t|
|
89
|
+
t.geometry :the_geom, :srid => 4326, :force_constraints => true
|
90
|
+
end
|
91
|
+
|
92
|
+
expected = []
|
93
|
+
|
94
|
+
expected << strip_heredoc(<<-SQL)
|
95
|
+
CREATE TABLE "foo" (
|
96
|
+
"id" serial primary key,
|
97
|
+
"the_geom" geometry(GEOMETRY, 4326),
|
98
|
+
CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326)),
|
99
|
+
CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2)
|
100
|
+
);
|
101
|
+
SQL
|
102
|
+
|
103
|
+
expected << strip_heredoc(<<-SQL)
|
104
|
+
CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");
|
105
|
+
SQL
|
106
|
+
|
107
|
+
assert_equal(expected, statements)
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_create_geometry_with_schema
|
111
|
+
Mig.create_table('shabba.foo') do |t|
|
112
|
+
t.geometry :the_geom, :srid => 4326
|
113
|
+
end
|
114
|
+
|
115
|
+
expected = []
|
116
|
+
|
117
|
+
expected << strip_heredoc(<<-SQL)
|
118
|
+
CREATE TABLE "shabba"."foo" (
|
119
|
+
"id" serial primary key,
|
120
|
+
"the_geom" geometry(GEOMETRY, 4326)
|
121
|
+
);
|
122
|
+
SQL
|
123
|
+
|
124
|
+
expected << strip_heredoc(<<-SQL)
|
125
|
+
CREATE INDEX "foo_the_geom_gist_index" ON "shabba"."foo" USING "gist"("the_geom");
|
126
|
+
SQL
|
127
|
+
|
128
|
+
assert_equal(expected, statements)
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_create_geometry_with_not_null
|
132
|
+
Mig.create_table(:foo) do |t|
|
133
|
+
t.geometry :the_geom, :srid => 4326, :null => false
|
134
|
+
end
|
135
|
+
|
136
|
+
expected = []
|
137
|
+
|
138
|
+
expected << strip_heredoc(<<-SQL)
|
139
|
+
CREATE TABLE "foo" (
|
140
|
+
"id" serial primary key,
|
141
|
+
"the_geom" geometry(GEOMETRY, 4326) NOT NULL
|
142
|
+
);
|
143
|
+
SQL
|
144
|
+
|
145
|
+
expected << strip_heredoc(<<-SQL)
|
146
|
+
CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");
|
147
|
+
SQL
|
148
|
+
|
149
|
+
assert_equal(expected, statements)
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_create_geometry_with_null_and_type
|
153
|
+
Mig.create_table(:foo) do |t|
|
154
|
+
t.geometry :the_geom, :srid => 4326, :geometry_type => :polygon
|
155
|
+
end
|
156
|
+
|
157
|
+
expected = []
|
158
|
+
|
159
|
+
expected << strip_heredoc(<<-SQL)
|
160
|
+
CREATE TABLE "foo" (
|
161
|
+
"id" serial primary key,
|
162
|
+
"the_geom" geometry(POLYGON, 4326)
|
163
|
+
);
|
164
|
+
SQL
|
165
|
+
|
166
|
+
expected << strip_heredoc(<<-SQL)
|
167
|
+
CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");
|
168
|
+
SQL
|
169
|
+
|
170
|
+
assert_equal(expected, statements)
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_change_table_add_geometry
|
174
|
+
Mig.change_table(:foo) do |t|
|
175
|
+
t.geometry :the_geom, :srid => 4326
|
176
|
+
end
|
177
|
+
|
178
|
+
expected = [
|
179
|
+
%{ALTER TABLE "foo" ADD COLUMN "the_geom" geometry(GEOMETRY, 4326)},
|
180
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
|
181
|
+
]
|
182
|
+
|
183
|
+
assert_equal(expected, statements)
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_change_table_add_geometry_with_spatial
|
187
|
+
Mig.change_table(:foo) do |t|
|
188
|
+
t.spatial :the_geom, :srid => 4326
|
189
|
+
end
|
190
|
+
|
191
|
+
expected = [
|
192
|
+
%{ALTER TABLE "foo" ADD COLUMN "the_geom" geometry(GEOMETRY, 4326)},
|
193
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
|
194
|
+
]
|
195
|
+
|
196
|
+
assert_equal(expected, statements)
|
197
|
+
end
|
198
|
+
|
199
|
+
def test_change_table_geometry_with_spatial_and_spatial_column_type
|
200
|
+
Mig.change_table(:foo) do |t|
|
201
|
+
t.spatial :the_geom, :srid => 4326, :spatial_column_type => :geography
|
202
|
+
end
|
203
|
+
|
204
|
+
expected = [
|
205
|
+
%{ALTER TABLE "foo" ADD COLUMN "the_geom" geography(GEOMETRY, 4326)},
|
206
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
|
207
|
+
]
|
208
|
+
|
209
|
+
assert_equal(expected, statements)
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_change_table_geography
|
213
|
+
Mig.change_table(:foo) do |t|
|
214
|
+
t.geography :the_geom, :srid => 4326
|
215
|
+
end
|
216
|
+
|
217
|
+
expected = [
|
218
|
+
%{ALTER TABLE "foo" ADD COLUMN "the_geom" geography(GEOMETRY, 4326)},
|
219
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
|
220
|
+
]
|
221
|
+
|
222
|
+
assert_equal(expected, statements)
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_change_table_geometry_with_force_constraints
|
226
|
+
Mig.change_table(:foo) do |t|
|
227
|
+
t.geometry :the_geom, :srid => 4326, :force_constraints => true
|
228
|
+
end
|
229
|
+
|
230
|
+
expected = [
|
231
|
+
%{ALTER TABLE "foo" ADD COLUMN "the_geom" geometry(GEOMETRY, 4326)},
|
232
|
+
%{ALTER TABLE "foo" ADD CONSTRAINT "enforce_srid_the_geom" CHECK (ST_srid("the_geom") = (4326));},
|
233
|
+
%{ALTER TABLE "foo" ADD CONSTRAINT "enforce_dims_the_geom" CHECK (ST_ndims("the_geom") = 2);},
|
234
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
|
235
|
+
]
|
236
|
+
|
237
|
+
assert_equal(expected, statements)
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_change_table_geometry_with_schema
|
241
|
+
Mig.change_table('shabba.foo') do |t|
|
242
|
+
t.geometry :the_geom, :srid => 4326
|
243
|
+
end
|
244
|
+
|
245
|
+
expected = [
|
246
|
+
%{ALTER TABLE "shabba"."foo" ADD COLUMN "the_geom" geometry(GEOMETRY, 4326)},
|
247
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON "shabba"."foo" USING "gist"("the_geom");}
|
248
|
+
]
|
249
|
+
|
250
|
+
assert_equal(expected, statements)
|
251
|
+
end
|
252
|
+
|
253
|
+
def test_change_table_geometry_with_not_null
|
254
|
+
Mig.change_table(:foo) do |t|
|
255
|
+
t.geometry :the_geom, :srid => 4326, :null => false
|
256
|
+
end
|
257
|
+
|
258
|
+
expected = [
|
259
|
+
%{ALTER TABLE "foo" ADD COLUMN "the_geom" geometry(GEOMETRY, 4326) NOT NULL},
|
260
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
|
261
|
+
]
|
262
|
+
|
263
|
+
assert_equal(expected, statements)
|
264
|
+
end
|
265
|
+
|
266
|
+
def test_change_table_geometry_with_null_and_type
|
267
|
+
Mig.change_table(:foo) do |t|
|
268
|
+
t.geometry :the_geom, :srid => 4326, :geometry_type => :polygon
|
269
|
+
end
|
270
|
+
|
271
|
+
expected = [
|
272
|
+
%{ALTER TABLE "foo" ADD COLUMN "the_geom" geometry(POLYGON, 4326)},
|
273
|
+
%{CREATE INDEX "foo_the_geom_gist_index" ON PUBLIC."foo" USING "gist"("the_geom");}
|
274
|
+
]
|
275
|
+
|
276
|
+
assert_equal(expected, statements)
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|