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
data/Rakefile CHANGED
@@ -4,7 +4,7 @@
4
4
  require 'rubygems'
5
5
  require 'rubygems/package_task'
6
6
  require 'rake/testtask'
7
- require 'rake/rdoctask'
7
+ require 'rdoc/task'
8
8
 
9
9
  if RUBY_VERSION >= '1.9'
10
10
  begin
@@ -35,7 +35,7 @@ end
35
35
 
36
36
  desc 'Test PostgreSQL extensions'
37
37
  Rake::TestTask.new(:test) do |t|
38
- t.pattern = 'test/**/*_test.rb'
38
+ t.test_files = FileList['test/**/*_tests.rb']
39
39
  t.verbose = false
40
40
  end
41
41
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.10
1
+ 0.0.11
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "activerecord-postgresql-extensions"
8
- s.version = "0.0.10"
8
+ s.version = "0.0.11"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["J Smith"]
12
- s.date = "2011-10-05"
12
+ s.date = "2011-11-09"
13
13
  s.description = "A whole bunch of extensions the ActiveRecord PostgreSQL adapter."
14
14
  s.email = "code@zoocasa.com"
15
15
  s.extra_rdoc_files = [
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
25
25
  "lib/postgresql_extensions/foreign_key_associations.rb",
26
26
  "lib/postgresql_extensions/postgresql_adapter_extensions.rb",
27
27
  "lib/postgresql_extensions/postgresql_constraints.rb",
28
+ "lib/postgresql_extensions/postgresql_extensions.rb",
28
29
  "lib/postgresql_extensions/postgresql_functions.rb",
29
30
  "lib/postgresql_extensions/postgresql_geometry.rb",
30
31
  "lib/postgresql_extensions/postgresql_indexes.rb",
@@ -35,27 +36,29 @@ Gem::Specification.new do |s|
35
36
  "lib/postgresql_extensions/postgresql_schemas.rb",
36
37
  "lib/postgresql_extensions/postgresql_sequences.rb",
37
38
  "lib/postgresql_extensions/postgresql_tables.rb",
39
+ "lib/postgresql_extensions/postgresql_text_search.rb",
38
40
  "lib/postgresql_extensions/postgresql_triggers.rb",
39
41
  "lib/postgresql_extensions/postgresql_types.rb",
40
42
  "lib/postgresql_extensions/postgresql_views.rb",
41
- "postgresql-extensions.gemspec",
42
- "test/adapter_test.rb",
43
- "test/constraints_test.rb",
44
- "test/functions_test.rb",
45
- "test/geometry_test.rb",
46
- "test/index_test.rb",
47
- "test/languages_test.rb",
48
- "test/permissions_test.rb",
49
- "test/roles_test.rb",
50
- "test/rules_test.rb",
51
- "test/schemas_test.rb",
52
- "test/sequences_test.rb",
53
- "test/tables_test.rb",
54
- "test/test_helper.rb"
43
+ "test/adapter_tests.rb",
44
+ "test/constraints_tests.rb",
45
+ "test/extensions_tests.rb",
46
+ "test/functions_tests.rb",
47
+ "test/geometry_tests.rb",
48
+ "test/index_tests.rb",
49
+ "test/languages_tests.rb",
50
+ "test/permissions_tests.rb",
51
+ "test/roles_tests.rb",
52
+ "test/rules_tests.rb",
53
+ "test/schemas_tests.rb",
54
+ "test/sequences_tests.rb",
55
+ "test/tables_tests.rb",
56
+ "test/test_helper.rb",
57
+ "test/text_search_tests.rb"
55
58
  ]
56
59
  s.homepage = "http://github.com/zoocasa/activerecord-postgresql-extensions"
57
60
  s.require_paths = ["lib"]
58
- s.rubygems_version = "1.8.10"
61
+ s.rubygems_version = "1.8.11"
59
62
  s.summary = "A whole bunch of extensions the ActiveRecord PostgreSQL adapter."
60
63
 
61
64
  if s.respond_to? :specification_version then
@@ -22,6 +22,8 @@ dirname = File.join(File.dirname(__FILE__), 'postgresql_extensions')
22
22
  postgresql_geometry
23
23
  postgresql_types
24
24
  postgresql_roles
25
+ postgresql_text_search
26
+ postgresql_extensions
25
27
  foreign_key_associations
