activerecord 4.2.0.beta1 → 4.2.0.beta2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activerecord might be problematic. Click here for more details.

Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +137 -38
  3. data/lib/active_record/associations.rb +78 -13
  4. data/lib/active_record/associations/association_scope.rb +53 -40
  5. data/lib/active_record/associations/collection_association.rb +1 -1
  6. data/lib/active_record/associations/collection_proxy.rb +4 -4
  7. data/lib/active_record/associations/has_many_through_association.rb +6 -6
  8. data/lib/active_record/associations/join_dependency/join_association.rb +1 -1
  9. data/lib/active_record/associations/preloader.rb +32 -23
  10. data/lib/active_record/associations/singular_association.rb +1 -1
  11. data/lib/active_record/associations/through_association.rb +5 -1
  12. data/lib/active_record/attribute_methods.rb +7 -7
  13. data/lib/active_record/attribute_methods/dirty.rb +20 -9
  14. data/lib/active_record/attribute_methods/query.rb +1 -1
  15. data/lib/active_record/attribute_methods/read.rb +1 -3
  16. data/lib/active_record/attribute_methods/serialization.rb +3 -4
  17. data/lib/active_record/attribute_methods/time_zone_conversion.rb +2 -0
  18. data/lib/active_record/autosave_association.rb +3 -3
  19. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +1 -1
  20. data/lib/active_record/connection_adapters/abstract/database_statements.rb +5 -0
  21. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +2 -0
  22. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +5 -8
  23. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +8 -4
  24. data/lib/active_record/connection_adapters/abstract/transaction.rb +11 -5
  25. data/lib/active_record/connection_adapters/abstract_adapter.rb +7 -1
  26. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +23 -15
  27. data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -1
  28. data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -1
  29. data/lib/active_record/connection_adapters/postgresql/oid/range.rb +4 -4
  30. data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +2 -0
  31. data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +3 -5
  32. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +8 -6
  33. data/lib/active_record/connection_adapters/postgresql_adapter.rb +9 -6
  34. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +6 -5
  35. data/lib/active_record/core.rb +11 -3
  36. data/lib/active_record/counter_cache.rb +1 -1
  37. data/lib/active_record/fixtures.rb +15 -8
  38. data/lib/active_record/gem_version.rb +2 -2
  39. data/lib/active_record/migration.rb +8 -12
  40. data/lib/active_record/reflection.rb +20 -18
  41. data/lib/active_record/relation/calculations.rb +7 -7
  42. data/lib/active_record/relation/finder_methods.rb +10 -9
  43. data/lib/active_record/relation/predicate_builder.rb +2 -2
  44. data/lib/active_record/relation/predicate_builder/array_handler.rb +12 -4
  45. data/lib/active_record/relation/query_methods.rb +8 -12
  46. data/lib/active_record/schema_dumper.rb +20 -28
  47. data/lib/active_record/tasks/database_tasks.rb +9 -5
  48. data/lib/active_record/transactions.rb +9 -9
  49. data/lib/active_record/type.rb +1 -0
  50. data/lib/active_record/type/binary.rb +10 -0
  51. data/lib/active_record/type/decorator.rb +14 -0
  52. data/lib/active_record/type/serialized.rb +8 -3
  53. metadata +7 -6
@@ -20,7 +20,7 @@ module ActiveRecord
20
20
  def reset_counters(id, *counters)
21
21
  object = find(id)
22
22
  counters.each do |counter_association|
23
- has_many_association = _reflect_on_association(counter_association.to_sym)
23
+ has_many_association = _reflect_on_association(counter_association)
24
24
  unless has_many_association
25
25
  has_many = reflect_on_all_associations(:has_many)
26
26
  has_many_association = has_many.find { |association| association.counter_cache_column && association.counter_cache_column.to_sym == counter_association.to_sym }
@@ -126,7 +126,7 @@ module ActiveRecord
126
126
  # that is included in <tt>ActiveRecord::FixtureSet.context_class</tt>.
127
127
  #
128
128
  # - define a helper method in `test_helper.rb`
