activerecord 5.0.0.beta3 → 5.0.0.beta4

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 (80) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +225 -8
  3. data/examples/performance.rb +0 -1
  4. data/examples/simple.rb +0 -1
  5. data/lib/active_record.rb +0 -1
  6. data/lib/active_record/associations.rb +10 -6
  7. data/lib/active_record/associations/association.rb +1 -1
  8. data/lib/active_record/associations/builder/collection_association.rb +5 -1
  9. data/lib/active_record/associations/join_dependency.rb +1 -1
  10. data/lib/active_record/associations/preloader.rb +1 -0
  11. data/lib/active_record/associations/preloader/through_association.rb +15 -8
  12. data/lib/active_record/attribute/user_provided_default.rb +10 -5
  13. data/lib/active_record/attribute_methods/time_zone_conversion.rb +1 -1
  14. data/lib/active_record/attributes.rb +3 -3
  15. data/lib/active_record/autosave_association.rb +1 -1
  16. data/lib/active_record/base.rb +2 -1
  17. data/lib/active_record/collection_cache_key.rb +1 -1
  18. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +0 -19
  19. data/lib/active_record/connection_adapters/abstract/database_statements.rb +7 -8
  20. data/lib/active_record/connection_adapters/abstract/query_cache.rb +1 -1
  21. data/lib/active_record/connection_adapters/abstract/quoting.rb +7 -1
  22. data/lib/active_record/connection_adapters/abstract/savepoints.rb +3 -3
  23. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +16 -2
  24. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +9 -4
  25. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +20 -10
  26. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +85 -20
  27. data/lib/active_record/connection_adapters/abstract/transaction.rb +13 -1
  28. data/lib/active_record/connection_adapters/abstract_adapter.rb +37 -16
  29. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +119 -108
  30. data/lib/active_record/connection_adapters/column.rb +5 -6
  31. data/lib/active_record/connection_adapters/mysql/database_statements.rb +125 -0
  32. data/lib/active_record/connection_adapters/mysql/quoting.rb +51 -0
  33. data/lib/active_record/connection_adapters/mysql/schema_creation.rb +27 -6
  34. data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +8 -13
  35. data/lib/active_record/connection_adapters/mysql2_adapter.rb +18 -55
  36. data/lib/active_record/connection_adapters/postgresql/column.rb +0 -1
  37. data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +2 -0
  38. data/lib/active_record/connection_adapters/postgresql/quoting.rb +4 -4
  39. data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +7 -10
  40. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +65 -25
  41. data/lib/active_record/connection_adapters/postgresql_adapter.rb +59 -30
  42. data/lib/active_record/connection_adapters/sqlite3/quoting.rb +48 -0
  43. data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +7 -0
  44. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +19 -56
  45. data/lib/active_record/connection_adapters/statement_pool.rb +6 -4
  46. data/lib/active_record/core.rb +13 -4
  47. data/lib/active_record/enum.rb +1 -1
  48. data/lib/active_record/errors.rb +9 -0
  49. data/lib/active_record/fixture_set/file.rb +7 -1
  50. data/lib/active_record/gem_version.rb +1 -1
  51. data/lib/active_record/locking/optimistic.rb +4 -0
  52. data/lib/active_record/log_subscriber.rb +1 -1
  53. data/lib/active_record/migration.rb +4 -4
  54. data/lib/active_record/migration/compatibility.rb +1 -1
  55. data/lib/active_record/model_schema.rb +12 -0
  56. data/lib/active_record/nested_attributes.rb +1 -1
  57. data/lib/active_record/persistence.rb +1 -1
  58. data/lib/active_record/query_cache.rb +13 -16
  59. data/lib/active_record/querying.rb +1 -1
  60. data/lib/active_record/railtie.rb +8 -11
  61. data/lib/active_record/railties/databases.rake +5 -5
  62. data/lib/active_record/reflection.rb +21 -4
  63. data/lib/active_record/relation.rb +10 -10
  64. data/lib/active_record/relation/batches.rb +29 -9
  65. data/lib/active_record/relation/delegation.rb +0 -1
  66. data/lib/active_record/relation/finder_methods.rb +27 -8
  67. data/lib/active_record/relation/predicate_builder.rb +4 -2
  68. data/lib/active_record/relation/where_clause.rb +2 -1
  69. data/lib/active_record/schema_dumper.rb +39 -24
  70. data/lib/active_record/scoping/default.rb +2 -1
  71. data/lib/active_record/suppressor.rb +5 -1
  72. data/lib/active_record/tasks/database_tasks.rb +6 -4
  73. data/lib/active_record/tasks/mysql_database_tasks.rb +1 -1
  74. data/lib/active_record/type.rb +1 -1
  75. data/lib/active_record/type/internal/abstract_json.rb +1 -5
  76. data/lib/active_record/type/time.rb +12 -0
  77. data/lib/active_record/validations/uniqueness.rb +1 -4
  78. data/lib/rails/generators/active_record/model/model_generator.rb +15 -11
  79. data/lib/rails/generators/active_record/model/templates/application_record.rb +2 -0
  80. metadata +11 -8
