activerecord 5.0.6 → 5.0.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7347f304b89c7cd71521a62833483343cfbd4f62
4
- data.tar.gz: 546689d6bcbdad06a6d39e43ee5900fee2769164
3
+ metadata.gz: 43441f7c1f6ff6bf9d51237667c9da354396c693
4
+ data.tar.gz: e197da21a11980582efc2769ee478cc32bf3336d
5
5
  SHA512:
6
- metadata.gz: 80ff5733d1a3b06ace2f8ee1bccfacc8b01d04e2a9008733d52e8b85dc1a4df7a569c136d22dec6348ab633309e2f9d4560e9bd4d6d44ae514720c2fedf5c22f
7
- data.tar.gz: 11efa39812618896f495aa36bdbf9e2f18dad0a514e365548b7ec207737adc75da5b907695377eb8e93042c2f175521fb2fe643c4d70eb33871bf0d78aa59e8c
6
+ metadata.gz: 8db63b4a21892e82034f68ccf8be0daf7cd963521b520355e17b8d8e44bf21b60bc88f72362a7a2ff32200293b8c1564f35193b98b16b40d5824767273875141
7
+ data.tar.gz: d698e7b2f3d86c7735d062c10b9f02d9333fbeb1ea9bf8a3afdaa9501bab0ef590c985257b1019a5e4f117fd76a962e8c69f1a9999e86285d7d01682675b761a
@@ -1,3 +1,71 @@
1
+ ## Rails 5.0.7 (March 29, 2018) ##
2
+
3
+ * Apply time column precision on assignment.
4
+
5
+ PR #20317 changed the behavior of datetime columns so that when they
6
+ have a specified precision then on assignment the value is rounded to
7
+ that precision. This behavior is now applied to time columns as well.
8
+
9
+ Fixes #30301.
10
+
11
+ *Andrew White*
12
+
13
+ * Normalize time column values for SQLite database.
14
+
15
+ For legacy reasons, time columns in SQLite are stored as full datetimes
16
+ because until #24542 the quoting for time columns didn't remove the date
17
+ component. To ensure that values are consistent we now normalize the
18
+ date component to 2001-01-01 on reading and writing.
19
+
20
+ *Andrew White*
21
+
22
+ * Ensure that the date component is removed when quoting times.
23
+
24
+ PR #24542 altered the quoting for time columns so that the date component
25
+ was removed however it only removed it when it was 2001-01-01. Now the
26
+ date component is removed irrespective of what the date is.
27
+
28
+ *Andrew White*
29
+
30
+ * Query cache was unavailable when entering the `ActiveRecord::Base.cache` block
31
+ without being connected.
32
+
33
+ *Tsukasa Oishi*
34
+
35
+ * Fix `bin/rails db:setup` and `bin/rails db:test:prepare` create wrong
36
+ ar_internal_metadata's data for a test database.
37
+
38
+ Before:
39
+ ```
40
+ $ RAILS_ENV=test rails dbconsole
41
+ > SELECT * FROM ar_internal_metadata;
42
+ key|value|created_at|updated_at
43
+ environment|development|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
44
+ ```
45
+
46
+ After:
47
+ ```
48
+ $ RAILS_ENV=test rails dbconsole
49
+ > SELECT * FROM ar_internal_metadata;
50
+ key|value|created_at|updated_at
51
+ environment|test|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
52
+ ```
53
+
54
+ Fixes #26731.
55
+
56
+ *bogdanvlviv*
57
+
58
+ * Fix longer sequence name detection for serial columns.
59
+
60
+ Fixes #28332.
61
+
62
+ *Ryuta Kamizono*
63
+
64
+ * Use `max_identifier_length` for `index_name_length` in PostgreSQL adapter.
65
+
66
+ *Ryuta Kamizono*
67
+
68
+
1
69
  ## Rails 5.0.6 (September 07, 2017) ##
2
70
 
3
71
  * No changes.
@@ -63,11 +63,8 @@ module ActiveRecord
63
63
  else
64
64
  klass.send(:build_default_scope, relation)
65
65
  end
66
- scope_chain_items.concat [klass_scope].compact
67
66
 
68
- rel = scope_chain_items.inject(scope_chain_items.shift) do |left, right|
69
- left.merge right
70
- end
67
+ rel = scope_chain_items.inject(klass_scope || scope_chain_items.shift, &:merge!)
71
68
 