129
- # class FixtureFileHelpers
129
+ # module FixtureFileHelpers
130
130
  # def file_sha(path)
131
131
  # Digest::SHA2.hexdigest(File.read(Rails.root.join('test/fixtures', path)))
132
132
  # end
@@ -181,6 +181,9 @@ module ActiveRecord
181
181
  # * Stable, autogenerated IDs
182
182
  # * Label references for associations (belongs_to, has_one, has_many)
183
183
  # * HABTM associations as inline lists
184
+ #
185
+ # There are some more advanced features available even if the id is specified:
186
+ #
184
187
  # * Autofilled timestamp columns
185
188
  # * Fixture label interpolation
186
189
  # * Support for YAML defaults
@@ -515,7 +518,7 @@ module ActiveRecord
515
518
  ::File.join(fixtures_directory, fs_name))
516
519
  end
517
520
 
518
- all_loaded_fixtures.update(fixtures_map)
521
+ update_all_loaded_fixtures fixtures_map
519
522
 
520
523
  connection.transaction(:requires_new => true) do
521
524
  fixture_sets.each do |fs|
@@ -562,6 +565,10 @@ module ActiveRecord
562
565
  @context_class ||= Class.new
563
566
  end
564
567
 
568
+ def self.update_all_loaded_fixtures(fixtures_map) # :nodoc:
569
+ all_loaded_fixtures.update(fixtures_map)
570
+ end
571
+
565
572
  attr_reader :table_name, :name, :fixtures, :model_class, :config
566
573
 
567
574
  def initialize(connection, name, class_name, path, config = ActiveRecord::Base)
@@ -654,7 +661,7 @@ module ActiveRecord
654
661
  row[association.foreign_type] = $1
655
662
  end
656
663
 
657
- fk_type = association.active_record.columns_hash[association.foreign_key].type
664
+ fk_type = association.active_record.columns_hash[fk_name].type
658
665
  row[fk_name] = ActiveRecord::FixtureSet.identify(value, fk_type)
659
666
  end
660
667
  when :has_many
@@ -870,11 +877,11 @@ module ActiveRecord
870
877
  def try_to_load_dependency(file_name)
871
878
  require_dependency file_name
872
879
  rescue LoadError => e
873
- # Let's hope the developer has included it
874
- # Let's warn in case this is a subdependency, otherwise
875
- # subdependency error messages are totally cryptic
876
- if ActiveRecord::Base.logger
877
- ActiveRecord::Base.logger.warn("Unable to load #{file_name}, underlying cause #{e.message} \n\n #{e.backtrace.join("\n")}")
880
+ unless fixture_class_names.key?(file_name.pluralize)
881
+ if ActiveRecord::Base.logger
882
+ ActiveRecord::Base.logger.warn("Unable to load #{file_name}, make sure you added it to ActiveSupport::TestCase.set_fixture_class")
883
+ ActiveRecord::Base.logger.warn("underlying cause #{e.message} \n\n #{e.backtrace.join("\n")}")
884
+ end
878
885
  end
879
886
  end
880
887
 
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
- # Returns the version of the currently loaded ActiveRecord as a <tt>Gem::Version</tt>
2
+ # Returns the version of the currently loaded Active Record as a <tt>Gem::Version</tt>
3
3
  def self.gem_version
4
4
  Gem::Version.new VERSION::STRING
5
5
  end
@@ -8,7 +8,7 @@ module ActiveRecord
8
8
  MAJOR = 4
9
9
  MINOR = 2
10
10
  TINY = 0
11
- PRE = "beta1"
11
+ PRE = "beta2"
12
12
 
13
13
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
14
14
  end
@@ -161,21 +161,14 @@ module ActiveRecord
161
161
  # in the <tt>db/migrate/</tt> directory where <tt>timestamp</tt> is the
162
162
  # UTC formatted date and time that the migration was generated.
163
163
  #
164
- # You may then edit the <tt>up</tt> and <tt>down</tt> methods of
165
- # MyNewMigration.
166
- #
167
164
  # There is a special syntactic shortcut to generate migrations that add fields to a table.