@@ -3,6 +3,13 @@ module ActiveRecord
3
3
  module SQLite3
4
4
  class SchemaCreation < AbstractAdapter::SchemaCreation
5
5
  private
6
+
7
+ def column_options(o)
8
+ options = super
9
+ options[:null] = false if o.primary_key
10
+ options
11
+ end
12
+
6
13
  def add_column_options!(sql, options)
7
14
  if options[:collation]
8
15
  sql << " COLLATE \"#{options[:collation]}\""
@@ -1,6 +1,7 @@
1
1
  require 'active_record/connection_adapters/abstract_adapter'
2
2
  require 'active_record/connection_adapters/statement_pool'
3
3
  require 'active_record/connection_adapters/sqlite3/explain_pretty_printer'
4
+ require 'active_record/connection_adapters/sqlite3/quoting'
4
5
  require 'active_record/connection_adapters/sqlite3/schema_creation'
5
6
 
6
7
  gem 'sqlite3', '~> 1.3.6'
@@ -49,7 +50,8 @@ module ActiveRecord
49
50
  # * <tt>:database</tt> - Path to the database file.
50
51
  class SQLite3Adapter < AbstractAdapter
51
52
  ADAPTER_NAME = 'SQLite'.freeze
52
- include Savepoints
53
+
54
+ include SQLite3::Quoting
53
55
 