72
69
  if rel && !rel.arel.constraints.empty?
73
70
  binds += rel.bound_attributes
@@ -131,42 +131,15 @@ module ActiveRecord
131
131
  end
132
132
 
133
133
  def build_scope
134
- scope = klass.unscoped
134
+ scope = klass.scope_for_association
135
135
 
136
- values = reflection_scope.values
137
- preload_values = preload_scope.values
138
-
139
- scope.where_clause = reflection_scope.where_clause + preload_scope.where_clause
140
- scope.references_values = Array(values[:references]) + Array(preload_values[:references])
141
-
142
- if preload_values[:select] || values[:select]
143
- scope._select!(preload_values[:select] || values[:select])
144
- end
145
- scope.includes! preload_values[:includes] || values[:includes]
146
- if preload_scope.joins_values.any?
147
- scope.joins!(preload_scope.joins_values)
148
- else
149
- scope.joins!(reflection_scope.joins_values)
150
- end
151
-
152
- if order_values = preload_values[:order] || values[:order]
153
- scope.order!(order_values)
154
- end
155
-
156
- if preload_values[:reordering] || values[:reordering]
157
- scope.reordering_value = true
158
- end
159
-
160
- if preload_values[:readonly] || values[:readonly]
161
- scope.readonly!
162
- end
163
-
164
- if options[:as]
165
- scope.where!(klass.table_name => { reflection.type => model.base_class.sti_name })
136
+ if reflection.type
137
+ scope.where!(reflection.type => model.base_class.sti_name)
166
138
  end
167
139
 
168
- scope.unscope_values = Array(values[:unscope]) + Array(preload_values[:unscope])
169
- klass.scope_for_association.merge(scope)
140
+ scope.merge!(reflection_scope)
141
+ scope.merge!(preload_scope) if preload_scope != NULL_RELATION
142
+ scope
170
143
  end
171
144
  end
172
145
  end
@@ -79,20 +79,26 @@ module ActiveRecord
79
79
  end
80
80
  end
81
81
 
82
-
83
82
  def through_scope
84
83
  scope = through_reflection.klass.unscoped
84
+ values = reflection_scope.values
85
85
 
86
86
  if options[:source_type]
87
87
  scope.where! reflection.foreign_type => options[:source_type]
88
88
  else
89
89
  unless reflection_scope.where_clause.empty?
90
- scope.includes_values = Array(reflection_scope.values[:includes] || options[:source])
90
+ scope.includes_values = Array(values[:includes] || options[:source])
91
91
  scope.where_clause = reflection_scope.where_clause
92
+ if joins = values[:joins]
93
+ scope.joins!(source_reflection.name => joins)
94
+ end
95
+ if left_outer_joins = values[:left_outer_joins]
96
+ scope.left_outer_joins!(source_reflection.name => left_outer_joins)
97
+ end
92
98
  end
93
99
 
94
- scope.references! reflection_scope.values[:references]
95
- if scope.eager_loading? && order_values = reflection_scope.values[:order]
100
+ scope.references! values[:references]
101
+ if scope.eager_loading? && order_values = values[:order]
96
102
  scope = scope.order(order_values)
97
103
  end
98
104
  end
@@ -102,7 +102,7 @@ module ActiveRecord
102
102
 
103
103
  config.active_record.time_zone_aware_types = [:datetime]
104
104
 
105
- To silence this deprecation warning, add the following:
105
+ To use the new behavior, add the following:
106
106
 
107
107
  config.active_record.time_zone_aware_types = [:datetime, :time]
108
108
  MESSAGE
@@ -2,7 +2,7 @@ require 'active_record/attribute_set/builder'
2
2
 
3
3
  module ActiveRecord
4
4
  class AttributeSet # :nodoc:
5
- delegate :fetch, to: :attributes
5
+ delegate :fetch, :except, to: :attributes
6
6
 
7
7
  def initialize(attributes)
8
8
  @attributes = attributes
@@ -3,35 +3,30 @@ require 'active_record/attribute'
3
3
  module ActiveRecord
4
4
  class AttributeSet # :nodoc:
5
5
  class Builder # :nodoc:
6
- attr_reader :types, :always_initialized, :default
6
+ attr_reader :types, :default_attributes
7
7
 
8
- def initialize(types, always_initialized = nil, &default)
8
+ def initialize(types, default_attributes = {})
9
9
  @types = types