168
165
  #
169
166
  # rails generate migration add_fieldname_to_tablename fieldname:string
170
167
  #
171
168
  # This will generate the file <tt>timestamp_add_fieldname_to_tablename</tt>, which will look like this:
172
169
  # class AddFieldnameToTablename < ActiveRecord::Migration
173
- # def up
174
- # add_column :tablenames, :fieldname, :string
175
- # end
176
- #
177
- # def down
178
- # remove_column :tablenames, :fieldname
170
+ # def change
171
+ # add_column :tablenames, :field, :string
179
172
  # end
180
173
  # end
181
174
  #
@@ -188,9 +181,12 @@ module ActiveRecord
188
181
  #
189
182
  # To roll the database back to a previous migration version, use
190
183
  # <tt>rake db:migrate VERSION=X</tt> where <tt>X</tt> is the version to which
191
- # you wish to downgrade. If any of the migrations throw an
192
- # <tt>ActiveRecord::IrreversibleMigration</tt> exception, that step will fail and you'll
193
- # have some manual work to do.
184
+ # you wish to downgrade. Alternatively, you can also use the STEP option if you
185
+ # wish to rollback last few migrations. <tt>rake db:migrate STEP=2</tt> will rollback
186
+ # the latest two migrations.
187
+ #
188
+ # If any of the migrations throw an <tt>ActiveRecord::IrreversibleMigration</tt> exception,
189
+ # that step will fail and you'll have some manual work to do.
194
190
  #
195
191
  # == Database support
196
192
  #
@@ -38,7 +38,7 @@ module ActiveRecord
38
38
  ar.aggregate_reflections = ar.aggregate_reflections.merge(name.to_s => reflection)
39
39
  end
40
40
 
41
- # \Reflection enables interrogating Active Record classes and objects
41
+ # \Reflection enables interrogating of Active Record classes and objects
42
42
  # about their associations and aggregations. This information can,
43
43
  # for example, be used in a form builder that takes an Active Record object
44
44
  # and creates input fields for all of the attributes depending on their type
@@ -339,12 +339,13 @@ module ActiveRecord
339
339
  return unless scope
340
340
 
341
341
  if scope.arity > 0
342
- ActiveSupport::Deprecation.warn <<-WARNING
343
- The association scope '#{name}' is instance dependent (the scope block takes an argument).
344
- Preloading happens before the individual instances are created. This means that there is no instance
345
- being passed to the association scope. This will most likely result in broken or incorrect behavior.
346
- Joining, Preloading and eager loading of these associations is deprecated and will be removed in the future.
347
- WARNING
342
+ ActiveSupport::Deprecation.warn \
343
+ "The association scope '#{name}' is instance dependent (the scope " \
344
+ "block takes an argument). Preloading happens before the individual " \
345
+ "instances are created. This means that there is no instance being " \
346
+ "passed to the association scope. This will most likely result in " \
347
+ "broken or incorrect behavior. Joining, Preloading and eager loading " \
348
+ "of these associations is deprecated and will be removed in the future."
348
349
  end
349
350
  end
350
351
  alias :check_eager_loadable! :check_preloadable!
@@ -727,8 +728,11 @@ Joining, Preloading and eager loading of these associations is deprecated and wi
727
728
  through_scope_chain = through_reflection.scope_chain.map(&:dup)
728
729
 
729
730
  if options[:source_type]
730
- through_scope_chain.first <<
731
- through_reflection.klass.where(foreign_type => options[:source_type])
731
+ type = foreign_type
732
+ source_type = options[:source_type]
733
+ through_scope_chain.first << lambda { |object|
734
+ where(type => source_type)
735
+ }
732
736
  end
733
737
 
734
738
  # Recursively fill out the rest of the array from the through reflection
@@ -787,15 +791,13 @@ Joining, Preloading and eager loading of these associations is deprecated and wi
787
791
  if names.length > 1
788
792
  example_options = options.dup
789
793
  example_options[:source] = source_reflection_names.first