26
28
  }.each do |file|
27
29
  require File.join(dirname, file)
@@ -57,16 +57,15 @@ module ActiveRecord
57
57
  #
58
58
  # Examples:
59
59
  #
60
- # ### ruby
61
- # # should produce '"geospatial"."my_tables"
62
- # with_schema :geospatial do
63
- # quote_table_name('my_table')
64
- # end
60
+ # # should produce '"geospatial"."my_tables"'
61
+ # with_schema :geospatial do
62
+ # quote_table_name('my_table')
63
+ # end
65
64
  #
66
- # # should produce 'SELECT * FROM "geospatial"."models"'
67
- # with_schema :geospatial do
68
- # Model.find(:all)
69
- # end
65
+ # # should produce 'SELECT * FROM "geospatial"."models"'
66
+ # with_schema :geospatial do
67
+ # Model.find(:all)
68
+ # end
70
69
  def with_schema schema
71
70
  scoped_schemas << schema
72
71
  begin
@@ -81,30 +80,28 @@ module ActiveRecord
81
80
  #
82
81
  # Example:
83
82
  #
84
- # ### ruby
85
- # with_schema :geospatial do
86
- # create_table(:test) do |t|
87
- # ignore_schema do
88
- # t.integer(
89
- # :ref_id,
90
- # :references => {
91
- # :table => :refs,
92
- # :column => :id,
93
- # :deferrable => true
94
- # }
95
- # )
96
- # end
97
- # end
98
- # end
83
+ # with_schema :geospatial do
84
+ # create_table(:test) do |t|
85
+ # ignore_schema do
86
+ # t.integer(
87
+ # :ref_id,
88
+ # :references => {
89
+ # :table => :refs,
90
+ # :column => :id,
91
+ # :deferrable => true
92
+ # }
93
+ # )
94
+ # end
95
+ # end
96
+ # end
99
97
  #
100
- # Should produce:
101
- #
102
- # ### sql
103
- # CREATE TABLE "geospatial"."test" (
104
- # "id" serial primary key,
105
- # "ref_id" integer DEFAULT NULL NULL,
106
- # FOREIGN KEY ("ref_id") REFERENCES "refs" ("id")
107
- # )
98
+ # # Produces:
99
+ # #
100
+ # # CREATE TABLE "geospatial"."test" (
101
+ # # "id" serial primary key,
102
+ # # "ref_id" integer DEFAULT NULL NULL,
103
+ # # FOREIGN KEY ("ref_id") REFERENCES "refs" ("id")
104
+ # # )
108
105
  #
109
106
  # Here we see that we used the geospatial schema when naming the
110
107
  # test table and dropped back to not specifying a schema when
@@ -112,8 +109,7 @@ module ActiveRecord
112
109
  # used ignore_schema, the foreign key would have been defined
113
110
  # thusly:
114
111
  #
115
- # ### sql
116
- # FOREIGN KEY ("ref_id") REFERENCES "geospatial"."refs" ("id")
112
+ # FOREIGN KEY ("ref_id") REFERENCES "geospatial"."refs" ("id")
117
113
  def ignore_schema
118
114
  with_schema nil do
119
115
  yield
@@ -209,22 +205,21 @@ module ActiveRecord
209
205
  #
210
206
  # Example of using a Hash as a table name:
211
207
  #
212
- # ### ruby
213
- # quote_table_name(:geospatial => :epois) # => "geospatial"."epois"
214
- # # => "geospatial"."epois"
208
+ # quote_table_name(:geospatial => :epois) # => "geospatial"."epois"
209
+ # # => "geospatial"."epois"
215
210
  #
216
- # quote_table_name(:epois)
217
- # # => "epois"
211
+ # quote_table_name(:epois)
212
+ # # => "epois"
218
213
  #
219
- # with_schema(:geospatial) { quote_table_name(:epois) }
220
- # # => "geospatial"."epois"
214
+ # with_schema(:geospatial) { quote_table_name(:epois) }
215
+ # # => "geospatial"."epois"
221
216
  #
222
- # with_schema(:geospatial) do
223
- # ignore_schema do
224
- # quote_table_name(:epois)
225
- # end
226
- # end
227
- # # => "epois"
217
+ # with_schema(:geospatial) do
218
+ # ignore_schema do
219
+ # quote_table_name(:epois)
220
+ # end
221
+ # end
222
+ # # => "epois"
228
223
  def quote_table_name_with_schemas(name)