10
- @always_initialized = always_initialized
11
- @default = default
10
+ @default_attributes = default_attributes
12
11
  end
13
12
 
14
13
  def build_from_database(values = {}, additional_types = {})
15
- if always_initialized && !values.key?(always_initialized)
16
- values[always_initialized] = nil
17
- end
18
-
19
- attributes = LazyAttributeHash.new(types, values, additional_types, &default)
14
+ attributes = LazyAttributeHash.new(types, values, additional_types, default_attributes)
20
15
  AttributeSet.new(attributes)
21
16
  end
22
17
  end
23
18
  end
24
19
 
25
20
  class LazyAttributeHash # :nodoc:
26
- delegate :transform_values, :each_key, :fetch, to: :materialize
21
+ delegate :transform_values, :each_key, :fetch, :except, to: :materialize
27
22
 
28
- def initialize(types, values, additional_types, &default)
23
+ def initialize(types, values, additional_types, default_attributes, delegate_hash = {})
29
24
  @types = types
30
25
  @values = values
31
26
  @additional_types = additional_types
32
27
  @materialized = false
33
- @delegate_hash = {}
34
- @default = default || proc {}
28
+ @delegate_hash = delegate_hash
29
+ @default_attributes = default_attributes
35
30
  end
36
31
 
37
32
  def key?(key)
@@ -79,15 +74,17 @@ module ActiveRecord
79
74
  end
80
75
 
81
76
  def marshal_dump
82
- materialize
77
+ [@types, @values, @additional_types, @default_attributes, @delegate_hash]
83
78
  end
84
79
 
85
- def marshal_load(delegate_hash)
86
- @delegate_hash = delegate_hash
87
- @types = {}
88
- @values = {}
89
- @additional_types = {}
90
- @materialized = true
80
+ def marshal_load(values)
81
+ if values.is_a?(Hash)
82
+ empty_hash = {}.freeze
83
+ initialize(empty_hash, empty_hash, empty_hash, empty_hash, values)
84
+ @materialized = true
85
+ else
86
+ initialize(*values)
87
+ end
91
88
  end
92
89
 
93
90
  def encode_with(coder)
@@ -100,7 +97,7 @@ module ActiveRecord
100
97
 
101
98
  protected
102
99
 
103
- attr_reader :types, :values, :additional_types, :delegate_hash, :default
100
+ attr_reader :types, :values, :additional_types, :delegate_hash, :default_attributes
104
101
 
105
102
  def materialize
106
103
  unless @materialized
@@ -123,7 +120,12 @@ module ActiveRecord
123
120
  if value_present
124
121
  delegate_hash[name] = Attribute.from_database(name, value, type)
125
122
  elsif types.key?(name)
126
- delegate_hash[name] = default.call(name) || Attribute.uninitialized(name, type)
123
+ attr = default_attributes[name]
124
+ if attr
125
+ delegate_hash[name] = attr.dup
126
+ else
127
+ delegate_hash[name] = Attribute.uninitialized(name, type)
128
+ end
127
129
  end
128
130
  end
129
131
  end
@@ -101,8 +101,14 @@ module ActiveRecord
101
101
  def cache_sql(sql, binds)
102
102
  result =
103
103
  if @query_cache[sql].key?(binds)
104
- ActiveSupport::Notifications.instrument("sql.active_record",
105
- :sql => sql, :binds => binds, :name => "CACHE", :connection_id => object_id)
104
+ ActiveSupport::Notifications.instrument(
105
+ "sql.active_record",
106
+ sql: sql,
107
+ binds: binds,
108
+ type_casted_binds: -> { type_casted_binds(binds) },
109
+ name: "CACHE",
110
+ connection_id: object_id,
111
+ )
106
112
  @query_cache[sql][binds]
107
113
  else
108
114
  @query_cache[sql][binds] = yield
@@ -148,7 +148,7 @@ module ActiveRecord
148
148
  end
149
149
 
150
150
  def quoted_time(value) # :nodoc:
151
- quoted_date(value).sub(/\A2000-01-01 /, '')
151
+ quoted_date(value).sub(/\A\d\d\d\d-\d\d-\d\d /, '')
152
152
  end
153
153
 
154
154
  def prepare_binds_for_database(binds) # :nodoc:
@@ -68,7 +68,7 @@ module ActiveRecord
68
68
  @statements = StatementPool.new(self.class.type_cast_config_to_integer(config[:statement_limit]))