790
- ActiveSupport::Deprecation.warn <<-eowarn
791
- Ambiguous source reflection for through association. Please specify a :source
792
- directive on your declaration like:
793
-
794
- class #{active_record.name} < ActiveRecord::Base
795
- #{macro} :#{name}, #{example_options}
796
- end
797
-
798
- eowarn
794
+ ActiveSupport::Deprecation.warn \
795
+ "Ambiguous source reflection for through association. Please " \
796
+ "specify a :source directive on your declaration like:\n" \
797
+ "\n" \
798
+ " class #{active_record.name} < ActiveRecord::Base\n" \
799
+ " #{macro} :#{name}, #{example_options}\n" \
800
+ " end"
799
801
  end
800
802
 
801
803
  @source_reflection_name = names.first
@@ -19,15 +19,15 @@ module ActiveRecord
19
19
  #
20
20
  # Person.group(:city).count
21
21
  # # => { 'Rome' => 5, 'Paris' => 3 }
22
- #
23
- # If +count+ is used with +group+ for multiple columns, it returns a Hash whose
24
- # keys are an array containing the individual values of each column and the value
22
+ #
23
+ # If +count+ is used with +group+ for multiple columns, it returns a Hash whose
24
+ # keys are an array containing the individual values of each column and the value
25
25
  # of each key would be the +count+.
26
- #
26
+ #
27
27
  # Article.group(:status, :category).count
28
- # # => {["draft", "business"]=>10, ["draft", "technology"]=>4,
28
+ # # => {["draft", "business"]=>10, ["draft", "technology"]=>4,
29
29
  # ["published", "business"]=>0, ["published", "technology"]=>2}
30
- #
30
+ #
31
31
  # If +count+ is used with +select+, it will count the selected columns:
32
32
  #
33
33
  # Person.select(:age).count
@@ -274,7 +274,7 @@ module ActiveRecord
274
274
  group_attrs = group_values
275
275
 
276
276
  if group_attrs.first.respond_to?(:to_sym)
277
- association = @klass._reflect_on_association(group_attrs.first.to_sym)
277
+ association = @klass._reflect_on_association(group_attrs.first)
278
278
  associated = group_attrs.size == 1 && association && association.belongs_to? # only count belongs_to associations
279
279
  group_fields = Array(associated ? association.foreign_key : group_attrs)
280
280
  else
@@ -103,7 +103,7 @@ module ActiveRecord
103
103
  # Same as +take+ but raises <tt>ActiveRecord::RecordNotFound</tt> if no record
104
104
  # is found. Note that <tt>take!</tt> accepts no arguments.
105
105
  def take!
106
- take or raise RecordNotFound
106
+ take or raise RecordNotFound.new("Couldn't find #{@klass.name} with [#{arel.where_sql}]")
107
107
  end
108
108
 
109
109
  # Find the first record (or first N records if a parameter is supplied).
@@ -138,7 +138,7 @@ module ActiveRecord
138
138
  # Same as +first+ but raises <tt>ActiveRecord::RecordNotFound</tt> if no record
139
139
  # is found. Note that <tt>first!</tt> accepts no arguments.
140
140
  def first!
141
- first or raise RecordNotFound
141
+ first or raise RecordNotFound.new("Couldn't find #{@klass.name} with [#{arel.where_sql}]")
142
142
  end
143
143
 
144
144
  # Find the last record (or last N records if a parameter is supplied).
@@ -171,7 +171,7 @@ module ActiveRecord
171
171
  # Same as +last+ but raises <tt>ActiveRecord::RecordNotFound</tt> if no record
172
172
  # is found. Note that <tt>last!</tt> accepts no arguments.
173
173
  def last!
174
- last or raise RecordNotFound
174
+ last or raise RecordNotFound.new("Couldn't find #{@klass.name} with [#{arel.where_sql}]")
175
175
  end
176
176
 
177
177
  # Find the second record.
@@ -187,7 +187,7 @@ module ActiveRecord
187
187
  # Same as +second+ but raises <tt>ActiveRecord::RecordNotFound</tt> if no record