229
224
  if current_schema || name.is_a?(Hash)
230
225
  quote_generic_with_schema(name)
@@ -450,16 +445,16 @@ module ActiveRecord
450
445
 
451
446
  sql = 'SET '
452
447
  sql << "#{duration} " if duration
453
- sql << "ROLE #{quote_role(role)}"
448
+ sql << "ROLE #{quote_role(role)};"
454
449
  execute(sql, "Setting current role")
455
450
  end
456
451
 
457
452
  def reset_role
458
- execute('RESET ROLE')
453
+ execute('RESET ROLE;')
459
454
  end
460
455
 
461
456
  def current_role
462
- execute('SELECT current_role')
457
+ execute('SELECT current_role;')
463
458
  end
464
459
  alias :current_user :current_role
465
460
 
@@ -468,7 +463,7 @@ module ActiveRecord
468
463
  query(<<-SQL, name).map { |row| row[0] }
469
464
  SELECT tablename
470
465
  FROM pg_tables
471
- WHERE schemaname IN ('pg_catalog')
466
+ WHERE schemaname IN ('pg_catalog');
472
467
  SQL
473
468
  end
474
469
 
@@ -483,7 +478,7 @@ module ActiveRecord
483
478
  alias_method_chain :schema_search_path=, :csv_fix
484
479
 
485
480
  def schema_search_path_with_csv_fix #:nodoc:
486
- @schema_search_path ||= query('SHOW search_path')[0][0].gsub(/, /, ',')
481
+ @schema_search_path ||= query('SHOW search_path;')[0][0].gsub(/, /, ',')
487
482
  end
488
483
  alias_method_chain :schema_search_path, :csv_fix
489
484
 
@@ -543,6 +538,7 @@ module ActiveRecord
543
538
  a.attnum = conkey
544
539
  AND
545
540
  a.attrelid = conrelid
541
+ ;
546
542
  SQL
547
543
 
548
544
  query(sql, name).inject([]) do |memo, (tbl, column, referenced_column)|
@@ -603,6 +599,7 @@ module ActiveRecord
603
599
  a.attnum = conkey
604
600
  AND
605
601
  a.attrelid = conrelid
602
+ ;
606
603
  SQL
607
604
 
608
605
  query(sql, name).inject([]) do |memo, (tbl, column, referenced_column)|
@@ -630,7 +627,7 @@ module ActiveRecord
630
627
 
631
628
  def change_column_default_with_expression(table_name, column_name, default) #:nodoc:
632
629
  if default.is_a?(Hash) && default.has_key?(:expression)
633
- execute "ALTER TABLE #{quote_table_name(table_name)} ALTER COLUMN #{quote_column_name(column_name)} SET DEFAULT #{default[:expression]}"
630
+ execute "ALTER TABLE #{quote_table_name(table_name)} ALTER COLUMN #{quote_column_name(column_name)} SET DEFAULT #{default[:expression]};"
634
631
  else
635
632
  change_column_default_without_expression(table_name, column_name, default)
636
633
  end
@@ -31,7 +31,7 @@ module ActiveRecord
31
31
  def add_check_constraint(table, expression, options = {})
32
32
  sql = "ALTER TABLE #{quote_table_name(table)} ADD "
33
33
  sql << PostgreSQLCheckConstraint.new(self, expression, options).to_s
34
- execute sql
34
+ execute("#{sql};")
35
35
  end
36
36
 
37
37
  # Adds a UNIQUE constraint to the table. See
@@ -39,7 +39,7 @@ module ActiveRecord
39
39
  def add_unique_constraint(table, columns, options = {})
40
40
  sql = "ALTER TABLE #{quote_table_name(table)} ADD "
41
41
  sql << PostgreSQLUniqueConstraint.new(self, columns, options).to_s
42
- execute sql
42
+ execute("#{sql};")
43
43
  end
44
44
 
45
45
  # Adds a FOREIGN KEY constraint to the table. See
@@ -47,7 +47,7 @@ module ActiveRecord
47
47
  def add_foreign_key(table, columns, ref_table, *args)
48
48
  sql = "ALTER TABLE #{quote_table_name(table)} ADD "
