activerecord 3.2.22.4 → 4.0.13
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 +2799 -617
- data/MIT-LICENSE +1 -1
- data/README.rdoc +23 -32
- data/examples/performance.rb +1 -1
- data/lib/active_record/aggregations.rb +40 -34
- data/lib/active_record/association_relation.rb +22 -0
- data/lib/active_record/associations/alias_tracker.rb +4 -2
- data/lib/active_record/associations/association.rb +60 -46
- data/lib/active_record/associations/association_scope.rb +46 -40
- data/lib/active_record/associations/belongs_to_association.rb +17 -4
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +1 -1
- data/lib/active_record/associations/builder/association.rb +81 -28
- data/lib/active_record/associations/builder/belongs_to.rb +73 -56
- data/lib/active_record/associations/builder/collection_association.rb +54 -40
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +23 -41
- data/lib/active_record/associations/builder/has_many.rb +8 -64
- data/lib/active_record/associations/builder/has_one.rb +13 -50
- data/lib/active_record/associations/builder/singular_association.rb +13 -13
- data/lib/active_record/associations/collection_association.rb +130 -96
- data/lib/active_record/associations/collection_proxy.rb +916 -63
- data/lib/active_record/associations/has_and_belongs_to_many_association.rb +15 -13
- data/lib/active_record/associations/has_many_association.rb +35 -8
- data/lib/active_record/associations/has_many_through_association.rb +37 -17
- data/lib/active_record/associations/has_one_association.rb +42 -19
- data/lib/active_record/associations/has_one_through_association.rb +1 -1
- data/lib/active_record/associations/join_dependency/join_association.rb +39 -22
- data/lib/active_record/associations/join_dependency/join_base.rb +2 -2
- data/lib/active_record/associations/join_dependency/join_part.rb +21 -8
- data/lib/active_record/associations/join_dependency.rb +30 -9
- data/lib/active_record/associations/join_helper.rb +1 -11
- data/lib/active_record/associations/preloader/association.rb +29 -33
- data/lib/active_record/associations/preloader/collection_association.rb +1 -1
- data/lib/active_record/associations/preloader/has_and_belongs_to_many.rb +2 -2
- data/lib/active_record/associations/preloader/has_many_through.rb +6 -2
- data/lib/active_record/associations/preloader/has_one.rb +1 -1
- data/lib/active_record/associations/preloader/through_association.rb +13 -17
- data/lib/active_record/associations/preloader.rb +20 -43
- data/lib/active_record/associations/singular_association.rb +11 -11
- data/lib/active_record/associations/through_association.rb +3 -3
- data/lib/active_record/associations.rb +223 -282
- data/lib/active_record/attribute_assignment.rb +134 -154
- data/lib/active_record/attribute_methods/before_type_cast.rb +44 -5
- data/lib/active_record/attribute_methods/dirty.rb +36 -29
- data/lib/active_record/attribute_methods/primary_key.rb +45 -31
- data/lib/active_record/attribute_methods/query.rb +5 -4
- data/lib/active_record/attribute_methods/read.rb +67 -90
- data/lib/active_record/attribute_methods/serialization.rb +133 -70
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +51 -45
- data/lib/active_record/attribute_methods/write.rb +34 -39
- data/lib/active_record/attribute_methods.rb +268 -108
- data/lib/active_record/autosave_association.rb +80 -73
- data/lib/active_record/base.rb +54 -451
- data/lib/active_record/callbacks.rb +60 -22
- data/lib/active_record/coders/yaml_column.rb +18 -21
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +347 -197
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +9 -0
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +146 -138
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +25 -19
- data/lib/active_record/connection_adapters/abstract/quoting.rb +19 -3
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +151 -142
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +70 -0
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +499 -217
- data/lib/active_record/connection_adapters/abstract/transaction.rb +208 -0
- data/lib/active_record/connection_adapters/abstract_adapter.rb +209 -44
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +169 -61
- data/lib/active_record/connection_adapters/column.rb +67 -36
- data/lib/active_record/connection_adapters/connection_specification.rb +96 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +28 -29
- data/lib/active_record/connection_adapters/mysql_adapter.rb +200 -73
- data/lib/active_record/connection_adapters/postgresql/array_parser.rb +98 -0
- data/lib/active_record/connection_adapters/postgresql/cast.rb +160 -0
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +240 -0
- data/lib/active_record/connection_adapters/postgresql/oid.rb +374 -0
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +183 -0
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +30 -0
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +508 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +544 -899
- data/lib/active_record/connection_adapters/schema_cache.rb +76 -16
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +595 -16
- data/lib/active_record/connection_handling.rb +98 -0
- data/lib/active_record/core.rb +472 -0
- data/lib/active_record/counter_cache.rb +107 -108
- data/lib/active_record/dynamic_matchers.rb +115 -63
- data/lib/active_record/errors.rb +36 -18
- data/lib/active_record/explain.rb +15 -63
- data/lib/active_record/explain_registry.rb +30 -0
- data/lib/active_record/explain_subscriber.rb +8 -4
- data/lib/active_record/fixture_set/file.rb +55 -0
- data/lib/active_record/fixtures.rb +159 -155
- data/lib/active_record/inheritance.rb +93 -59
- data/lib/active_record/integration.rb +8 -8
- data/lib/active_record/locale/en.yml +8 -1
- data/lib/active_record/locking/optimistic.rb +39 -43
- data/lib/active_record/locking/pessimistic.rb +4 -4
- data/lib/active_record/log_subscriber.rb +19 -9
- data/lib/active_record/migration/command_recorder.rb +102 -33
- data/lib/active_record/migration/join_table.rb +15 -0
- data/lib/active_record/migration.rb +411 -173
- data/lib/active_record/model_schema.rb +81 -94
- data/lib/active_record/nested_attributes.rb +173 -131
- data/lib/active_record/null_relation.rb +67 -0
- data/lib/active_record/persistence.rb +254 -106
- data/lib/active_record/query_cache.rb +18 -36
- data/lib/active_record/querying.rb +19 -15
- data/lib/active_record/railtie.rb +113 -38
- data/lib/active_record/railties/console_sandbox.rb +3 -4
- data/lib/active_record/railties/controller_runtime.rb +4 -3
- data/lib/active_record/railties/databases.rake +115 -368
- data/lib/active_record/railties/jdbcmysql_error.rb +1 -1
- data/lib/active_record/readonly_attributes.rb +7 -3
- data/lib/active_record/reflection.rb +110 -61
- data/lib/active_record/relation/batches.rb +29 -29
- data/lib/active_record/relation/calculations.rb +155 -125
- data/lib/active_record/relation/delegation.rb +94 -18
- data/lib/active_record/relation/finder_methods.rb +151 -203
- data/lib/active_record/relation/merger.rb +188 -0
- data/lib/active_record/relation/predicate_builder.rb +85 -42
- data/lib/active_record/relation/query_methods.rb +793 -146
- data/lib/active_record/relation/spawn_methods.rb +43 -150
- data/lib/active_record/relation.rb +293 -173
- data/lib/active_record/result.rb +48 -7
- data/lib/active_record/runtime_registry.rb +17 -0
- data/lib/active_record/sanitization.rb +41 -54
- data/lib/active_record/schema.rb +19 -12
- data/lib/active_record/schema_dumper.rb +41 -41
- data/lib/active_record/schema_migration.rb +46 -0
- data/lib/active_record/scoping/default.rb +56 -52
- data/lib/active_record/scoping/named.rb +78 -103
- data/lib/active_record/scoping.rb +54 -124
- data/lib/active_record/serialization.rb +6 -2
- data/lib/active_record/serializers/xml_serializer.rb +9 -15
- data/lib/active_record/statement_cache.rb +26 -0
- data/lib/active_record/store.rb +131 -15
- data/lib/active_record/tasks/database_tasks.rb +204 -0
- data/lib/active_record/tasks/firebird_database_tasks.rb +56 -0
- data/lib/active_record/tasks/mysql_database_tasks.rb +144 -0
- data/lib/active_record/tasks/oracle_database_tasks.rb +45 -0
- data/lib/active_record/tasks/postgresql_database_tasks.rb +90 -0
- data/lib/active_record/tasks/sqlite_database_tasks.rb +51 -0
- data/lib/active_record/tasks/sqlserver_database_tasks.rb +48 -0
- data/lib/active_record/test_case.rb +67 -38
- data/lib/active_record/timestamp.rb +16 -11
- data/lib/active_record/transactions.rb +73 -51
- data/lib/active_record/validations/associated.rb +19 -13
- data/lib/active_record/validations/presence.rb +65 -0
- data/lib/active_record/validations/uniqueness.rb +110 -57
- data/lib/active_record/validations.rb +18 -17
- data/lib/active_record/version.rb +7 -6
- data/lib/active_record.rb +63 -45
- data/lib/rails/generators/active_record/migration/migration_generator.rb +45 -8
- data/lib/rails/generators/active_record/{model/templates/migration.rb → migration/templates/create_table_migration.rb} +4 -0
- data/lib/rails/generators/active_record/migration/templates/migration.rb +20 -15
- data/lib/rails/generators/active_record/model/model_generator.rb +5 -4
- data/lib/rails/generators/active_record/model/templates/model.rb +4 -6
- data/lib/rails/generators/active_record/model/templates/module.rb +1 -1
- data/lib/rails/generators/active_record.rb +3 -5
- metadata +43 -29
- data/examples/associations.png +0 -0
- data/lib/active_record/attribute_methods/deprecated_underscore_read.rb +0 -32
- data/lib/active_record/connection_adapters/abstract/connection_specification.rb +0 -191
- data/lib/active_record/connection_adapters/sqlite_adapter.rb +0 -583
- data/lib/active_record/dynamic_finder_match.rb +0 -68
- data/lib/active_record/dynamic_scope_match.rb +0 -23
- data/lib/active_record/fixtures/file.rb +0 -65
- data/lib/active_record/identity_map.rb +0 -162
- data/lib/active_record/observer.rb +0 -121
- data/lib/active_record/session_store.rb +0 -360
- data/lib/rails/generators/active_record/migration.rb +0 -15
- data/lib/rails/generators/active_record/observer/observer_generator.rb +0 -15
- data/lib/rails/generators/active_record/observer/templates/observer.rb +0 -4
- data/lib/rails/generators/active_record/session_migration/session_migration_generator.rb +0 -25
- data/lib/rails/generators/active_record/session_migration/templates/migration.rb +0 -12
@@ -1,15 +1,15 @@
|
|
1
|
-
require 'active_support/core_ext/module/delegation'
|
2
|
-
|
3
1
|
module ActiveRecord
|
4
2
|
module Querying
|
5
|
-
delegate :find, :first, :first!, :last, :last!, :
|
6
|
-
delegate :first_or_create, :first_or_create!, :first_or_initialize, :to => :
|
7
|
-
delegate :
|
8
|
-
delegate :
|
3
|
+
delegate :find, :take, :take!, :first, :first!, :last, :last!, :exists?, :any?, :many?, :to => :all
|
4
|
+
delegate :first_or_create, :first_or_create!, :first_or_initialize, :to => :all
|
5
|
+
delegate :find_or_create_by, :find_or_create_by!, :find_or_initialize_by, :to => :all
|
6
|
+
delegate :find_by, :find_by!, :to => :all
|
7
|
+
delegate :destroy, :destroy_all, :delete, :delete_all, :update, :update_all, :to => :all
|
8
|
+
delegate :find_each, :find_in_batches, :to => :all
|
9
9
|
delegate :select, :group, :order, :except, :reorder, :limit, :offset, :joins,
|
10
10
|
:where, :preload, :eager_load, :includes, :from, :lock, :readonly,
|
11
|
-
:having, :create_with, :uniq, :to => :
|
12
|
-
delegate :count, :average, :minimum, :maximum, :sum, :calculate, :pluck, :to => :
|
11
|
+
:having, :create_with, :uniq, :distinct, :references, :none, :unscope, :to => :all
|
12
|
+
delegate :count, :average, :minimum, :maximum, :sum, :calculate, :pluck, :ids, :to => :all
|
13
13
|
|
14
14
|
# Executes a custom SQL query against your database and returns all the results. The results will
|
15
15
|
# be returned as an array with columns requested encapsulated as attributes of the model you call
|
@@ -25,18 +25,24 @@ module ActiveRecord
|
|
25
25
|
# MySQL specific terms will lock you to using that particular database engine or require you to
|
26
26
|
# change your call if you switch engines.
|
27
27
|
#
|
28
|
-
# ==== Examples
|
29
28
|
# # A simple SQL query spanning multiple tables
|
30
29
|
# Post.find_by_sql "SELECT p.title, c.author FROM posts p, comments c WHERE p.id = c.post_id"
|
31
|
-
#
|
30
|
+
# # => [#<Post:0x36bff9c @attributes={"title"=>"Ruby Meetup", "first_name"=>"Quentin"}>, ...]
|
32
31
|
#
|
33
32
|
# # You can use the same string replacement techniques as you can with ActiveRecord#find
|
34
33
|
# Post.find_by_sql ["SELECT title FROM posts WHERE author = ? AND created > ?", author_id, start_date]
|
35
|
-
#
|
34
|
+
# # => [#<Post:0x36bff9c @attributes={"title"=>"The Cheap Man Buys Twice"}>, ...]
|
36
35
|
def find_by_sql(sql, binds = [])
|
37
|
-
|
38
|
-
|
36
|
+
result_set = connection.select_all(sanitize_sql(sql), "#{name} Load", binds)
|
37
|
+
column_types = {}
|
38
|
+
|
39
|
+
if result_set.respond_to? :column_types
|
40
|
+
column_types = result_set.column_types
|
41
|
+
else
|
42
|
+
ActiveSupport::Deprecation.warn "the object returned from `select_all` must respond to `column_types`"
|
39
43
|
end
|
44
|
+
|
45
|
+
result_set.map { |record| instantiate(record, column_types) }
|
40
46
|
end
|
41
47
|
|
42
48
|
# Returns the result of an SQL statement that should only include a COUNT(*) in the SELECT part.
|
@@ -47,8 +53,6 @@ module ActiveRecord
|
|
47
53
|
#
|
48
54
|
# * +sql+ - An SQL statement which should return a count query from the database, see the example below.
|
49
55
|
#
|
50
|
-
# ==== Examples
|
51
|
-
#
|
52
56
|
# Product.count_by_sql "SELECT COUNT(*) FROM sales s, customers c WHERE s.customer_id = c.id"
|
53
57
|
def count_by_sql(sql)
|
54
58
|
sql = sanitize_conditions(sql)
|
@@ -10,7 +10,7 @@ require "action_controller/railtie"
|
|
10
10
|
|
11
11
|
module ActiveRecord
|
12
12
|
# = Active Record Railtie
|
13
|
-
class Railtie < Rails::Railtie
|
13
|
+
class Railtie < Rails::Railtie # :nodoc:
|
14
14
|
config.active_record = ActiveSupport::OrderedOptions.new
|
15
15
|
|
16
16
|
config.app_generators.orm :active_record, :migration => true,
|
@@ -29,8 +29,33 @@ module ActiveRecord
|
|
29
29
|
'ActiveRecord::RecordNotSaved' => :unprocessable_entity
|
30
30
|
)
|
31
31
|
|
32
|
+
|
33
|
+
config.active_record.use_schema_cache_dump = true
|
34
|
+
|
35
|
+
config.eager_load_namespaces << ActiveRecord
|
36
|
+
|
32
37
|
rake_tasks do
|
33
38
|
require "active_record/base"
|
39
|
+
|
40
|
+
ActiveRecord::Tasks::DatabaseTasks.seed_loader = Rails.application
|
41
|
+
ActiveRecord::Tasks::DatabaseTasks.env = Rails.env
|
42
|
+
|
43
|
+
namespace :db do
|
44
|
+
task :load_config do
|
45
|
+
ActiveRecord::Tasks::DatabaseTasks.db_dir = Rails.application.config.paths["db"].first
|
46
|
+
ActiveRecord::Tasks::DatabaseTasks.database_configuration = Rails.application.config.database_configuration
|
47
|
+
ActiveRecord::Tasks::DatabaseTasks.migrations_paths = Rails.application.paths['db/migrate'].to_a
|
48
|
+
ActiveRecord::Tasks::DatabaseTasks.fixtures_path = File.join Rails.root, 'test', 'fixtures'
|
49
|
+
ActiveRecord::Tasks::DatabaseTasks.root = Rails.root
|
50
|
+
|
51
|
+
if defined?(ENGINE_PATH) && engine = Rails::Engine.find(ENGINE_PATH)
|
52
|
+
if engine.paths['db/migrate'].existent
|
53
|
+
ActiveRecord::Tasks::DatabaseTasks.migrations_paths += engine.paths['db/migrate'].to_a
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
34
59
|
load "active_record/railties/databases.rake"
|
35
60
|
end
|
36
61
|
|
@@ -40,10 +65,11 @@ module ActiveRecord
|
|
40
65
|
console do |app|
|
41
66
|
require "active_record/railties/console_sandbox" if app.sandbox?
|
42
67
|
require "active_record/base"
|
43
|
-
|
68
|
+
console = ActiveSupport::Logger.new(STDERR)
|
69
|
+
Rails.logger.extend ActiveSupport::Logger.broadcast console
|
44
70
|
end
|
45
71
|
|
46
|
-
runner do
|
72
|
+
runner do
|
47
73
|
require "active_record/base"
|
48
74
|
end
|
49
75
|
|
@@ -58,16 +84,84 @@ module ActiveRecord
|
|
58
84
|
ActiveSupport.on_load(:active_record) { self.logger ||= ::Rails.logger }
|
59
85
|
end
|
60
86
|
|
61
|
-
initializer "active_record.
|
62
|
-
config.
|
63
|
-
"
|
87
|
+
initializer "active_record.migration_error" do
|
88
|
+
if config.active_record.delete(:migration_error) == :page_load
|
89
|
+
config.app_middleware.insert_after "::ActionDispatch::Callbacks",
|
90
|
+
"ActiveRecord::Migration::CheckPending"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
initializer "active_record.check_schema_cache_dump" do
|
95
|
+
if config.active_record.delete(:use_schema_cache_dump)
|
96
|
+
config.after_initialize do |app|
|
97
|
+
ActiveSupport.on_load(:active_record) do
|
98
|
+
filename = File.join(app.config.paths["db"].first, "schema_cache.dump")
|
99
|
+
|
100
|
+
if File.file?(filename)
|
101
|
+
cache = Marshal.load File.binread filename
|
102
|
+
if cache.version == ActiveRecord::Migrator.current_version
|
103
|
+
self.connection.schema_cache = cache
|
104
|
+
else
|
105
|
+
warn "Ignoring db/schema_cache.dump because it has expired. The current schema version is #{ActiveRecord::Migrator.current_version}, but the one in the cache is #{cache.version}."
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
64
111
|
end
|
65
112
|
|
66
113
|
initializer "active_record.set_configs" do |app|
|
67
114
|
ActiveSupport.on_load(:active_record) do
|
68
|
-
|
69
|
-
|
115
|
+
begin
|
116
|
+
old_behavior, ActiveSupport::Deprecation.behavior = ActiveSupport::Deprecation.behavior, :stderr
|
117
|
+
whitelist_attributes = app.config.active_record.delete(:whitelist_attributes)
|
118
|
+
|
119
|
+
if respond_to?(:mass_assignment_sanitizer=)
|
120
|
+
mass_assignment_sanitizer = nil
|
121
|
+
else
|
122
|
+
mass_assignment_sanitizer = app.config.active_record.delete(:mass_assignment_sanitizer)
|
123
|
+
end
|
124
|
+
|
125
|
+
unless whitelist_attributes.nil? && mass_assignment_sanitizer.nil?
|
126
|
+
ActiveSupport::Deprecation.warn <<-EOF.strip_heredoc, []
|
127
|
+
Model based mass assignment security has been extracted
|
128
|
+
out of Rails into a gem. Please use the new recommended protection model for
|
129
|
+
params or add `protected_attributes` to your Gemfile to use the old one.
|
130
|
+
|
131
|
+
To disable this message remove the `whitelist_attributes` option from your
|
132
|
+
`config/application.rb` file and any `mass_assignment_sanitizer` options
|
133
|
+
from your `config/environments/*.rb` files.
|
134
|
+
|
135
|
+
See http://guides.rubyonrails.org/security.html#mass-assignment for more information.
|
136
|
+
EOF
|
137
|
+
end
|
138
|
+
|
139
|
+
unless app.config.active_record.delete(:auto_explain_threshold_in_seconds).nil?
|
140
|
+
ActiveSupport::Deprecation.warn <<-EOF.strip_heredoc, []
|
141
|
+
The Active Record auto explain feature has been removed.
|
142
|
+
|
143
|
+
To disable this message remove the `active_record.auto_explain_threshold_in_seconds`
|
144
|
+
option from the `config/environments/*.rb` config file.
|
145
|
+
|
146
|
+
See http://guides.rubyonrails.org/4_0_release_notes.html for more information.
|
147
|
+
EOF
|
148
|
+
end
|
149
|
+
|
150
|
+
unless app.config.active_record.delete(:observers).nil?
|
151
|
+
ActiveSupport::Deprecation.warn <<-EOF.strip_heredoc, []
|
152
|
+
Active Record Observers has been extracted out of Rails into a gem.
|
153
|
+
Please use callbacks or add `rails-observers` to your Gemfile to use observers.
|
154
|
+
|
155
|
+
To disable this message remove the `observers` option from your
|
156
|
+
`config/application.rb` or from your initializers.
|
157
|
+
|
158
|
+
See http://guides.rubyonrails.org/4_0_release_notes.html for more information.
|
159
|
+
EOF
|
160
|
+
end
|
161
|
+
ensure
|
162
|
+
ActiveSupport::Deprecation.behavior = old_behavior
|
70
163
|
end
|
164
|
+
|
71
165
|
app.config.active_record.each do |k,v|
|
72
166
|
send "#{k}=", v
|
73
167
|
end
|
@@ -78,19 +172,13 @@ module ActiveRecord
|
|
78
172
|
# and then establishes the connection.
|
79
173
|
initializer "active_record.initialize_database" do |app|
|
80
174
|
ActiveSupport.on_load(:active_record) do
|
81
|
-
|
82
|
-
unless ENV['DATABASE_URL']
|
83
|
-
db_connection_type = "database.yml"
|
84
|
-
self.configurations = app.config.database_configuration
|
85
|
-
end
|
86
|
-
Rails.logger.info "Connecting to database specified by #{db_connection_type}"
|
87
|
-
|
175
|
+
self.configurations = app.config.database_configuration || {}
|
88
176
|
establish_connection
|
89
177
|
end
|
90
178
|
end
|
91
179
|
|
92
180
|
# Expose database runtime to controller for logging.
|
93
|
-
initializer "active_record.log_runtime" do
|
181
|
+
initializer "active_record.log_runtime" do
|
94
182
|
require "active_record/railties/controller_runtime"
|
95
183
|
ActiveSupport.on_load(:action_controller) do
|
96
184
|
include ActiveRecord::Railties::ControllerRuntime
|
@@ -98,34 +186,21 @@ module ActiveRecord
|
|
98
186
|
end
|
99
187
|
|
100
188
|
initializer "active_record.set_reloader_hooks" do |app|
|
101
|
-
hook =
|
102
|
-
ActiveRecord::Base.clear_reloadable_connections!
|
103
|
-
ActiveRecord::Base.clear_cache!
|
104
|
-
end
|
189
|
+
hook = app.config.reload_classes_only_on_change ? :to_prepare : :to_cleanup
|
105
190
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
ActionDispatch::Reloader.to_cleanup(&hook)
|
191
|
+
ActiveSupport.on_load(:active_record) do
|
192
|
+
ActionDispatch::Reloader.send(hook) do
|
193
|
+
if ActiveRecord::Base.connected?
|
194
|
+
ActiveRecord::Base.clear_reloadable_connections!
|
195
|
+
ActiveRecord::Base.clear_cache!
|
196
|
+
end
|
113
197
|
end
|
114
198
|
end
|
115
199
|
end
|
116
200
|
|
117
201
|
initializer "active_record.add_watchable_files" do |app|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
config.after_initialize do
|
122
|
-
ActiveSupport.on_load(:active_record) do
|
123
|
-
instantiate_observers
|
124
|
-
|
125
|
-
ActionDispatch::Reloader.to_prepare do
|
126
|
-
ActiveRecord::Base.instantiate_observers
|
127
|
-
end
|
128
|
-
end
|
202
|
+
path = app.paths["db"].first
|
203
|
+
config.watchable_files.concat ["#{path}/schema.rb", "#{path}/structure.sql"]
|
129
204
|
end
|
130
205
|
end
|
131
206
|
end
|
@@ -1,6 +1,5 @@
|
|
1
|
-
ActiveRecord::Base.connection.
|
2
|
-
|
1
|
+
ActiveRecord::Base.connection.begin_transaction(joinable: false)
|
2
|
+
|
3
3
|
at_exit do
|
4
|
-
ActiveRecord::Base.connection.
|
5
|
-
ActiveRecord::Base.connection.decrement_open_transactions
|
4
|
+
ActiveRecord::Base.connection.rollback_transaction
|
6
5
|
end
|
@@ -2,7 +2,7 @@ require 'active_support/core_ext/module/attr_internal'
|
|
2
2
|
require 'active_record/log_subscriber'
|
3
3
|
|
4
4
|
module ActiveRecord
|
5
|
-
module Railties
|
5
|
+
module Railties # :nodoc:
|
6
6
|
module ControllerRuntime #:nodoc:
|
7
7
|
extend ActiveSupport::Concern
|
8
8
|
|
@@ -21,9 +21,10 @@ module ActiveRecord
|
|
21
21
|
def cleanup_view_runtime
|
22
22
|
if ActiveRecord::Base.connected?
|
23
23
|
db_rt_before_render = ActiveRecord::LogSubscriber.reset_runtime
|
24
|
+
self.db_runtime = (db_runtime || 0) + db_rt_before_render
|
24
25
|
runtime = super
|
25
26
|
db_rt_after_render = ActiveRecord::LogSubscriber.reset_runtime
|
26
|
-
self.db_runtime
|
27
|
+
self.db_runtime += db_rt_after_render
|
27
28
|
runtime - db_rt_after_render
|
28
29
|
else
|
29
30
|
super
|
@@ -37,7 +38,7 @@ module ActiveRecord
|
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
40
|
-
module ClassMethods
|
41
|
+
module ClassMethods # :nodoc:
|
41
42
|
def log_process_action(payload)
|
42
43
|
messages, db_runtime = super, payload[:db_runtime]
|
43
44
|
messages << ("ActiveRecord: %.1fms" % db_runtime.to_f) if db_runtime
|