188
188
  # is found.
189
189
  def second!
190
- second or raise RecordNotFound
190
+ second or raise RecordNotFound.new("Couldn't find #{@klass.name} with [#{arel.where_sql}]")
191
191
  end
192
192
 
193
193
  # Find the third record.
@@ -203,7 +203,7 @@ module ActiveRecord
203
203
  # Same as +third+ but raises <tt>ActiveRecord::RecordNotFound</tt> if no record
204
204
  # is found.
205
205
  def third!
206
- third or raise RecordNotFound
206
+ third or raise RecordNotFound.new("Couldn't find #{@klass.name} with [#{arel.where_sql}]")
207
207
  end
208
208
 
209
209
  # Find the fourth record.
@@ -219,7 +219,7 @@ module ActiveRecord
219
219
  # Same as +fourth+ but raises <tt>ActiveRecord::RecordNotFound</tt> if no record
220
220
  # is found.
221
221
  def fourth!
222
- fourth or raise RecordNotFound
222
+ fourth or raise RecordNotFound.new("Couldn't find #{@klass.name} with [#{arel.where_sql}]")
223
223
  end
224
224
 
225
225
  # Find the fifth record.
@@ -235,7 +235,7 @@ module ActiveRecord
235
235
  # Same as +fifth+ but raises <tt>ActiveRecord::RecordNotFound</tt> if no record
236
236
  # is found.
237
237
  def fifth!
238
- fifth or raise RecordNotFound
238
+ fifth or raise RecordNotFound.new("Couldn't find #{@klass.name} with [#{arel.where_sql}]")
239
239
  end
240
240
 
241
241
  # Find the forty-second record. Also known as accessing "the reddit".
@@ -251,7 +251,7 @@ module ActiveRecord
251
251
  # Same as +forty_two+ but raises <tt>ActiveRecord::RecordNotFound</tt> if no record
252
252
  # is found.
253
253
  def forty_two!
254
- forty_two or raise RecordNotFound
254
+ forty_two or raise RecordNotFound.new("Couldn't find #{@klass.name} with [#{arel.where_sql}]")
255
255
  end
256
256
 
257
257
  # Returns +true+ if a record exists in the table that matches the +id+ or
@@ -401,8 +401,9 @@ module ActiveRecord
401
401
  "#{quoted_table_name}.#{quoted_primary_key}", relation.order_values)
402
402
 
403
403
  relation = relation.except(:select).select(values).distinct!
404
+ arel = relation.arel
404
405
 
405
- id_rows = @klass.connection.select_all(relation.arel, 'SQL', relation.bind_values)
406
+ id_rows = @klass.connection.select_all(arel, 'SQL', arel.bind_values + relation.bind_values)
406
407
  id_rows.map {|row| row[primary_key]}
407
408
  end
408
409
 
@@ -26,7 +26,7 @@ module ActiveRecord
26
26
  queries << '1=0'
27
27
  else
28
28
  table = Arel::Table.new(column, default_table.engine)
29
- association = klass._reflect_on_association(column.to_sym)
29
+ association = klass._reflect_on_association(column)
30
30
 
31
31
  value.each do |k, v|
32
32
  queries.concat expand(association && association.klass, table, k, v)
@@ -55,7 +55,7 @@ module ActiveRecord
55
55
  #
56
56
  # For polymorphic relationships, find the foreign key and type:
57
57
  # PriceEstimate.where(estimate_of: treasure)
58
- if klass && reflection = klass._reflect_on_association(column.to_sym)
58
+ if klass && reflection = klass._reflect_on_association(column)
59
59
  if reflection.polymorphic? && base_class = polymorphic_base_class_from_value(value)
60
60
  queries << build(table[reflection.foreign_type], base_class)
61
61
  end
@@ -2,12 +2,20 @@ module ActiveRecord
2
2
  class PredicateBuilder
3
3
  class ArrayHandler # :nodoc:
4
4
  def call(attribute, value)