49
49
  sql << PostgreSQLForeignKeyConstraint.new(self, columns, ref_table, *args).to_s
50
- execute sql
50
+ execute("#{sql};")
51
51
  end
52
52
 
53
53
  # Drops a constraint from the table. Use this to drop CHECK,
@@ -60,7 +60,7 @@ module ActiveRecord
60
60
  def drop_constraint(table, name, options = {})
61
61
  sql = "ALTER TABLE #{quote_table_name(table)} DROP CONSTRAINT #{quote_generic(name)}"
62
62
  sql << ' CASCADE' if options[:cascade]
63
- execute sql
63
+ execute("#{sql};")
64
64
  end
65
65
  end
66
66
 
@@ -119,18 +119,17 @@ module ActiveRecord
119
119
  #
120
120
  # ==== Example
121
121
  #
122
- # ### ruby
123
- # create_table(:foo) do |t|
124
- # t.integer :fancy_id, :check => "fancy_id != 10"
125
- # end
122
+ # create_table(:foo) do |t|
123
+ # t.integer :fancy_id, :check => "fancy_id != 10"
124
+ # end
126
125
  #
127
- # # Produces:
128
- # #
129
- # # CREATE TABLE "foo" (
130
- # # "id" serial primary key,
131
- # # "fancy_id" integer DEFAULT NULL NULL,
132
- # # CHECK (fancy_id != 10)
133
- # # );
126
+ # # Produces:
127
+ # #
128
+ # # CREATE TABLE "foo" (
129
+ # # "id" serial primary key,
130
+ # # "fancy_id" integer DEFAULT NULL NULL,
131
+ # # CHECK (fancy_id != 10)
132
+ # # );
134
133
  #
135
134
  # You can also provide an Array to <tt>:check</tt> with multiple CHECK
136
135
  # constraints. Each CHECK constraint can be either a String containing
@@ -140,10 +139,9 @@ module ActiveRecord
140
139
  # automatically. Thus, the following is equivalent to the example
141
140
  # above:
142
141
  #
143
- # ### ruby
144
- # create_table(:foo) do |t|
145
- # t.integer :fancy_id, :check => [ { :expression => "fancy_id != 10" } ]
146
- # end
142
+ # create_table(:foo) do |t|
143
+ # t.integer :fancy_id, :check => [ { :expression => "fancy_id != 10" } ]
144
+ # end
147
145
  #
148
146
  # See below for additional options.
149
147
  #
@@ -154,36 +152,35 @@ module ActiveRecord
154
152
  #
155
153
  # ==== Examples
156
154
  #
157
- # ### ruby
158
- # create_table(:foo) do |t|
159
- # t.integer :fancy_id
160
- # t.integer :another_fancy_id
161
- # t.check_constraint 'fancy_id != another_fancy_id'
162
- # end
163
- #
164
- # # Produces:
165
- # #
166
- # # CREATE TABLE "foo" (
167
- # # "id" serial primary key,
168
- # # "fancy_id" integer DEFAULT NULL NULL,
169
- # # "another_fancy_id" integer DEFAULT NULL NULL,
170
- # # CHECK (fancy_id != another_fancy_id)
171
- # # );
172
- #
173
- # create_table(:foo) do |t|
174
- # t.integer :fancy_id
175
- # t.integer :another_fancy_id
176
- # t.check_constraint 'fancy_id != another_fancy_id', :name => 'my_constraint'
177
- # end
178
- #
179
- # # Produces:
180
- # #
181
- # # CREATE TABLE "foo" (
182
- # # "id" serial primary key,
183
- # # "fancy_id" integer DEFAULT NULL NULL,
184
- # # "another_fancy_id" integer DEFAULT NULL NULL,
185
- # # CONSTRAINT "my_constraint" CHECK (fancy_id != another_fancy_id)
186
- # # );
155
+ # create_table(:foo) do |t|
156
+ # t.integer :fancy_id
157
+ # t.integer :another_fancy_id
158
+ # t.check_constraint 'fancy_id != another_fancy_id'
159
+ # end
160
+ #
161
+ # # Produces:
162
+ # #
163
+ # # CREATE TABLE "foo" (
164
+ # # "id" serial primary key,
165
+ # # "fancy_id" integer DEFAULT NULL NULL,
166
+ # # "another_fancy_id" integer DEFAULT NULL NULL,
167
+ # # CHECK (fancy_id != another_fancy_id)
168
+ # # );
169
+ #
170
+ # create_table(:foo) do |t|
171
+ # t.integer :fancy_id
172
+ # t.integer :another_fancy_id
173
+ # t.check_constraint 'fancy_id != another_fancy_id', :name => 'my_constraint'
174
+ # end
175
+ #
176
+ # # Produces:
177
+ # #
178
+ # # CREATE TABLE "foo" (
179
+ # # "id" serial primary key,
180
+ # # "fancy_id" integer DEFAULT NULL NULL,
181
+ # # "another_fancy_id" integer DEFAULT NULL NULL,
182
+ # # CONSTRAINT "my_constraint" CHECK (fancy_id != another_fancy_id)
183
+ # # );
187
184
  #