69
69
 
70
70
  if version < '5.0.0'
71
- raise "Your version of MySQL (#{full_version.match(/^\d+\.\d+\.\d+/)[0]}) is too old. Active Record supports MySQL >= 5.0."
71
+ raise "Your version of MySQL (#{version_string}) is too old. Active Record supports MySQL >= 5.0."
72
72
  end
73
73
  end
74
74
 
@@ -81,7 +81,7 @@ module ActiveRecord
81
81
  end
82
82
 
83
83
  def version #:nodoc:
84
- @version ||= Version.new(full_version.match(/^\d+\.\d+\.\d+/)[0])
84
+ @version ||= Version.new(version_string)
85
85
  end
86
86
 
87
87
  def mariadb? # :nodoc:
@@ -399,8 +399,8 @@ module ActiveRecord
399
399
  table_name = table_name.to_s
400
400
  column_definitions(table_name).map do |field|
401
401
  type_metadata = fetch_type_metadata(field[:Type], field[:Extra])
402
- if type_metadata.type == :datetime && field[:Default] == "CURRENT_TIMESTAMP"
403
- default, default_function = nil, field[:Default]
402
+ if type_metadata.type == :datetime && field[:Default] =~ /\ACURRENT_TIMESTAMP(?:\(\))?\z/i
403
+ default, default_function = nil, "CURRENT_TIMESTAMP"
404
404
  else
405
405
  default, default_function = field[:Default], nil
406
406
  end
@@ -940,6 +940,10 @@ module ActiveRecord
940
940
  end
941
941
  end
942
942
 
943
+ def version_string
944
+ full_version.match(/^(?:5\.5\.5-)?(\d+\.\d+\.\d+)/)[1]
945
+ end
946
+
943
947
  class MysqlJson < Type::Internal::AbstractJson # :nodoc:
944
948
  def changed_in_place?(raw_old_value, new_value)
945
949
  # Normalization is required because MySQL JSON data format includes
@@ -13,7 +13,7 @@ module ActiveRecord
13
13
  # +default+ is the type-casted default value, such as +new+ in <tt>sales_stage varchar(20) default 'new'</tt>.
14
14
  # +sql_type_metadata+ is various information about the type of the column
15
15
  # +null+ determines if this column allows +NULL+ values.
16
- def initialize(name, default, sql_type_metadata = nil, null = true, table_name = nil, default_function = nil, collation = nil, comment: nil)
16
+ def initialize(name, default, sql_type_metadata = nil, null = true, table_name = nil, default_function = nil, collation = nil, comment: nil, **)
17
17
  @name = name.freeze
18
18
  @table_name = table_name
19
19
  @sql_type_metadata = sql_type_metadata
@@ -1,7 +1,7 @@
1
1
  require 'active_record/connection_adapters/abstract_mysql_adapter'
2
2
  require 'active_record/connection_adapters/mysql/database_statements'
3
3
 
4
- gem 'mysql2', '>= 0.3.18', '< 0.5'
4
+ gem 'mysql2', '>= 0.3.18', '< 0.6.0'
5
5
  require 'mysql2'
6
6
  raise 'mysql2 0.4.3 is not supported. Please upgrade to 0.4.4+' if Mysql2::VERSION == '0.4.3'
7
7
 
@@ -5,11 +5,38 @@ module ActiveRecord
5
5
  delegate :array, :oid, :fmod, to: :sql_type_metadata
6
6
  alias :array? :array
7
7
 
8
+ def initialize(*, max_identifier_length: 63, **)
9
+ super
10
+ @max_identifier_length = max_identifier_length
11
+ end
12
+
8
13
  def serial?
9
14
  return unless default_function
10
15
 
11
- %r{\Anextval\('"?#{table_name}_#{name}_seq"?'::regclass\)\z} === default_function
16
+ if %r{\Anextval\('"?(?<sequence_name>.+_(?<suffix>seq\d*))"?'::regclass\)\z} =~ default_function
17
+ sequence_name_from_parts(table_name, name, suffix) == sequence_name
18
+ end
12
19
  end