5
- return attribute.in([]) if value.empty?
6
-
7
5
  values = value.map { |x| x.is_a?(Base) ? x.id : x }
8
- ranges, values = values.partition { |v| v.is_a?(Range) }
9
6
  nils, values = values.partition(&:nil?)
10
7
 
8
+ if values.any? { |val| val.is_a?(Array) }
9
+ ActiveSupport::Deprecation.warn "Passing a nested array to Active Record " \
10
+ "finder methods is deprecated and will be removed. Flatten your array " \
11
+ "before using it for 'IN' conditions."
12
+ values = values.flatten
13
+ end
14
+
15
+ return attribute.in([]) if values.empty? && nils.empty?
16
+
17
+ ranges, values = values.partition { |v| v.is_a?(Range) }
18
+
11
19
  values_predicate =
12
20
  case values.length
13
21
  when 0 then NullPredicate
@@ -20,7 +28,7 @@ module ActiveRecord
20
28
  end
21
29
 
22
30
  array_predicates = ranges.map { |range| attribute.in(range) }
23
- array_predicates << values_predicate
31
+ array_predicates.unshift(values_predicate)
24
32
  array_predicates.inject { |composite, predicate| composite.or(predicate) }
25
33
  end
26
34
 
@@ -94,10 +94,8 @@ module ActiveRecord
94
94
  def check_cached_relation # :nodoc:
95
95
  if defined?(@arel) && @arel
96
96
  @arel = nil
97
- ActiveSupport::Deprecation.warn <<-WARNING
98
- Modifying already cached Relation. The cache will be reset.
99
- Use a cloned Relation to prevent this warning.
100
- WARNING
97
+ ActiveSupport::Deprecation.warn "Modifying already cached Relation. The " \
98
+ "cache will be reset. Use a cloned Relation to prevent this warning."
101
99
  end
102
100
  end
103
101
 
@@ -689,11 +687,11 @@ WARNING
689
687
  # end
690
688
  #
691
689
  def none
692
- extending(NullRelation)
690
+ where("1=0").extending!(NullRelation)
693
691
  end
694
692
 
695
693
  def none! # :nodoc:
696
- extending!(NullRelation)
694
+ where!("1=0").extending!(NullRelation)
697
695
  end
698
696
 
699
697
  # Sets readonly attributes for the returned relation. If value is
@@ -881,12 +879,10 @@ WARNING
881
879
  arel.lock(lock_value) if lock_value
882
880
 
883
881
  # Reorder bind indexes if joins produced bind values
884
- if arel.bind_values.any?
885
- bvs = arel.bind_values + bind_values
886
- arel.ast.grep(Arel::Nodes::BindParam).each_with_index do |bp, i|
887
- column = bvs[i].first
888
- bp.replace connection.substitute_at(column, i)
889
- end
882
+ bvs = arel.bind_values + bind_values
883
+ arel.ast.grep(Arel::Nodes::BindParam).each_with_index do |bp, i|
884
+ column = bvs[i].first
885
+ bp.replace connection.substitute_at(column, i)
890
886
  end
891
887
 
892
888
  arel
@@ -100,7 +100,7 @@ HEADER
100
100
  # dump foreign keys at the end to make sure all dependent tables exist.
101
101
  if @connection.supports_foreign_keys?
102
102
  sorted_tables.each do |tbl|
103
- foreign_keys(tbl, stream)
103
+ foreign_keys(tbl, stream) unless ignored?(tbl)
104
104
  end
105
105
  end
106
106
  end
@@ -111,12 +111,7 @@ HEADER
111
111
  tbl = StringIO.new
112
112
 
113
113
  # first dump primary key column
114
- if @connection.respond_to?(:pk_and_sequence_for)
115
- pk, _ = @connection.pk_and_sequence_for(table)
116
- end
117
- if !pk && @connection.respond_to?(:primary_key)
118
- pk = @connection.primary_key(table)
119
- end
114
+ pk = @connection.primary_key(table)
120
115
 
121
116
  tbl.print " create_table #{remove_prefix_and_suffix(table).inspect}"