188
185
  # See below for additional options.
189
186
  #
@@ -194,12 +191,11 @@ module ActiveRecord
194
191
  #
195
192
  # ==== Example
196
193
  #
197
- # ### ruby
198
- # add_check_constraint(:foo, 'fancy_id != 10')
194
+ # add_check_constraint(:foo, 'fancy_id != 10')
199
195
  #
200
- # # Produces:
201
- # #
202
- # # ALTER TABLE "foo" ADD CHECK (fancy_id != 10);
196
+ # # Produces:
197
+ # #
198
+ # # ALTER TABLE "foo" ADD CHECK (fancy_id != 10);
203
199
  #
204
200
  # See below for additional options.
205
201
  #
@@ -254,18 +250,17 @@ module ActiveRecord
254
250
  #
255
251
  # ==== Example:
256
252
  #
257
- # ### ruby
258
- # create_table(:foo) do |t|
259
- # t.integer :fancy_id, :unique => true
260
- # end
253
+ # create_table(:foo) do |t|
254
+ # t.integer :fancy_id, :unique => true
255
+ # end
261
256
  #
262
- # # Produces:
263
- # #
264
- # # CREATE TABLE "foo" (
265
- # # "id" serial primary key,
266
- # # "fancy_id" integer DEFAULT NULL NULL,
267
- # # UNIQUE ("fancy_id")
268
- # # );
257
+ # # Produces:
258
+ # #
259
+ # # CREATE TABLE "foo" (
260
+ # # "id" serial primary key,
261
+ # # "fancy_id" integer DEFAULT NULL NULL,
262
+ # # UNIQUE ("fancy_id")
263
+ # # );
269
264
  #
270
265
  # You can provide additional options to the UNIQUE constraint by
271
266
  # passing a Hash instead of true. See below for details on these
@@ -279,21 +274,20 @@ module ActiveRecord
279
274
  #
280
275
  # ==== Example:
281
276
  #
282
- # ### ruby
283
- # create_table(:foo) do |t|
284
- # t.integer :fancy_id
285
- # t.integer :another_fancy_id
286
- # t.unique_constraint [ :fancy_id, :another_fancy_id ]
287
- # end
288
- #
289
- # # Produces:
290
- # #
291
- # # CREATE TABLE "foo" (
292
- # # "id" serial primary key,
293
- # # "fancy_id" integer DEFAULT NULL NULL,
294
- # # "another_fancy_id" integer DEFAULT NULL NULL,
295
- # # UNIQUE ("fancy_id", "another_fancy_id")
296
- # # );
277
+ # create_table(:foo) do |t|
278
+ # t.integer :fancy_id
279
+ # t.integer :another_fancy_id
280
+ # t.unique_constraint [ :fancy_id, :another_fancy_id ]
281
+ # end
282
+ #
283
+ # # Produces:
284
+ # #
285
+ # # CREATE TABLE "foo" (
286
+ # # "id" serial primary key,
287
+ # # "fancy_id" integer DEFAULT NULL NULL,
288
+ # # "another_fancy_id" integer DEFAULT NULL NULL,
289
+ # # UNIQUE ("fancy_id", "another_fancy_id")
290
+ # # );
297
291
  #
298
292
  # See below for additional options.
299
293
  #
@@ -312,18 +306,17 @@ module ActiveRecord
312
306
  #
313
307
  # ==== Examples:
314
308
  #