54
56
  NATIVE_DATABASE_TYPES = {
55
57
  primary_key: 'INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL',
@@ -77,21 +79,15 @@ module ActiveRecord
77
79
  SQLite3::SchemaCreation.new self
78
80
  end
79
81
 
82
+ def arel_visitor # :nodoc:
83
+ Arel::Visitors::SQLite.new(self)
84
+ end
85
+
80
86
  def initialize(connection, logger, connection_options, config)
81
87
  super(connection, logger, config)
82
88
 
83
89
  @active = nil
84
- @statements = StatementPool.new(self.class.type_cast_config_to_integer(config.fetch(:statement_limit) { 1000 }))
85
-
86
- @visitor = Arel::Visitors::SQLite.new self
87
- @quoted_column_names = {}
88
-
89
- if self.class.type_cast_config_to_boolean(config.fetch(:prepared_statements) { true })
90
- @prepared_statements = true
91
- @visitor.extend(DetermineIfPreparableVisitor)
92
- else
93
- @prepared_statements = false
94
- end
90
+ @statements = StatementPool.new(self.class.type_cast_config_to_integer(config[:statement_limit]))
95
91
  end
96
92
 
97
93
  def supports_ddl_transactions?
@@ -133,6 +129,10 @@ module ActiveRecord
133
129
  true
134
130
  end
135
131
 
132
+ def supports_multi_insert?
133
+ sqlite_version >= '3.7.11'
134
+ end
135
+
136
136
  def active?
137
137
  @active != false
138
138
  end
@@ -154,6 +154,10 @@ module ActiveRecord
154
154
  true
155
155
  end
156
156
 
157
+ def valid_type?(type)
158
+ true
159
+ end
160
+
157
161
  # Returns 62. SQLite supports index names up to 64
158
162
  # characters. The rest is used by rails internally to perform
159
163
  # temporary rename operations
@@ -174,44 +178,6 @@ module ActiveRecord
174
178
  true
175
179
  end
176
180
 
177
- # QUOTING ==================================================
178
-
179
- def _quote(value) # :nodoc:
180
- case value
181
- when Type::Binary::Data
182
- "x'#{value.hex}'"
183
- else
184
- super
185
- end
186
- end
187
-
188
- def _type_cast(value) # :nodoc:
189
- case value
190
- when BigDecimal
191
- value.to_f
192
- when String
193
- if value.encoding == Encoding::ASCII_8BIT
194
- super(value.encode(Encoding::UTF_8))
195
- else
196
- super
197
- end
198
- else
199
- super
200
- end
201
- end
202
-
203
- def quote_string(s) #:nodoc:
204
- @connection.class.quote(s)
205
- end
206
-
207
- def quote_table_name_for_assignment(table, attr)
208
- quote_column_name(attr)
209
- end
210
-
211
- def quote_column_name(name) #:nodoc:
212
- @quoted_column_names[name] ||= %Q("#{name.to_s.gsub('"', '""')}")
213
- end
214
-
215
181
  #--
216
182
  # DATABASE STATEMENTS ======================================
217
183
  #++
@@ -266,10 +232,6 @@ module ActiveRecord
266
232
  log(sql, name) { @connection.execute(sql) }
267
233
  end
268
234
 
269
- def select_rows(sql, name = nil, binds = [])
270
- exec_query(sql, name, binds).rows
271
- end
272
-
273
235
  def begin_db_transaction #:nodoc:
274
236
  log('begin transaction',nil) { @connection.transaction }
275
237
  end
@@ -337,7 +299,8 @@ module ActiveRecord
337
299
  end
338
300
 
339
301
  # Returns an array of +Column+ objects for the table specified by +table_name+.
340
- def columns(table_name) #:nodoc:
302
+ def columns(table_name) # :nodoc:
303
+ table_name = table_name.to_s
341
304
  table_structure(table_name).map do |field|
342
305
  case field["dflt_value"]
343
306
  when /^null$/i
@@ -351,7 +314,7 @@ module ActiveRecord
351
314
  collation = field['collation']
352
315
  sql_type = field['type']
353
316
  type_metadata = fetch_type_metadata(sql_type)
354
- new_column(field['name'], field['dflt_value'], type_metadata, field['notnull'].to_i == 0, nil, collation)
317
+ new_column(field['name'], field['dflt_value'], type_metadata, field['notnull'].to_i == 0, table_name, nil, collation)
355
318
  end
356
319
  end
357
320
 
@@ -1,11 +1,13 @@
1
1
  module ActiveRecord
2
2
  module ConnectionAdapters
3
- class StatementPool
3
+ class StatementPool # :nodoc:
4
4
  include Enumerable
5
5
 
6
- def initialize(max = 1000)
6
+ DEFAULT_STATEMENT_LIMIT = 1000
7
+
8
+ def initialize(statement_limit = nil)
7
9
  @cache = Hash.new { |h,pid| h[pid] = {} }
8
- @max = max
10
+ @statement_limit = statement_limit || DEFAULT_STATEMENT_LIMIT
9
11
  end
10
12
 
11
13
  def each(&block)
@@ -25,7 +27,7 @@ module ActiveRecord
25
27
  end
26
28
 
27
29
  def []=(sql, stmt)
28
- while @max <= cache.size
30
+ while @statement_limit <= cache.size
29
31
  dealloc(cache.shift.last)
30
32
  end
31
33
  cache[sql] = stmt
@@ -70,6 +70,14 @@ module ActiveRecord
70
70
  mattr_accessor :schema_format, instance_writer: false
71
71
  self.schema_format = :ruby
72
72
 
73
+ ##
74
+ # :singleton-method:
75
+ # Specifies if an error should be raised on query limit or order being
76
+ # ignored when doing batch queries. Useful in applications where the
77
+ # limit or scope being ignored is error-worthy, rather than a warning.
78
+ mattr_accessor :error_on_ignored_order_or_limit, instance_writer: false
79
+ self.error_on_ignored_order_or_limit = false
80
+
73
81
  ##
74
82
  # :singleton-method:
75
83
  # Specify whether or not to use timestamps for migration versions
@@ -128,7 +136,7 @@ module ActiveRecord
128
136
  end
129
137
 
130
138
  def initialize_find_by_cache # :nodoc:
131
- @find_by_statement_cache = {}.extend(Mutex_m)
139
+ @find_by_statement_cache = { true => {}.extend(Mutex_m), false => {}.extend(Mutex_m) }
132
140
  end
133
141
 
134
142
  def inherited(child_class) # :nodoc:
@@ -151,7 +159,7 @@ module ActiveRecord
151
159
  id = id.id
152
160
  ActiveSupport::Deprecation.warn(<<-MSG.squish)
153
161
  You are passing an instance of ActiveRecord::Base to `find`.
154
- Please pass the id of the object by calling `.id`
162
+ Please pass the id of the object by calling `.id`.
155
163
  MSG
156
164
  end
157
165
 
@@ -272,8 +280,9 @@ module ActiveRecord
272
280
  private
273
281
 
274
282
  def cached_find_by_statement(key, &block) # :nodoc:
275
- @find_by_statement_cache[key] || @find_by_statement_cache.synchronize {
276
- @find_by_statement_cache[key] ||= StatementCache.create(connection, &block)
283
+ cache = @find_by_statement_cache[connection.prepared_statements]
284
+ cache[key] || cache.synchronize {
285
+ cache[key] ||= StatementCache.create(connection, &block)
277
286
  }
278
287
  end
279
288
 
@@ -152,7 +152,7 @@ module ActiveRecord
152
152
  enum_values = ActiveSupport::HashWithIndifferentAccess.new
153
153
  name = name.to_sym
154
154
 
155
- # def self.statuses statuses end
155
+ # def self.statuses() statuses end
156
156
  detect_enum_conflict!(name, name.to_s.pluralize, true)
157
157
  klass.singleton_class.send(:define_method, name.to_s.pluralize) { enum_values }
158
158
 
@@ -125,6 +125,10 @@ module ActiveRecord
125
125
  class InvalidForeignKey < WrappedDatabaseException
126
126
  end
127
127
 
128
+ # Raised when a record cannot be inserted or updated because a value too long for a column type.
129
+ class ValueTooLong < StatementInvalid
130
+ end
131
+
128
132
  # Raised when number of bind variables in statement given to +:condition+ key
129
133
  # (for example, when using {ActiveRecord::Base.find}[rdoc-ref:FinderMethods#find] method)
130
134
  # does not match number of expected values supplied.
@@ -139,6 +143,11 @@ module ActiveRecord
139
143
  class NoDatabaseError < StatementInvalid
140
144
  end
141
145
 
146
+ # Raised when Postgres returns 'cached plan must not change result type' and
147
+ # we cannot retry gracefully (e.g. inside a transaction)
148
+ class PreparedStatementCacheExpired < StatementInvalid
149
+ end
150
+
142
151
  # Raised on attempt to save stale record. Record is stale when it's being saved in another query after
143
152
  # instantiation, for example, when two users edit the same wiki page and one starts editing and saves
144
153
  # the page before the other.
@@ -52,9 +52,15 @@ module ActiveRecord
52
52
  end
53
53
  end
54
54
 
55
+ def prepare_erb(content)
56
+ erb = ERB.new(content)
57
+ erb.filename = @file
58
+ erb
59
+ end
60
+
55
61
  def render(content)
56
62
  context = ActiveRecord::FixtureSet::RenderContext.create_subclass.new
57
- ERB.new(content).result(context.get_binding)
63
+ prepare_erb(content).result(context.get_binding)
58
64
  end
59
65
 
60
66
  # Validate our unmarshalled data.
@@ -8,7 +8,7 @@ module ActiveRecord
8
8
  MAJOR = 5
9
9
  MINOR = 0
10
10
  TINY = 0
11
- PRE = "beta3"
11
+ PRE = "beta4"
12
12
 
13
13
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
14
14
  end
@@ -190,6 +190,10 @@ module ActiveRecord
190
190
  super.to_i
191
191
  end
192
192
 
193
+ def serialize(value)
194
+ super.to_i
195
+ end
196
+
193
197
  def init_with(coder)
194
198
  __setobj__(coder['subtype'])
195
199
  end
@@ -67,7 +67,7 @@ module ActiveRecord
67
67
  case sql
68
68
  when /\A\s*rollback/mi
69
69
  RED
70
- when /\s*.*?select .*for update/mi, /\A\s*lock/mi
70
+ when /select .*for update/mi, /\A\s*lock/mi
71
71
  WHITE
72
72
  when /\A\s*select/i
73
73
  BLUE
@@ -156,8 +156,8 @@ module ActiveRecord
156
156
 
157
157
  class ProtectedEnvironmentError < ActiveRecordError #:nodoc:
158
158
  def initialize(env = "production")
159
- msg = "You are attempting to run a destructive action against your '#{env}' database\n"
160
- msg << "If you are sure you want to continue, run the same command with the environment variable\n"
159
+ msg = "You are attempting to run a destructive action against your '#{env}' database.\n"
160
+ msg << "If you are sure you want to continue, run the same command with the environment variable:\n"
161
161
  msg << "DISABLE_DATABASE_ENVIRONMENT_CHECK=1"
162
162
  super(msg)
163
163
  end
@@ -528,7 +528,7 @@ module ActiveRecord
528
528
  name = "V#{version.tr('.', '_')}"
529
529
  unless Compatibility.const_defined?(name)
530
530
  versions = Compatibility.constants.grep(/\AV[0-9_]+\z/).map { |s| s.to_s.delete('V').tr('_', '.').inspect }
531
- raise "Unknown migration version #{version.inspect}; expected one of #{versions.sort.join(', ')}"
531
+ raise ArgumentError, "Unknown migration version #{version.inspect}; expected one of #{versions.sort.join(', ')}"
532
532
  end
533
533
  Compatibility.const_get(name)
534
534
  end
@@ -540,7 +540,7 @@ module ActiveRecord
540
540
  MigrationFilenameRegexp = /\A([0-9]+)_([_a-z0-9]*)\.?([_a-z0-9]*)?\.rb\z/ # :nodoc:
541
541
 
542
542
  # This class is used to verify that all migrations have been run before
543
- # loading a web page if config.active_record.migration_error is set to :page_load
543
+ # loading a web page if <tt>config.active_record.migration_error</tt> is set to :page_load
544
544
  class CheckPending
545
545
  def initialize(app)
546
546
  @app = app
@@ -57,7 +57,7 @@ module ActiveRecord
57
57
  def index_exists?(table_name, column_name, options = {})
58
58
  column_names = Array(column_name).map(&:to_s)
59
59
  options[:name] =
60
- if options.key?(:name).present?
60
+ if options[:name].present?
61
61
  options[:name].to_s
62
62
  else
63
63
  index_name(table_name, column: column_names)
@@ -231,6 +231,18 @@ module ActiveRecord
231
231
  @explicit_sequence_name = true
232
232
  end
233
233
 
234
+ # Determines if the primary key values should be selected from their
235
+ # corresponding sequence before the insert statement.
236
+ def prefetch_primary_key?
237
+ connection.prefetch_primary_key?(table_name)
238
+ end
239
+
240
+ # Returns the next value that will be used as the primary key on
241
+ # an insert statment.
242
+ def next_sequence_value
243
+ connection.next_sequence_value(sequence_name)
244
+ end
245
+
234
246
  # Indicates whether the table associated with this class exists
235
247
  def table_exists?
236
248
  connection.schema_cache.data_source_exists?(table_name)
@@ -215,7 +215,7 @@ module ActiveRecord
215
215
  #
216
216
  # The keys of the hash which is the value for +:posts_attributes+ are
217
217
  # ignored in this case.
218
- # However, it is not allowed to use +'id'+ or +:id+ for one of
218
+ # However, it is not allowed to use <tt>'id'</tt> or <tt>:id</tt> for one of
219
219
  # such keys, otherwise the hash will be wrapped in an array and
220
220
  # interpreted as an attribute hash for a single post.
221
221
  #
@@ -61,7 +61,7 @@ module ActiveRecord
61
61
  # +instantiate+ instead of +new+, finder methods ensure they get new
62
62
  # instances of the appropriate class for each record.
63
63
  #
64
- # See +ActiveRecord::Inheritance#discriminate_class_for_record+ to see
64
+ # See <tt>ActiveRecord::Inheritance#discriminate_class_for_record</tt> to see
65
65
  # how this "single-table" inheritance mapping is implemented.
66
66
  def instantiate(attributes, column_types = {})
67
67
  klass = discriminate_class_for_record(attributes)
@@ -23,34 +23,31 @@ module ActiveRecord
23
23
  end
24
24
  end
25
25
 
26
- def initialize(app)
27
- @app = app
28
- end
29
-
30
- def call(env)
26
+ def self.run
31
27
  connection = ActiveRecord::Base.connection
32
28
  enabled = connection.query_cache_enabled
33
29
  connection_id = ActiveRecord::Base.connection_id
34
30
  connection.enable_query_cache!
35
31
 
36
- response = @app.call(env)
37
- response[2] = Rack::BodyProxy.new(response[2]) do
38
- restore_query_cache_settings(connection_id, enabled)
39
- end
40
-
41
- response
42
- rescue Exception => e
43
- restore_query_cache_settings(connection_id, enabled)
44
- raise e
32
+ [enabled, connection_id]
45
33
  end
46
34
 
47
- private
35
+ def self.complete(state)
36
+ enabled, connection_id = state
48
37
 
49
- def restore_query_cache_settings(connection_id, enabled)
50
38
  ActiveRecord::Base.connection_id = connection_id
51
39
  ActiveRecord::Base.connection.clear_query_cache
52
40
  ActiveRecord::Base.connection.disable_query_cache! unless enabled
53
41
  end
54
42
 
43
+ def self.install_executor_hooks(executor = ActiveSupport::Executor)
44
+ executor.register_hook(self)
45
+
46
+ executor.to_complete do
47
+ unless ActiveRecord::Base.connection.transaction_open?
48
+ ActiveRecord::Base.clear_active_connections!
49
+ end
50
+ end
51
+ end
55
52
  end
56
53
  end
@@ -1,6 +1,6 @@
1
1
  module ActiveRecord
2
2
  module Querying
3
- delegate :find, :take, :take!, :first, :first!, :last, :last!, :exists?, :any?, :many?, to: :all
3
+ delegate :find, :take, :take!, :first, :first!, :last, :last!, :exists?, :any?, :many?, :empty?, :none?, :one?, to: :all
4
4
  delegate :second, :second!, :third, :third!, :fourth, :fourth!, :fifth, :fifth!, :forty_two, :forty_two!, :third_to_last, :third_to_last!, :second_to_last, :second_to_last!, to: :all
5
5
  delegate :first_or_create, :first_or_create!, :first_or_initialize, to: :all
6
6
  delegate :find_or_create_by, :find_or_create_by!, :find_or_initialize_by, to: :all
@@ -16,12 +16,6 @@ module ActiveRecord
16
16
  config.app_generators.orm :active_record, :migration => true,
17
17
  :timestamps => true
18
18
 
19
- config.app_middleware.insert_after ::ActionDispatch::Callbacks,
20
- ActiveRecord::QueryCache
21
-
22
- config.app_middleware.insert_after ::ActionDispatch::Callbacks,
23
- ActiveRecord::ConnectionAdapters::ConnectionManagement
24
-
25
19
  config.action_dispatch.rescue_responses.merge!(
26
20
  'ActiveRecord::RecordNotFound' => :not_found,
27
21
  'ActiveRecord::StaleObjectError' => :conflict,
@@ -71,7 +65,6 @@ module ActiveRecord
71
65
  ActiveSupport.on_load(:active_record) do
72
66
  self.time_zone_aware_attributes = true
73
67
  self.default_timezone = :utc
74
- self.time_zone_aware_types = ActiveRecord::Base.time_zone_aware_types
75
68
  end
76
69
  end
77
70
 
@@ -153,11 +146,9 @@ end_warning
153
146
  end
154
147
  end
155
148
 
156
- initializer "active_record.set_reloader_hooks" do |app|
157
- hook = app.config.reload_classes_only_on_change ? :to_prepare : :to_cleanup
158
-
149
+ initializer "active_record.set_reloader_hooks" do
159
150
  ActiveSupport.on_load(:active_record) do
160
- ActionDispatch::Reloader.send(hook) do
151
+ ActiveSupport::Reloader.before_class_unload do
161
152
  if ActiveRecord::Base.connected?
162
153
  ActiveRecord::Base.clear_cache!
163
154
  ActiveRecord::Base.clear_reloadable_connections!
@@ -166,6 +157,12 @@ end_warning
166
157
  end
167
158
  end
168
159
 
160
+ initializer "active_record.set_executor_hooks" do
161
+ ActiveSupport.on_load(:active_record) do
162
+ ActiveRecord::QueryCache.install_executor_hooks
163
+ end
164
+ end
165
+
169
166
  initializer "active_record.add_watchable_files" do |app|
170
167
  path = app.paths["db"].first
171
168
  config.watchable_files.concat ["#{path}/schema.rb", "#{path}/structure.sql"]