20
+
21
+ protected
22
+ attr_reader :max_identifier_length
23
+
24
+ private
25
+ def sequence_name_from_parts(table_name, column_name, suffix)
26
+ over_length = [table_name, column_name, suffix].map(&:length).sum + 2 - max_identifier_length
27
+
28
+ if over_length > 0
29
+ column_name_length = [(max_identifier_length - suffix.length - 2) / 2, column_name.length].min
30
+ over_length -= column_name.length - column_name_length
31
+ column_name = column_name[0, column_name_length - [over_length, 0].min]
32
+ end
33
+
34
+ if over_length > 0
35
+ table_name = table_name[0, table_name.length - over_length]
36
+ end
37
+
38
+ "#{table_name}_#{column_name}_#{suffix}"
39
+ end
13
40
  end
14
41
  end
15
42
  end
@@ -230,7 +230,7 @@ module ActiveRecord
230
230
  type_metadata = fetch_type_metadata(column_name, type, oid, fmod)
231
231
  default_value = extract_value_from_default(default)
232
232
  default_function = extract_default_function(default_value, default)
233
- new_column(column_name, default_value, type_metadata, !notnull, table_name, default_function, collation, comment: comment.presence)
233
+ new_column(column_name, default_value, type_metadata, !notnull, table_name, default_function, collation, comment: comment.presence, max_identifier_length: max_identifier_length)
234
234
  end
235
235
  end
236
236
 
@@ -629,10 +629,6 @@ module ActiveRecord
629
629
  end
630
630
  end
631
631
 
632
- def index_name_length
633
- 63
634
- end
635
-
636
632
  # Maps logical Rails types to PostgreSQL-specific data types.
637
633
  def type_to_sql(type, limit = nil, precision = nil, scale = nil, array = nil)
638
634
  sql = case type.to_s
@@ -1,5 +1,5 @@
1
1
  # Make sure we're using pg high enough for type casts and Ruby 2.2+ compatibility
2
- gem 'pg', '~> 0.18'
2
+ gem "pg", ">= 0.18", "< 2.0"
3
3
  require 'pg'
4
4
 
5
5
  require "active_record/connection_adapters/abstract_adapter"
@@ -212,7 +212,7 @@ module ActiveRecord
212
212
 
213
213
  # @local_tz is initialized as nil to avoid warnings when connect tries to use it
214
214
  @local_tz = nil
215
- @table_alias_length = nil
215
+ @max_identifier_length = nil
216
216
 
217
217
  connect
218
218
  add_pg_encoders
@@ -358,9 +358,11 @@ module ActiveRecord
358
358
  end
359
359
 
360
360
  # Returns the configured supported identifier length supported by PostgreSQL
361
- def table_alias_length
362
- @table_alias_length ||= query('SHOW max_identifier_length', 'SCHEMA')[0][0].to_i
361
+ def max_identifier_length
362
+ @max_identifier_length ||= query('SHOW max_identifier_length', 'SCHEMA')[0][0].to_i
363
363
  end
364
+ alias table_alias_length max_identifier_length
365
+ alias index_name_length max_identifier_length
364
366
 
365
367
  # Set the authorized user for this session
366
368
  def session_auth=(user)
@@ -15,7 +15,7 @@ module ActiveRecord
15
15
  end
16
16
 
17
17
  def quoted_time(value)
18
- quoted_date(value)
18
+ quoted_date(value).sub(/\A\d\d\d\d-\d\d-\d\d /, "2000-01-01 ")
19
19
  end
20
20
 
21
21
  private
@@ -7,7 +7,7 @@ module ActiveRecord
7
7
  module VERSION
8
8
  MAJOR = 5
9
9
  MINOR = 0
10
- TINY = 6
10
+ TINY = 7
11
11
  PRE = nil
12
12
 
13
13
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
@@ -33,7 +33,7 @@ module ActiveRecord
33
33
  binds = nil
34
34
 
35
35
  unless (payload[:binds] || []).empty?
36
- casted_params = type_casted_binds(payload[:binds], payload[:type_casted_binds])
36
+ casted_params = type_casted_binds(payload[:type_casted_binds])
37
37
  binds = " " + payload[:binds].zip(casted_params).map { |attr, value|
38
38
  render_bind(attr, value)
39
39
  }.inspect
@@ -47,8 +47,8 @@ module ActiveRecord
47
47
 
48
48
  private
49
49
 
50
- def type_casted_binds(binds, casted_binds)
51
- casted_binds || ActiveRecord::Base.connection.type_casted_binds(binds)
50
+ def type_casted_binds(casted_binds)
51
+ casted_binds.respond_to?(:call) ? casted_binds.call : casted_binds
52
52
  end