315
- # ### ruby
316
- # # using the constraint method:
317
- # add_unique_constraint(:foo, [ :fancy_id, :another_fancy_id ])
318
- # # => ALTER TABLE "foo" ADD UNIQUE ("fancy_id", "another_fancy_id");
309
+ # # using the constraint method:
310
+ # add_unique_constraint(:foo, [ :fancy_id, :another_fancy_id ])
311
+ # # => ALTER TABLE "foo" ADD UNIQUE ("fancy_id", "another_fancy_id");
319
312
  #
320
- # # using create_index:
321
- # create_index('my_index_name', :foo, [ :fancy_id, :another_fancy_id ], :unique => true)
322
- # # => CREATE UNIQUE INDEX "my_index_name" ON "foo"("fancy_id", "another_fancy_id");
313
+ # # using create_index:
314
+ # create_index('my_index_name', :foo, [ :fancy_id, :another_fancy_id ], :unique => true)
315
+ # # => CREATE UNIQUE INDEX "my_index_name" ON "foo"("fancy_id", "another_fancy_id");
323
316
  #
324
- # # using the standard ActiveRecord add_index:
325
- # add_index(:foo, [ :fancy_id, :another_fancy_id ], :unique => true)
326
- # # => CREATE UNIQUE INDEX "index_foo_on_fancy_id_and_another_fancy_id" ON "foo" ("fancy_id", "another_fancy_id");
317
+ # # using the standard ActiveRecord add_index:
318
+ # add_index(:foo, [ :fancy_id, :another_fancy_id ], :unique => true)
319
+ # # => CREATE UNIQUE INDEX "index_foo_on_fancy_id_and_another_fancy_id" ON "foo" ("fancy_id", "another_fancy_id");
327
320
  #
328
321
  # You'll notice that in create_index we must manually supply a name
329
322
  # while add_index can generate one for us automatically. See the
@@ -395,18 +388,17 @@ module ActiveRecord
395
388
  #
396
389
  # ==== Example:
397
390
  #
398
- # ### ruby
399
- # create_table(:foo) do |t|
400
- # t.integer :bar_id, :references => { :table => :bar, :column => :id }
401
- # end
391
+ # create_table(:foo) do |t|
392
+ # t.integer :bar_id, :references => { :table => :bar, :column => :id }
393
+ # end
402
394
  #
403
- # # Produces:
404
- # #
405
- # # CREATE TABLE "foo" (
406
- # # "id" serial primary key,
407
- # # "bar_id" integer DEFAULT NULL NULL,
408
- # # FOREIGN KEY ("bar_id") REFERENCES "bar" ("id")
409
- # # );
395
+ # # Produces:
396
+ # #
397
+ # # CREATE TABLE "foo" (
398
+ # # "id" serial primary key,
399
+ # # "bar_id" integer DEFAULT NULL NULL,
400
+ # # FOREIGN KEY ("bar_id") REFERENCES "bar" ("id")
401
+ # # );
410
402
  #
411
403
  # You can leave out the :column option if you are following the Rails
412
404
  # standards for foreign key referral, as PostgreSQL automatically
@@ -426,54 +418,52 @@ module ActiveRecord
426
418
  #
427
419
  # The following example produces the same result as above:
428
420
  #
429
- # ### ruby
430
- # create_table(:foo) do |t|
431
- # t.integer :bar_id
432
- # t.foreign_key :bar_id, :bar, :id
433
- # end
421
+ # create_table(:foo) do |t|
422
+ # t.integer :bar_id
423
+ # t.foreign_key :bar_id, :bar, :id
424
+ # end
434
425
  #
435
- # # Produces:
436
- # #
437
- # # CREATE TABLE "foo" (
438
- # # "id" serial primary key,
439
- # # "bar_id" integer DEFAULT NULL NULL,
440
- # # FOREIGN KEY ("bar_id") REFERENCES "bar" ("id")
441
- # # );
426
+ # # Produces:
427
+ # #
428
+ # # CREATE TABLE "foo" (
429
+ # # "id" serial primary key,
430
+ # # "bar_id" integer DEFAULT NULL NULL,
431
+ # # FOREIGN KEY ("bar_id") REFERENCES "bar" ("id")
432
+ # # );
442
433
  #
443
434
  # Defining a FOREIGN KEY constraint on the table-level allows you to
444
435
  # create multicolumn foreign keys. You can define these super advanced
445
436
  # foreign keys thusly:
446
437
  #
