activerecord-postgresql-extensions 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/Rakefile +2 -2
  2. data/VERSION +1 -1
  3. data/activerecord-postgresql-extensions.gemspec +20 -17
  4. data/lib/activerecord-postgresql-extensions.rb +2 -0
  5. data/lib/postgresql_extensions/postgresql_adapter_extensions.rb +50 -53
  6. data/lib/postgresql_extensions/postgresql_constraints.rb +142 -153
  7. data/lib/postgresql_extensions/postgresql_extensions.rb +246 -0
  8. data/lib/postgresql_extensions/postgresql_functions.rb +31 -33
  9. data/lib/postgresql_extensions/postgresql_geometry.rb +2 -2
  10. data/lib/postgresql_extensions/postgresql_indexes.rb +13 -14
  11. data/lib/postgresql_extensions/postgresql_languages.rb +4 -4
  12. data/lib/postgresql_extensions/postgresql_permissions.rb +12 -14
  13. data/lib/postgresql_extensions/postgresql_roles.rb +2 -2
  14. data/lib/postgresql_extensions/postgresql_rules.rb +11 -10
  15. data/lib/postgresql_extensions/postgresql_schemas.rb +4 -4
  16. data/lib/postgresql_extensions/postgresql_sequences.rb +15 -16
  17. data/lib/postgresql_extensions/postgresql_tables.rb +20 -21
  18. data/lib/postgresql_extensions/postgresql_text_search.rb +313 -0
  19. data/lib/postgresql_extensions/postgresql_triggers.rb +13 -14
  20. data/lib/postgresql_extensions/postgresql_types.rb +1 -1
  21. data/lib/postgresql_extensions/postgresql_views.rb +13 -14
  22. data/test/{adapter_test.rb → adapter_tests.rb} +6 -6
  23. data/test/{constraints_test.rb → constraints_tests.rb} +13 -13
  24. data/test/extensions_tests.rb +275 -0
  25. data/test/{functions_test.rb → functions_tests.rb} +10 -10
  26. data/test/{geometry_test.rb → geometry_tests.rb} +16 -16
  27. data/test/{index_test.rb → index_tests.rb} +11 -11
  28. data/test/{languages_test.rb → languages_tests.rb} +6 -6
  29. data/test/{permissions_test.rb → permissions_tests.rb} +36 -36
  30. data/test/{roles_test.rb → roles_tests.rb} +6 -6
  31. data/test/{rules_test.rb → rules_tests.rb} +3 -3
  32. data/test/{schemas_test.rb → schemas_tests.rb} +6 -6
  33. data/test/{sequences_test.rb → sequences_tests.rb} +10 -10
  34. data/test/{tables_test.rb → tables_tests.rb} +2 -2
  35. data/test/text_search_tests.rb +263 -0
  36. metadata +19 -16
  37. data/postgresql-extensions.gemspec +0 -50
@@ -41,17 +41,16 @@ module ActiveRecord
41
41
  #
42
42
  # ==== Example
43
43
  #
44
- # ### ruby
45
- # create_trigger(
46
- # 'willie_nelsons_trigger',
47
- # :before,
48
- # :update,
49
- # { :nylon => :guitar },
50
- # 'strum_trigger',
51
- # :for_each => :row
52
- # )
53
- # # => CREATE TRIGGER "willie_nelsons_trigger" BEFORE UPDATE
54
- # # ON "nylon"."guitar" FOR EACH ROW EXECUTE PROCEDURE "test_trigger"();
44
+ # create_trigger(
45
+ # 'willie_nelsons_trigger',
46
+ # :before,
47
+ # :update,
48
+ # { :nylon => :guitar },
49
+ # 'strum_trigger',
50
+ # :for_each => :row
51
+ # )
52
+ # # => CREATE TRIGGER "willie_nelsons_trigger" BEFORE UPDATE
53
+ # # ON "nylon"."guitar" FOR EACH ROW EXECUTE PROCEDURE "test_trigger"();
55
54
  def create_trigger(name, called, events, table, function, options = {})
56
55
  execute PostgreSQLTriggerDefinition.new(self, name, called, events, table, function, options).to_s
57
56
  end
@@ -68,12 +67,12 @@ module ActiveRecord
68
67
  sql << 'IF EXISTS ' if options[:if_exists]