122
117
  pkcol = columns.detect { |c| c.name == pk }
@@ -188,25 +183,22 @@ HEADER
188
183
  if (indexes = @connection.indexes(table)).any?
189
184
  add_index_statements = indexes.map do |index|
190
185
  statement_parts = [
191
- ('add_index ' + remove_prefix_and_suffix(index.table).inspect),
186
+ "add_index #{remove_prefix_and_suffix(index.table).inspect}",
192
187
  index.columns.inspect,
193
- ('name: ' + index.name.inspect),
188
+ "name: #{index.name.inspect}",
194
189
  ]
195
190
  statement_parts << 'unique: true' if index.unique
196
191
 
197
192
  index_lengths = (index.lengths || []).compact
198
- statement_parts << ('length: ' + Hash[index.columns.zip(index.lengths)].inspect) unless index_lengths.empty?
199
-
200
- index_orders = (index.orders || {})
201
- statement_parts << ('order: ' + index.orders.inspect) unless index_orders.empty?
193
+ statement_parts << "length: #{Hash[index.columns.zip(index.lengths)].inspect}" if index_lengths.any?
202
194
 
203
- statement_parts << ('where: ' + index.where.inspect) if index.where
195
+ index_orders = index.orders || {}
196
+ statement_parts << "order: #{index.orders.inspect}" if index_orders.any?
197
+ statement_parts << "where: #{index.where.inspect}" if index.where
198
+ statement_parts << "using: #{index.using.inspect}" if index.using
199
+ statement_parts << "type: #{index.type.inspect}" if index.type
204
200
 
205
- statement_parts << ('using: ' + index.using.inspect) if index.using
206
-
207
- statement_parts << ('type: ' + index.type.inspect) if index.type
208
-
209
- ' ' + statement_parts.join(', ')
201
+ " #{statement_parts.join(', ')}"
210
202
  end
211
203
 
212
204
  stream.puts add_index_statements.sort.join("\n")
@@ -218,26 +210,26 @@ HEADER
218
210
  if (foreign_keys = @connection.foreign_keys(table)).any?
219
211
  add_foreign_key_statements = foreign_keys.map do |foreign_key|
220
212
  parts = [
221
- 'add_foreign_key ' + remove_prefix_and_suffix(foreign_key.from_table).inspect,
222
- remove_prefix_and_suffix(foreign_key.to_table).inspect,
223
- ]
213
+ "add_foreign_key #{remove_prefix_and_suffix(foreign_key.from_table).inspect}",
214
+ remove_prefix_and_suffix(foreign_key.to_table).inspect,
215
+ ]
224
216
 
225
217
  if foreign_key.column != @connection.foreign_key_column_for(foreign_key.to_table)
226
- parts << ('column: ' + foreign_key.column.inspect)
218
+ parts << "column: #{foreign_key.column.inspect}"
227
219
  end
228
220
 
229
221
  if foreign_key.custom_primary_key?
230
- parts << ('primary_key: ' + foreign_key.primary_key.inspect)
222
+ parts << "primary_key: #{foreign_key.primary_key.inspect}"
231
223
  end
232
224
 
233
225
  if foreign_key.name !~ /^fk_rails_[0-9a-f]{10}$/
234
- parts << ('name: ' + foreign_key.name.inspect)
226
+ parts << "name: #{foreign_key.name.inspect}"
235
227
  end
236
228
 
237
- parts << ('on_update: ' + foreign_key.on_update.inspect) if foreign_key.on_update
238
- parts << ('on_delete: ' + foreign_key.on_delete.inspect) if foreign_key.on_delete
229
+ parts << "on_update: #{foreign_key.on_update.inspect}" if foreign_key.on_update
230
+ parts << "on_delete: #{foreign_key.on_delete.inspect}" if foreign_key.on_delete
239
231
 
240
- ' ' + parts.join(', ')
232
+ " #{parts.join(', ')}"
241
233
  end
242
234
 
243
235
  stream.puts add_foreign_key_statements.sort.join("\n")