53
53
 
54
54
  def render_bind(attr, value)
@@ -113,20 +113,6 @@ module ActiveRecord
113
113
  # If true, the default table name for a Product class will be "products". If false, it would just be "product".
114
114
  # See table_name for the full rules on table/class naming. This is true, by default.
115
115
 
116
- ##
117
- # :singleton-method: ignored_columns
118
- # :call-seq: ignored_columns
119
- #
120
- # The list of columns names the model should ignore. Ignored columns won't have attribute
121
- # accessors defined, and won't be referenced in SQL queries.
122
-
123
- ##
124
- # :singleton-method: ignored_columns=
125
- # :call-seq: ignored_columns=(columns)
126
- #
127
- # Sets the columns names the model should ignore. Ignored columns won't have attribute
128
- # accessors defined, and won't be referenced in SQL queries.
129
-
130
116
  included do
131
117
  mattr_accessor :primary_key_prefix_type, instance_writer: false
132
118
 
@@ -148,10 +134,8 @@ module ActiveRecord
148
134
  class_attribute :pluralize_table_names, instance_writer: false
149
135
  self.pluralize_table_names = true
150
136
 
151
- class_attribute :ignored_columns, instance_accessor: false
152
- self.ignored_columns = [].freeze
153
-
154
137
  self.inheritance_column = 'type'
138
+ self.ignored_columns = [].freeze
155
139
 
156
140
  delegate :type_for_attribute, to: :class
157
141
 
@@ -282,6 +266,22 @@ module ActiveRecord
282
266
  @explicit_inheritance_column = true
283
267
  end
284
268
 
269
+ # The list of columns names the model should ignore. Ignored columns won't have attribute
270
+ # accessors defined, and won't be referenced in SQL queries.
271
+ def ignored_columns
272
+ if defined?(@ignored_columns)
273
+ @ignored_columns
274
+ else
275
+ superclass.ignored_columns
276
+ end
277
+ end
278
+
279
+ # Sets the columns names the model should ignore. Ignored columns won't have attribute
280
+ # accessors defined, and won't be referenced in SQL queries.
281
+ def ignored_columns=(columns)
282
+ @ignored_columns = columns.map(&:to_s)
283
+ end
284
+
285
285
  def sequence_name
286
286
  if base_class == self
287
287
  @sequence_name ||= reset_sequence_name
@@ -332,11 +332,11 @@ module ActiveRecord
332
332
  end
333
333
 
334
334
  def attributes_builder # :nodoc:
335
- @attributes_builder ||= AttributeSet::Builder.new(attribute_types, primary_key) do |name|
336
- unless columns_hash.key?(name)
337
- _default_attributes[name].dup
338
- end
335
+ unless defined?(@attributes_builder) && @attributes_builder
336
+ defaults = _default_attributes.except(*(column_names - [primary_key]))
337
+ @attributes_builder = AttributeSet::Builder.new(attribute_types, defaults)
339
338
  end
339
+ @attributes_builder
340
340
  end
341
341
 
342
342
  def columns_hash # :nodoc:
@@ -5,7 +5,7 @@ module ActiveRecord
5
5
  # Enable the query cache within the block if Active Record is configured.
6
6
  # If it's not, it will execute the given block.
7
7
  def cache(&block)
8
- if connected?
8
+ if connected? || !configurations.empty?
9
9
  connection.cache(&block)
10
10
  else
11
11
  yield
@@ -15,7 +15,7 @@ module ActiveRecord
15
15
  # Disable the query cache within the block if Active Record is configured.
16
16
  # If it's not, it will execute the given block.
17
17
  def uncached(&block)
18
- if connected?
18
+ if connected? || !configurations.empty?
19
19
  connection.uncached(&block)
20
20
  else
21
21
  yield
@@ -323,7 +323,7 @@ db_namespace = namespace :db do
323
323
  begin
324
324
  should_reconnect = ActiveRecord::Base.connection_pool.active_connection?
325
325
  ActiveRecord::Schema.verbose = false
326
- ActiveRecord::Tasks::DatabaseTasks.load_schema ActiveRecord::Base.configurations['test'], :ruby, ENV['SCHEMA']
326
+ ActiveRecord::Tasks::DatabaseTasks.load_schema ActiveRecord::Base.configurations["test"], :ruby, ENV["SCHEMA"], "test"
327
327
  ensure