69
68
  sql << "#{quote_generic(name)} ON #{quote_table_name(table)}"
70
69
  sql << ' CASCADE' if options[:cascade]
71
- execute sql
70
+ execute("#{sql};")
72
71
  end
73
72
 
74
73
  # Renames a trigger.
75
74
  def rename_trigger(name, table, new_name, options = {})
76
- execute "ALTER TRIGGER #{quote_generic(name)} ON #{quote_table_name(table)} RENAME TO #{quote_generic(new_name)}"
75
+ execute "ALTER TRIGGER #{quote_generic(name)} ON #{quote_table_name(table)} RENAME TO #{quote_generic(new_name)};"
77
76
  end
78
77
  end
79
78
 
@@ -99,7 +98,7 @@ module ActiveRecord
99
98
  sql << " ON #{base.quote_table_name(table)}"
100
99
  sql << " FOR EACH #{options[:for_each].to_s.upcase}" if options[:for_each]
101
100
  sql << " EXECUTE PROCEDURE #{base.quote_function(function)}(#{options[:args]})"
102
- sql
101
+ "#{sql};"
103
102
  end
104
103
  alias :to_s :to_sql
105
104
 
@@ -6,7 +6,7 @@ module ActiveRecord
6
6
  class PostgreSQLAdapter < AbstractAdapter
7
7
  # Returns an Array of available languages.
8
8
  def types(name = nil)
9
- query(%{SELECT typname FROM pg_type}, name).map { |row| row[0] }
9
+ query(%{SELECT typname FROM pg_type;}, name).map { |row| row[0] }
10
10
  end
11
11
 
12
12
  def type_exists?(name)
@@ -30,16 +30,15 @@ module ActiveRecord
30
30
  #
31
31
  # ==== Examples
32
32
  #
33
- # ### ruby
34
- # create_view(:foo_view, 'SELECT * FROM bar')
35
- # # => CREATE VIEW "foo_view" AS SELECT * FROM bar;
33
+ # create_view(:foo_view, 'SELECT * FROM bar')
34
+ # # => CREATE VIEW "foo_view" AS SELECT * FROM bar;
36
35
  #
37
- # create_view(
38
- # { :geospatial => :foo_view },
39
- # 'SELECT * FROM bar',
40
- # :columns => [ :id, :name, :the_geom ]
41
- # )
42
- # # => CREATE VIEW "geospatial"."foo_view" ("id", "name", "the_geom") AS SELECT * FROM bar;
36
+ # create_view(
37
+ # { :geospatial => :foo_view },
38
+ # 'SELECT * FROM bar',
39
+ # :columns => [ :id, :name, :the_geom ]
40
+ # )
41
+ # # => CREATE VIEW "geospatial"."foo_view" ("id", "name", "the_geom") AS SELECT * FROM bar;
43
42
  def create_view(name, query, options = {})
44
43
  execute PostgreSQLViewDefinition.new(self, name, query, options).to_s
45
44
  end
@@ -55,22 +54,22 @@ module ActiveRecord
55
54
  sql << 'IF EXISTS ' if options[:if_exists]
56
55
  sql << Array(name).collect { |v| quote_view_name(v) }.join(', ')
57
56
  sql << ' CASCADE' if options[:cascade]
58
- execute sql
57
+ execute("#{sql};")
59
58
  end
60
59
 
61
60
  # Renames a view.
62
61
  def rename_view(name, new_name, options = {})
63
- execute "ALTER TABLE #{quote_view_name(name)} RENAME TO #{quote_generic_ignore_schema(new_name)}"
62
+ execute "ALTER TABLE #{quote_view_name(name)} RENAME TO #{quote_generic_ignore_schema(new_name)};"
64
63
  end
65
64
 
66
65
  # Change the ownership of a view.
67
66
  def alter_view_owner(name, role, options = {})
68
- execute "ALTER TABLE #{quote_view_name(name)} OWNER TO #{quote_role(role)}"
67
+ execute "ALTER TABLE #{quote_view_name(name)} OWNER TO #{quote_role(role)};"
69
68
  end
70
69
 
71
70
  # Alter a view's schema.
72
71
  def alter_view_schema(name, schema, options = {})