447
- # ### ruby
448
- # create_table(:foo) {}
449
- #
450
- # create_table(:bar) do |t|
451
- # t.integer :foo_id
452
- # t.unique_constraint [ :id, :foo_id ]
453
- # end
454
- #
455
- # create_table(:funk) do |t|
456
- # t.integer :bar_id
457
- # t.foreign_key [ :id, :bar_id ], :bar, [ :id, :foo_id ]
458
- # end
459
- #
460
- # # Produces:
461
- # #
462
- # # CREATE TABLE "foo" (
463
- # # "id" serial primary key
464
- # # );
465
- # #
466
- # # CREATE TABLE "bar" (
467
- # # "id" serial primary key,
468
- # # "foo_id" integer DEFAULT NULL NULL,
469
- # # UNIQUE ("id", "foo_id")
470
- # # );
471
- # #
472
- # # CREATE TABLE "funk" (
473
- # # "id" serial primary key,
474
- # # "bar_id" integer DEFAULT NULL NULL,
475
- # # FOREIGN KEY ("id", "bar_id") REFERENCES "bar" ("id", "foo_id")
476
- # # );
438
+ # create_table(:foo) {}
439
+ #
440
+ # create_table(:bar) do |t|
441
+ # t.integer :foo_id
442
+ # t.unique_constraint [ :id, :foo_id ]
443
+ # end
444
+ #
445
+ # create_table(:funk) do |t|
446
+ # t.integer :bar_id
447
+ # t.foreign_key [ :id, :bar_id ], :bar, [ :id, :foo_id ]
448
+ # end
449
+ #
450
+ # # Produces:
451
+ # #
452
+ # # CREATE TABLE "foo" (
453
+ # # "id" serial primary key
454
+ # # );
455
+ # #
456
+ # # CREATE TABLE "bar" (
457
+ # # "id" serial primary key,
458
+ # # "foo_id" integer DEFAULT NULL NULL,
459
+ # # UNIQUE ("id", "foo_id")
460
+ # # );
461
+ # #
462
+ # # CREATE TABLE "funk" (
463
+ # # "id" serial primary key,
464
+ # # "bar_id" integer DEFAULT NULL NULL,
465
+ # # FOREIGN KEY ("id", "bar_id") REFERENCES "bar" ("id", "foo_id")
466
+ # # );
477
467
  #
478
468
  # === Table Manipulation
479
469
  #
@@ -482,18 +472,17 @@ module ActiveRecord
482
472
  #
483
473
  # ==== Examples:
484
474
  #
485
- # ### ruby
486
- # add_foreign_key(:foo, :bar_id, :bar)
487
- # # => ALTER TABLE "funk" ADD FOREIGN KEY ("bar_id") REFERENCES "bar";
475
+ # add_foreign_key(:foo, :bar_id, :bar)
476
+ # # => ALTER TABLE "funk" ADD FOREIGN KEY ("bar_id") REFERENCES "bar";
488
477
  #
489
- # add_foreign_key(:foo, :bar_id, :bar, :id)
490
- # # => ALTER TABLE "funk" ADD FOREIGN KEY ("bar_id") REFERENCES "bar"("id");
478
+ # add_foreign_key(:foo, :bar_id, :bar, :id)
479
+ # # => ALTER TABLE "funk" ADD FOREIGN KEY ("bar_id") REFERENCES "bar"("id");
491
480
  #
492
- # add_foreign_key(:foo, [ :bar_id, :blort_id ], :bar, [ :id, :blort_id ],
493
- # :name => 'my_fk', :match => :simple
494
- # )
495
- # # => ALTER TABLE "foo" ADD CONSTRAINT "my_fk" FOREIGN KEY ("id", "blort_id")
496
- # # REFERENCES "bar" ("id", "blort_id") MATCH SIMPLE;
481
+ # add_foreign_key(:foo, [ :bar_id, :blort_id ], :bar, [ :id, :blort_id ],
482
+ # :name => 'my_fk', :match => :simple
483
+ # )
484
+ # # => ALTER TABLE "foo" ADD CONSTRAINT "my_fk" FOREIGN KEY ("id", "blort_id")
485
+ # # REFERENCES "bar" ("id", "blort_id") MATCH SIMPLE;
497
486
  #
498
487
  # === Options for FOREIGN KEY Constraints
499
488
  #