328
328
  if should_reconnect
329
329
  ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[ActiveRecord::Tasks::DatabaseTasks.env])
@@ -333,7 +333,7 @@ db_namespace = namespace :db do
333
333
 
334
334
  # desc "Recreate the test database from an existent structure.sql file"
335
335
  task :load_structure => %w(db:test:purge) do
336
- ActiveRecord::Tasks::DatabaseTasks.load_schema ActiveRecord::Base.configurations['test'], :sql, ENV['SCHEMA']
336
+ ActiveRecord::Tasks::DatabaseTasks.load_schema ActiveRecord::Base.configurations["test"], :sql, ENV["SCHEMA"], "test"
337
337
  end
338
338
 
339
339
  # desc "Recreate the test database from a fresh schema"
@@ -42,7 +42,7 @@ module ActiveRecord
42
42
  end
43
43
 
44
44
  def associated_table(table_name)
45
- association = klass._reflect_on_association(table_name) || klass._reflect_on_association(table_name.singularize)
45
+ association = klass._reflect_on_association(table_name) || klass._reflect_on_association(table_name.to_s.singularize)
46
46
 
47
47
  if !association && table_name == arel_table.name
48
48
  return self
@@ -215,22 +215,22 @@ module ActiveRecord
215
215
  class_for_adapter(configuration['adapter']).new(*arguments).structure_load(filename)
216
216
  end
217
217
 
218
- def load_schema(configuration, format = ActiveRecord::Base.schema_format, file = nil) # :nodoc:
218
+ def load_schema(configuration, format = ActiveRecord::Base.schema_format, file = nil, environment = env) # :nodoc:
219
219
  file ||= schema_file(format)
220
220
 
221
+ check_schema_file(file)
222
+ ActiveRecord::Base.establish_connection(configuration)
223
+
221
224
  case format
222
225
  when :ruby
223
- check_schema_file(file)
224
- ActiveRecord::Base.establish_connection(configuration)
225
226
  load(file)
226
227
  when :sql
227
- check_schema_file(file)
228
228
  structure_load(configuration, file)
229
229
  else
230
230
  raise ArgumentError, "unknown format #{format.inspect}"
231
231
  end
232
232
  ActiveRecord::InternalMetadata.create_table
233
- ActiveRecord::InternalMetadata[:environment] = ActiveRecord::Migrator.current_environment
233
+ ActiveRecord::InternalMetadata[:environment] = environment
234
234
  end
235
235
 
236
236
  def load_schema_for(*args)
@@ -251,8 +251,8 @@ module ActiveRecord
251
251
  end
252
252
 
253
253
  def load_schema_current(format = ActiveRecord::Base.schema_format, file = nil, environment = env)
254
- each_current_configuration(environment) { |configuration|
255
- load_schema configuration, format, file
254
+ each_current_configuration(environment) { |configuration, configuration_environment|
255
+ load_schema configuration, format, file, configuration_environment
256
256
  }
257
257
  ActiveRecord::Base.establish_connection(environment.to_sym)
258
258
  end
@@ -289,9 +289,10 @@ module ActiveRecord
289
289
  environments = [environment]
290
290
  environments << 'test' if environment == 'development'
291
291
 
292
- configurations = ActiveRecord::Base.configurations.values_at(*environments)
293
- configurations.compact.each do |configuration|
294
- yield configuration unless configuration['database'].blank?
292
+ ActiveRecord::Base.configurations.slice(*environments).each do |configuration_environment, configuration|
293
+ next unless configuration["database"]
294
+
295
+ yield configuration, configuration_environment
295
296
  end
296
297
  end
297
298
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.6
4
+ version: 5.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-08 00:00:00.000000000 Z
11
+ date: 2018-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 5.0.6
19
+ version: 5.0.7
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 5.0.6
26
+ version: 5.0.7
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activemodel
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 5.0.6
33
+ version: 5.0.7
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 5.0.6
40
+ version: 5.0.7
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: arel
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -328,7 +328,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
328
328
  version: '0'
329
329
  requirements: []
330
330
  rubyforge_project:
331
- rubygems_version: 2.6.13
331
+ rubygems_version: 2.6.14
332
332
  signing_key:
333
333
  specification_version: 4
334
334
  summary: Object-relational mapper framework (part of Rails).