73
- execute "ALTER TABLE #{quote_view_name(name)} SET SCHEMA #{quote_schema(schema)}"
72
+ execute "ALTER TABLE #{quote_view_name(name)} SET SCHEMA #{quote_schema(schema)};"
74
73
  end
75
74
  end
76
75
 
@@ -95,7 +94,7 @@ module ActiveRecord
95
94
  end.join(', ') << ') '
96
95
  end
97
96
  sql << "AS #{query}"
98
- sql
97
+ "#{sql};"
99
98
  end
100
99
  alias :to_s :to_sql
101
100
  end
@@ -57,9 +57,9 @@ class AdapterExtensionTests < Test::Unit::TestCase
57
57
  ARBC.set_role('foo', :duration => :session)
58
58
 
59
59
  assert_equal([
60
- %{SET ROLE "foo"},
61
- %{SET LOCAL ROLE "foo"},
62
- %{SET SESSION ROLE "foo"}
60
+ %{SET ROLE "foo";},
61
+ %{SET LOCAL ROLE "foo";},
62
+ %{SET SESSION ROLE "foo";}
63
63
  ], ARBC.statements)
64
64
 
65
65
  assert_raise(ArgumentError) do
@@ -69,7 +69,7 @@ class AdapterExtensionTests < Test::Unit::TestCase
69
69
 
70
70
  def test_reset_role
71
71
  ARBC.reset_role
72
- assert_equal([ 'RESET ROLE' ], ARBC.statements)
72
+ assert_equal([ 'RESET ROLE;' ], ARBC.statements)
73
73
  end
74
74
 
75
75
  def test_current_role
@@ -77,8 +77,8 @@ class AdapterExtensionTests < Test::Unit::TestCase
77
77
  ARBC.current_user
78
78
 
79
79
  assert_equal([
80
- 'SELECT current_role',
81
- 'SELECT current_role'
80
+ 'SELECT current_role;',
81
+ 'SELECT current_role;'
82
82
  ], ARBC.statements)
83
83
  end
84
84
  end
@@ -26,7 +26,7 @@ CREATE TABLE "foo" (
26
26
  "email" text,
27
27
  UNIQUE ("id", "bar_id"),
28
28
  UNIQUE ("name", "email") USING INDEX TABLESPACE "fubar"
29
- )
29
+ );
30
30
  EOF
31
31
  end
32
32
 
@@ -40,7 +40,7 @@ CREATE TABLE "foo" (
40
40
  "id" serial primary key,
41
41
  "bar_id" integer,
42
42
  UNIQUE ("bar_id")
43
- )
43
+ );
44
44
  EOF
45
45
  end
46
46
 
@@ -55,8 +55,8 @@ EOF
55
55
  )
56
56
 
57
57
  assert_equal([
58
- "ALTER TABLE \"foo\" ADD UNIQUE (\"bar_id\")",
59
- "ALTER TABLE \"foo\" ADD CONSTRAINT \"bar_id_unique\" UNIQUE (\"bar_id\") WITH (FILLFACTOR=10) USING INDEX TABLESPACE \"fubar\""
58
+ "ALTER TABLE \"foo\" ADD UNIQUE (\"bar_id\");",
59
+ "ALTER TABLE \"foo\" ADD CONSTRAINT \"bar_id_unique\" UNIQUE (\"bar_id\") WITH (FILLFACTOR=10) USING INDEX TABLESPACE \"fubar\";"
60
60
  ], statements)
61
61
  end
62
62
 
@@ -68,11 +68,11 @@ EOF
68
68
  Mig.add_foreign_key(:foo, :bar_id, :bar, :deferrable => :immediate)
69
69
 
