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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +137 -38
- data/lib/active_record/associations.rb +78 -13
- data/lib/active_record/associations/association_scope.rb +53 -40
- data/lib/active_record/associations/collection_association.rb +1 -1
- data/lib/active_record/associations/collection_proxy.rb +4 -4
- data/lib/active_record/associations/has_many_through_association.rb +6 -6
- data/lib/active_record/associations/join_dependency/join_association.rb +1 -1
- data/lib/active_record/associations/preloader.rb +32 -23
- data/lib/active_record/associations/singular_association.rb +1 -1
- data/lib/active_record/associations/through_association.rb +5 -1
- data/lib/active_record/attribute_methods.rb +7 -7
- data/lib/active_record/attribute_methods/dirty.rb +20 -9
- data/lib/active_record/attribute_methods/query.rb +1 -1
- data/lib/active_record/attribute_methods/read.rb +1 -3
- data/lib/active_record/attribute_methods/serialization.rb +3 -4
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +2 -0
- data/lib/active_record/autosave_association.rb +3 -3
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +5 -0
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +2 -0
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +5 -8
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +8 -4
- data/lib/active_record/connection_adapters/abstract/transaction.rb +11 -5
- data/lib/active_record/connection_adapters/abstract_adapter.rb +7 -1
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +23 -15
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +4 -4
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +3 -5
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +8 -6
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +9 -6
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +6 -5
- data/lib/active_record/core.rb +11 -3
- data/lib/active_record/counter_cache.rb +1 -1
- data/lib/active_record/fixtures.rb +15 -8
- data/lib/active_record/gem_version.rb +2 -2
- data/lib/active_record/migration.rb +8 -12
- data/lib/active_record/reflection.rb +20 -18
- data/lib/active_record/relation/calculations.rb +7 -7
- data/lib/active_record/relation/finder_methods.rb +10 -9
- data/lib/active_record/relation/predicate_builder.rb +2 -2
- data/lib/active_record/relation/predicate_builder/array_handler.rb +12 -4
- data/lib/active_record/relation/query_methods.rb +8 -12
- data/lib/active_record/schema_dumper.rb +20 -28
- data/lib/active_record/tasks/database_tasks.rb +9 -5
- data/lib/active_record/transactions.rb +9 -9
- data/lib/active_record/type.rb +1 -0
- data/lib/active_record/type/binary.rb +10 -0
- data/lib/active_record/type/decorator.rb +14 -0
- data/lib/active_record/type/serialized.rb +8 -3
- 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
|
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
|
-
#
|
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
|
-
|
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[
|
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
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
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
|
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 = "
|
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
|
174
|
-
# add_column :tablenames, :
|
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.
|
192
|
-
# <tt>
|
193
|
-
#
|
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
|
343
|
-
The association scope '#{name}' is instance dependent (the scope
|
344
|
-
Preloading happens before the individual
|
345
|
-
|
346
|
-
|
347
|
-
|
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
|
-
|
731
|
-
|
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
|
791
|
-
Ambiguous source reflection for through association. Please
|
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
|
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(
|
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
|
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
|
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
|
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
|
98
|
-
|
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
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
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
|
-
|
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
|
-
|
186
|
+
"add_index #{remove_prefix_and_suffix(index.table).inspect}",
|
192
187
|
index.columns.inspect,
|
193
|
-
|
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 <<
|
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
|
-
|
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
|
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
|
-
|
222
|
-
|
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 <<
|
218
|
+
parts << "column: #{foreign_key.column.inspect}"
|
227
219
|
end
|
228
220
|
|
229
221
|
if foreign_key.custom_primary_key?
|
230
|
-
parts <<
|
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 <<
|
226
|
+
parts << "name: #{foreign_key.name.inspect}"
|
235
227
|
end
|
236
228
|
|
237
|
-
parts <<
|
238
|
-
parts <<
|
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
|
-
|
232
|
+
" #{parts.join(', ')}"
|
241
233
|
end
|
242
234
|
|
243
235
|
stream.puts add_foreign_key_statements.sort.join("\n")
|