70
70
  assert_equal([
71
- "ALTER TABLE \"foo\" ADD FOREIGN KEY (\"bar_id\") REFERENCES \"bar\"",
72
- "ALTER TABLE \"foo\" ADD CONSTRAINT \"bar_fk\" FOREIGN KEY (\"bar_id\") REFERENCES \"bar\" (\"ogc_fid\")",
73
- "ALTER TABLE \"foo\" ADD FOREIGN KEY (\"one_id\", \"bar_id\") REFERENCES \"bar\" (\"one_id\", \"bar_id\") MATCH FULL",
74
- "ALTER TABLE \"foo\" ADD FOREIGN KEY (\"bar_id\") REFERENCES \"bar\" ON DELETE SET DEFAULT",
75
- "ALTER TABLE \"foo\" ADD FOREIGN KEY (\"bar_id\") REFERENCES \"bar\" DEFERRABLE INITIALLY IMMEDIATE"
71
+ "ALTER TABLE \"foo\" ADD FOREIGN KEY (\"bar_id\") REFERENCES \"bar\";",
72
+ "ALTER TABLE \"foo\" ADD CONSTRAINT \"bar_fk\" FOREIGN KEY (\"bar_id\") REFERENCES \"bar\" (\"ogc_fid\");",
73
+ "ALTER TABLE \"foo\" ADD FOREIGN KEY (\"one_id\", \"bar_id\") REFERENCES \"bar\" (\"one_id\", \"bar_id\") MATCH FULL;",
74
+ "ALTER TABLE \"foo\" ADD FOREIGN KEY (\"bar_id\") REFERENCES \"bar\" ON DELETE SET DEFAULT;",
75
+ "ALTER TABLE \"foo\" ADD FOREIGN KEY (\"bar_id\") REFERENCES \"bar\" DEFERRABLE INITIALLY IMMEDIATE;"
76
76
  ], statements)
77
77
  end
78
78
 
@@ -81,8 +81,8 @@ EOF
81
81
  Mig.drop_constraint(:foo, :bar, :cascade => true)
82
82
 
83
83
  assert_equal([
84
- "ALTER TABLE \"foo\" DROP CONSTRAINT \"bar\"",
85
- "ALTER TABLE \"foo\" DROP CONSTRAINT \"bar\" CASCADE"
84
+ "ALTER TABLE \"foo\" DROP CONSTRAINT \"bar\";",
85
+ "ALTER TABLE \"foo\" DROP CONSTRAINT \"bar\" CASCADE;"
86
86
  ], statements)
87
87
  end
88
88
 
@@ -91,8 +91,8 @@ EOF
91
91
  Mig.add_check_constraint(:foo, 'length(name) < 100', :name => 'name_length_check')
92
92
 
93
93
  assert_equal([
94
- "ALTER TABLE \"foo\" ADD CHECK (length(name) < 100)",
95
- "ALTER TABLE \"foo\" ADD CONSTRAINT \"name_length_check\" CHECK (length(name) < 100)"
94
+ "ALTER TABLE \"foo\" ADD CHECK (length(name) < 100);",
95
+ "ALTER TABLE \"foo\" ADD CONSTRAINT \"name_length_check\" CHECK (length(name) < 100);"
96
96
  ], statements)
97
97
  end
98
98
  end
@@ -0,0 +1,275 @@
1
+
2
+ $: << File.dirname(__FILE__)
3
+ require 'test_helper'
4
+
5
+ class ExtensionsTests < Test::Unit::TestCase
6
+ include PostgreSQLExtensionsTestHelper
7
+
8
+ def test_create_extension
9
+ ARBC.create_extension(:foo)
10
+ ARBC.create_extension(:foo, :if_not_exists => true)
11
+ ARBC.create_extension(:foo, :schema => :bar)
12
+ ARBC.create_extension(:foo, :version => '0.0.1')
13
+ ARBC.create_extension(:foo, :old_version => '0.0.1')
14
+
15
+ assert_equal([
16
+ %{CREATE EXTENSION "foo";},
17
+ %{CREATE EXTENSION IF NOT EXISTS "foo";},
18
+ %{CREATE EXTENSION "foo" SCHEMA "bar";},
19
+ %{CREATE EXTENSION "foo" VERSION "0.0.1";},
20
+ %{CREATE EXTENSION "foo" FROM "0.0.1";}
21
+ ], statements)
22
+ end
23
+
24
+ def test_drop_extension
25
+ ARBC.drop_extension(:foo)
26
+ ARBC.drop_extension(:foo, :if_exists => true)
27
+ ARBC.drop_extension(:foo, :cascade => true)
28
+ ARBC.drop_extension(:foo, :bar)
29
+
30
+ assert_equal([
31
+ %{DROP EXTENSION "foo";},
32
+ %{DROP EXTENSION IF EXISTS "foo";},
33
+ %{DROP EXTENSION "foo" CASCADE;},
34
+ %{DROP EXTENSION "foo", "bar";}
35
+ ], statements)
36
+ end
37
+
38
+ def test_update_extension
39
+ ARBC.update_extension(:foo)
40
+ ARBC.update_extension(:foo, '2.0.0')
41
+
42
+ assert_equal([
43
+ %{ALTER EXTENSION "foo" UPDATE;},
44
+ %{ALTER EXTENSION "foo" UPDATE TO "2.0.0";}
45
+ ], statements)
46
+ end
47
+
48
+ def test_update_schema
49
+ ARBC.alter_extension_schema(:foo, :bar)
50
+
51
+ assert_equal([
52
+ %{ALTER EXTENSION "foo" SET SCHEMA "bar";}
53
+ ], statements)
54
+ end
55
+
56
+ def test_alter_extension_empty
57
+ ARBC.alter_extension(:foo)
58
+
59
+ assert_equal([], statements)
60
+ end
61
+
62
+ def test_alter_extension_regular_options_with_hashes
63
+ ARBC.alter_extension(:foo, {
64
+ :collation => :bar,
65
+ :conversion => :bar,
66
+ :domain => :bar,
67
+ :foreign_data_wrapper => :bar,
68
+ :foreign_table => :bar,
69
+ :schema => :bar,
70
+ :sequence => :bar,
71
+ :server => :bar,
72
+ :table => :bar,
73
+ :text_search_configuration => :bar,
74
+ :text_search_dictionary => :bar,
75
+ :text_search_parser => :bar,
76
+ :text_search_template => :bar,
77
+ :type => :bar,
78
+ :view => :bar
79
+ })
80
+
81
+ ARBC.alter_extension(:foo, {
82
+ :add_collation => :bar,
83
+ :add_conversion => :bar,
84
+ :add_domain => :bar,
85
+ :add_foreign_data_wrapper => :bar,
86
+ :add_foreign_table => :bar,
87
+ :add_schema => :bar,
88
+ :add_sequence => :bar,
89
+ :add_server => :bar,
90
+ :add_table => :bar,
91
+ :add_text_search_configuration => :bar,
92
+ :add_text_search_dictionary => :bar,
93
+ :add_text_search_parser => :bar,
94
+ :add_text_search_template => :bar,
95
+ :add_type => :bar,
96
+ :add_view => :bar
97
+ })
98
+
99
+ ARBC.alter_extension(:foo, {
100
+ :drop_collation => :bar,
101
+ :drop_conversion => :bar,
102
+ :drop_domain => :bar,
103
+ :drop_foreign_data_wrapper => :bar,
104
+ :drop_foreign_table => :bar,
105
+ :drop_schema => :bar,
106
+ :drop_sequence => :bar,
107
+ :drop_server => :bar,
108
+ :drop_table => :bar,
109
+ :drop_text_search_configuration => :bar,
110
+ :drop_text_search_dictionary => :bar,
111
+ :drop_text_search_parser => :bar,
112
+ :drop_text_search_template => :bar,
113
+ :drop_type => :bar,
114
+ :drop_view => :bar
115
+ })
116
+
117
+ assert_equal([
118
+ [
119
+ %{ALTER EXTENSION "foo" ADD COLLATION "bar";},
120
+ %{ALTER EXTENSION "foo" ADD CONVERSION "bar";},
121
+ %{ALTER EXTENSION "foo" ADD DOMAIN "bar";},
122
+ %{ALTER EXTENSION "foo" ADD FOREIGN DATA WRAPPER "bar";},
123
+ %{ALTER EXTENSION "foo" ADD FOREIGN TABLE "bar";},
124
+ %{ALTER EXTENSION "foo" ADD SCHEMA "bar";},
125
+ %{ALTER EXTENSION "foo" ADD SEQUENCE "bar";},
126
+ %{ALTER EXTENSION "foo" ADD SERVER "bar";},
127
+ %{ALTER EXTENSION "foo" ADD TABLE "bar";},
128
+ %{ALTER EXTENSION "foo" ADD TEXT SEARCH CONFIGURATION "bar";},
129
+ %{ALTER EXTENSION "foo" ADD TEXT SEARCH DICTIONARY "bar";},
130
+ %{ALTER EXTENSION "foo" ADD TEXT SEARCH PARSER "bar";},
131
+ %{ALTER EXTENSION "foo" ADD TEXT SEARCH TEMPLATE "bar";},
132
+ %{ALTER EXTENSION "foo" ADD TYPE "bar";},
133
+ %{ALTER EXTENSION "foo" ADD VIEW "bar";}
134
+ ].sort,
135
+
136
+ [
137
+ %{ALTER EXTENSION "foo" ADD COLLATION "bar";},
138
+ %{ALTER EXTENSION "foo" ADD CONVERSION "bar";},
139
+ %{ALTER EXTENSION "foo" ADD DOMAIN "bar";},
140
+ %{ALTER EXTENSION "foo" ADD FOREIGN DATA WRAPPER "bar";},
141
+ %{ALTER EXTENSION "foo" ADD FOREIGN TABLE "bar";},
142
+ %{ALTER EXTENSION "foo" ADD SCHEMA "bar";},
143
+ %{ALTER EXTENSION "foo" ADD SEQUENCE "bar";},
144
+ %{ALTER EXTENSION "foo" ADD SERVER "bar";},
145
+ %{ALTER EXTENSION "foo" ADD TABLE "bar";},
146
+ %{ALTER EXTENSION "foo" ADD TEXT SEARCH CONFIGURATION "bar";},
147
+ %{ALTER EXTENSION "foo" ADD TEXT SEARCH DICTIONARY "bar";},
148
+ %{ALTER EXTENSION "foo" ADD TEXT SEARCH PARSER "bar";},
149
+ %{ALTER EXTENSION "foo" ADD TEXT SEARCH TEMPLATE "bar";},
150
+ %{ALTER EXTENSION "foo" ADD TYPE "bar";},
151
+ %{ALTER EXTENSION "foo" ADD VIEW "bar";}
152
+ ].sort,
153
+
154
+ [
155
+ %{ALTER EXTENSION "foo" DROP COLLATION "bar";},
156
+ %{ALTER EXTENSION "foo" DROP CONVERSION "bar";},
157
+ %{ALTER EXTENSION "foo" DROP DOMAIN "bar";},
158
+ %{ALTER EXTENSION "foo" DROP FOREIGN DATA WRAPPER "bar";},
159
+ %{ALTER EXTENSION "foo" DROP FOREIGN TABLE "bar";},
160
+ %{ALTER EXTENSION "foo" DROP SCHEMA "bar";},
161
+ %{ALTER EXTENSION "foo" DROP SEQUENCE "bar";},
162
+ %{ALTER EXTENSION "foo" DROP SERVER "bar";},
163
+ %{ALTER EXTENSION "foo" DROP TABLE "bar";},
164
+ %{ALTER EXTENSION "foo" DROP TEXT SEARCH CONFIGURATION "bar";},
165
+ %{ALTER EXTENSION "foo" DROP TEXT SEARCH DICTIONARY "bar";},
166
+ %{ALTER EXTENSION "foo" DROP TEXT SEARCH PARSER "bar";},
167
+ %{ALTER EXTENSION "foo" DROP TEXT SEARCH TEMPLATE "bar";},
168
+ %{ALTER EXTENSION "foo" DROP TYPE "bar";},
169
+ %{ALTER EXTENSION "foo" DROP VIEW "bar";}
170
+ ].sort
171
+ ], statements.collect { |s|
172
+ s.split(/\n/).sort
173
+ })
174
+ end
175
+
176
+ def test_alter_extension_regular_options_with_block
177
+ ARBC.alter_extension(:foo) do |e|
178
+ e.drop_collation :bar
179
+ e.add_conversion :bar
180
+ e.domain :bar
181
+ end
182
+
183
+ assert_equal([
184
+ %{ALTER EXTENSION "foo" DROP COLLATION "bar";
185
+ ALTER EXTENSION "foo" ADD CONVERSION "bar";
186
+ ALTER EXTENSION "foo" ADD DOMAIN "bar";}
187
+ ], statements)
188
+ end
189
+
190
+ def test_alter_extension_cast_option
191
+ ARBC.alter_extension(:foo) do |e|
192
+ e.cast :hello => :world
193
+ e.cast [ :hello, :world ]
194
+ e.cast :source => :hello, :target => :world
195
+ end
196
+
197
+ assert_equal([
198
+ %{ALTER EXTENSION "foo" ADD CAST ("hello" AS "world");
199
+ ALTER EXTENSION "foo" ADD CAST ("hello" AS "world");
200
+ ALTER EXTENSION "foo" ADD CAST ("hello" AS "world");}
201
+ ], statements)
202
+ end
203
+
204
+ def test_alter_extension_aggregate_option
205
+ ARBC.alter_extension(:foo) do |e|
206
+ e.aggregate :name => :bar, :types => %w{ type_a type_b type_c }
207
+ e.aggregate :bar, :type_a, :type_b, :type_c
208
+ end
209
+
210
+ assert_equal([
211
+ %{ALTER EXTENSION "foo" ADD AGGREGATE "bar" ("type_a", "type_b", "type_c");
212
+ ALTER EXTENSION "foo" ADD AGGREGATE "bar" ("type_a", "type_b", "type_c");}
213
+ ], statements)
214
+ end
215
+
216
+ def test_alter_extension_operator_option
217
+ ARBC.alter_extension(:foo) do |e|
218
+ e.operator :bar, :hello, :world
219
+ e.operator [ :bar, :hello, :world ]
220
+ e.operator :name => :bar, :left_type => :hello, :right_type => :world
221
+ end
222
+
223
+ assert_equal([
224
+ %{ALTER EXTENSION "foo" ADD OPERATOR "bar" ("hello", "world");
225
+ ALTER EXTENSION "foo" ADD OPERATOR "bar" ("hello", "world");
226
+ ALTER EXTENSION "foo" ADD OPERATOR "bar" ("hello", "world");}
227
+ ], statements)
228
+ end
229
+
230
+ def test_alter_extension_operator_class_option
231
+ ARBC.alter_extension(:foo) do |e|
232
+ e.operator_class :hello => :world
233
+ e.operator_class :hello, :world
234
+ e.operator_class [ :hello, :world ]
235
+ e.operator_class :name => :hello, :indexing_method => :world
236
+ end
237
+
238
+ assert_equal([
239
+ %{ALTER EXTENSION "foo" ADD OPERATOR CLASS "hello" USING "world");
240
+ ALTER EXTENSION "foo" ADD OPERATOR CLASS "hello" USING "world");
241
+ ALTER EXTENSION "foo" ADD OPERATOR CLASS "hello" USING "world");
242
+ ALTER EXTENSION "foo" ADD OPERATOR CLASS "hello" USING "world");}
243
+ ], statements)
244
+ end
245
+
246
+ def test_alter_extension_operator_family_option
247
+ ARBC.alter_extension(:foo) do |e|
248
+ e.operator_family :hello => :world
249
+ e.operator_family :hello, :world
250
+ e.operator_family [ :hello, :world ]
251
+ e.operator_family :name => :hello, :indexing_method => :world
252
+ end
253
+
254
+ assert_equal([
255
+ %{ALTER EXTENSION "foo" ADD OPERATOR FAMILY "hello" USING "world");
256
+ ALTER EXTENSION "foo" ADD OPERATOR FAMILY "hello" USING "world");
257
+ ALTER EXTENSION "foo" ADD OPERATOR FAMILY "hello" USING "world");
258
+ ALTER EXTENSION "foo" ADD OPERATOR FAMILY "hello" USING "world");}
259
+ ], statements)
260
+ end
261
+
262
+ def test_alter_extension_function_option
263
+ ARBC.alter_extension(:foo) do |e|
264
+ e.function :bar, "VARIADIC hello world"
265
+ e.function [ :bar, "VARIADIC hello world" ]
266
+ e.function :name => :bar, :arguments => "VARIADIC hello world"
267
+ end
268
+
269
+ assert_equal([
270
+ %{ALTER EXTENSION "foo" ADD FUNCTION "bar"(VARIADIC hello world);
271
+ ALTER EXTENSION "foo" ADD FUNCTION "bar"(VARIADIC hello world);
272
+ ALTER EXTENSION "foo" ADD FUNCTION "bar"(VARIADIC hello world);}
273
+ ], statements)
274
+ end
275
+ end