activerecord 5.0.0.beta1.1 → 5.0.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 +123 -15
- data/MIT-LICENSE +2 -2
- data/README.rdoc +1 -1
- data/lib/active_record.rb +2 -1
- data/lib/active_record/aggregations.rb +1 -1
- data/lib/active_record/associations.rb +3 -0
- data/lib/active_record/associations/builder/belongs_to.rb +1 -1
- data/lib/active_record/associations/builder/has_one.rb +1 -1
- data/lib/active_record/associations/builder/singular_association.rb +1 -1
- data/lib/active_record/associations/has_many_through_association.rb +5 -0
- data/lib/active_record/associations/join_dependency/join_association.rb +1 -2
- data/lib/active_record/associations/preloader/through_association.rb +7 -2
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +11 -7
- data/lib/active_record/autosave_association.rb +18 -3
- data/lib/active_record/base.rb +0 -3
- data/lib/active_record/collection_cache_key.rb +12 -3
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +21 -34
- data/lib/active_record/connection_adapters/abstract/quoting.rb +8 -4
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +7 -1
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +36 -20
- data/lib/active_record/connection_adapters/abstract/transaction.rb +8 -2
- data/lib/active_record/connection_adapters/abstract_adapter.rb +8 -15
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +57 -198
- data/lib/active_record/connection_adapters/column.rb +1 -1
- data/lib/active_record/connection_adapters/mysql/column.rb +50 -0
- data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +70 -0
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +24 -0
- data/lib/active_record/connection_adapters/mysql/type_metadata.rb +32 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +15 -34
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +7 -69
- data/lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb +42 -0
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +4 -0
- data/lib/active_record/connection_adapters/postgresql/oid/money.rb +0 -2
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +8 -1
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +5 -4
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +3 -7
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +15 -23
- data/lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb +19 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +2 -31
- data/lib/active_record/connection_handling.rb +1 -1
- data/lib/active_record/core.rb +1 -1
- data/lib/active_record/counter_cache.rb +4 -4
- data/lib/active_record/enum.rb +8 -5
- data/lib/active_record/errors.rb +6 -1
- data/lib/active_record/gem_version.rb +1 -1
- data/lib/active_record/inheritance.rb +6 -1
- data/lib/active_record/internal_metadata.rb +56 -0
- data/lib/active_record/migration.rb +85 -20
- data/lib/active_record/migration/compatibility.rb +28 -2
- data/lib/active_record/model_schema.rb +25 -1
- data/lib/active_record/persistence.rb +11 -10
- data/lib/active_record/railtie.rb +6 -3
- data/lib/active_record/railties/databases.rake +20 -6
- data/lib/active_record/reflection.rb +39 -31
- data/lib/active_record/relation.rb +4 -4
- data/lib/active_record/relation/batches.rb +26 -41
- data/lib/active_record/relation/batches/batch_enumerator.rb +6 -6
- data/lib/active_record/relation/finder_methods.rb +35 -13
- data/lib/active_record/relation/from_clause.rb +1 -1
- data/lib/active_record/relation/merger.rb +3 -0
- data/lib/active_record/relation/predicate_builder.rb +19 -1
- data/lib/active_record/relation/predicate_builder/range_handler.rb +17 -1
- data/lib/active_record/relation/query_methods.rb +37 -19
- data/lib/active_record/relation/record_fetch_warning.rb +4 -6
- data/lib/active_record/relation/where_clause.rb +1 -1
- data/lib/active_record/relation/where_clause_factory.rb +1 -0
- data/lib/active_record/sanitization.rb +1 -1
- data/lib/active_record/schema.rb +3 -0
- data/lib/active_record/schema_dumper.rb +1 -1
- data/lib/active_record/schema_migration.rb +5 -14
- data/lib/active_record/scoping.rb +17 -11
- data/lib/active_record/scoping/default.rb +2 -2
- data/lib/active_record/tasks/database_tasks.rb +18 -0
- data/lib/active_record/timestamp.rb +5 -1
- data/lib/active_record/transactions.rb +3 -3
- data/lib/active_record/validations/uniqueness.rb +6 -3
- data/lib/rails/generators/active_record/migration/templates/migration.rb +4 -0
- data/lib/rails/generators/active_record/model/model_generator.rb +7 -1
- metadata +14 -7
@@ -11,11 +11,11 @@ module ActiveRecord
|
|
11
11
|
|
12
12
|
module ClassMethods
|
13
13
|
def current_scope #:nodoc:
|
14
|
-
ScopeRegistry.value_for(:current_scope, self
|
14
|
+
ScopeRegistry.value_for(:current_scope, self)
|
15
15
|
end
|
16
16
|
|
17
17
|
def current_scope=(scope) #:nodoc:
|
18
|
-
ScopeRegistry.set_value_for(:current_scope, self
|
18
|
+
ScopeRegistry.set_value_for(:current_scope, self, scope)
|
19
19
|
end
|
20
20
|
|
21
21
|
# Collects attributes from scopes that should be applied when creating
|
@@ -53,18 +53,18 @@ module ActiveRecord
|
|
53
53
|
# following code:
|
54
54
|
#
|
55
55
|
# registry = ActiveRecord::Scoping::ScopeRegistry
|
56
|
-
# registry.set_value_for(:current_scope,
|
56
|
+
# registry.set_value_for(:current_scope, Board, some_new_scope)
|
57
57
|
#
|
58
58
|
# Now when you run:
|
59
59
|
#
|
60
|
-
# registry.value_for(:current_scope,
|
60
|
+
# registry.value_for(:current_scope, Board)
|
61
61
|
#
|
62
62
|
# You will obtain whatever was defined in +some_new_scope+. The #value_for
|
63
63
|
# and #set_value_for methods are delegated to the current ScopeRegistry
|
64
64
|
# object, so the above example code can also be called as:
|
65
65
|
#
|
66
66
|
# ActiveRecord::Scoping::ScopeRegistry.set_value_for(:current_scope,
|
67
|
-
#
|
67
|
+
# Board, some_new_scope)
|
68
68
|
class ScopeRegistry # :nodoc:
|
69
69
|
extend ActiveSupport::PerThreadRegistry
|
70
70
|
|
@@ -74,16 +74,22 @@ module ActiveRecord
|
|
74
74
|
@registry = Hash.new { |hash, key| hash[key] = {} }
|
75
75
|
end
|
76
76
|
|
77
|
-
# Obtains the value for a given +
|
78
|
-
def value_for(scope_type,
|
77
|
+
# Obtains the value for a given +scope_type+ and +model+.
|
78
|
+
def value_for(scope_type, model)
|
79
79
|
raise_invalid_scope_type!(scope_type)
|
80
|
-
|
80
|
+
klass = model
|
81
|
+
base = model.base_class
|
82
|
+
while klass <= base
|
83
|
+
value = @registry[scope_type][klass.name]
|
84
|
+
return value if value
|
85
|
+
klass = klass.superclass
|
86
|
+
end
|
81
87
|
end
|
82
88
|
|
83
|
-
# Sets the +value+ for a given +scope_type+ and +
|
84
|
-
def set_value_for(scope_type,
|
89
|
+
# Sets the +value+ for a given +scope_type+ and +model+.
|
90
|
+
def set_value_for(scope_type, model, value)
|
85
91
|
raise_invalid_scope_type!(scope_type)
|
86
|
-
@registry[scope_type][
|
92
|
+
@registry[scope_type][model.name] = value
|
87
93
|
end
|
88
94
|
|
89
95
|
private
|
@@ -122,11 +122,11 @@ module ActiveRecord
|
|
122
122
|
end
|
123
123
|
|
124
124
|
def ignore_default_scope? # :nodoc:
|
125
|
-
ScopeRegistry.value_for(:ignore_default_scope,
|
125
|
+
ScopeRegistry.value_for(:ignore_default_scope, base_class)
|
126
126
|
end
|
127
127
|
|
128
128
|
def ignore_default_scope=(ignore) # :nodoc:
|
129
|
-
ScopeRegistry.set_value_for(:ignore_default_scope,
|
129
|
+
ScopeRegistry.set_value_for(:ignore_default_scope, base_class, ignore)
|
130
130
|
end
|
131
131
|
|
132
132
|
# The ignore_default_scope flag is used to prevent an infinite recursion
|
@@ -42,6 +42,22 @@ module ActiveRecord
|
|
42
42
|
|
43
43
|
LOCAL_HOSTS = ['127.0.0.1', 'localhost']
|
44
44
|
|
45
|
+
def check_protected_environments!
|
46
|
+
unless ENV['DISABLE_DATABASE_ENVIRONMENT_CHECK']
|
47
|
+
current = ActiveRecord::Migrator.current_environment
|
48
|
+
stored = ActiveRecord::Migrator.last_stored_environment
|
49
|
+
|
50
|
+
if ActiveRecord::Migrator.protected_environment?
|
51
|
+
raise ActiveRecord::ProtectedEnvironmentError.new(stored)
|
52
|
+
end
|
53
|
+
|
54
|
+
if stored && stored != current
|
55
|
+
raise ActiveRecord::EnvironmentMismatchError.new(current: current, stored: stored)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
rescue ActiveRecord::NoDatabaseError
|
59
|
+
end
|
60
|
+
|
45
61
|
def register_task(pattern, task)
|
46
62
|
@tasks ||= {}
|
47
63
|
@tasks[pattern] = task
|
@@ -204,6 +220,8 @@ module ActiveRecord
|
|
204
220
|
else
|
205
221
|
raise ArgumentError, "unknown format #{format.inspect}"
|
206
222
|
end
|
223
|
+
ActiveRecord::InternalMetadata.create_table
|
224
|
+
ActiveRecord::InternalMetadata[:environment] = ActiveRecord::Migrator.current_environment
|
207
225
|
end
|
208
226
|
|
209
227
|
def load_schema_for(*args)
|
@@ -16,7 +16,7 @@ module ActiveRecord
|
|
16
16
|
# == Time Zone aware attributes
|
17
17
|
#
|
18
18
|
# Active Record keeps all the <tt>datetime</tt> and <tt>time</tt> columns
|
19
|
-
#
|
19
|
+
# timezone aware. By default, these values are stored in the database as UTC
|
20
20
|
# and converted back to the current <tt>Time.zone</tt> when pulled from the database.
|
21
21
|
#
|
22
22
|
# This feature can be turned off completely by setting:
|
@@ -28,6 +28,10 @@ module ActiveRecord
|
|
28
28
|
#
|
29
29
|
# ActiveRecord::Base.time_zone_aware_types = [:datetime]
|
30
30
|
#
|
31
|
+
# You can also add database specific timezone aware types. For example, for PostgreSQL:
|
32
|
+
#
|
33
|
+
# ActiveRecord::Base.time_zone_aware_types += [:tsrange, :tstzrange]
|
34
|
+
#
|
31
35
|
# Finally, you can indicate specific attributes of a model for which time zone
|
32
36
|
# conversion should not applied, for instance by setting:
|
33
37
|
#
|
@@ -233,19 +233,19 @@ module ActiveRecord
|
|
233
233
|
set_callback(:commit, :after, *args, &block)
|
234
234
|
end
|
235
235
|
|
236
|
-
# Shortcut for
|
236
|
+
# Shortcut for <tt>after_commit :hook, on: :create</tt>.
|
237
237
|
def after_create_commit(*args, &block)
|
238
238
|
set_options_for_callbacks!(args, on: :create)
|
239
239
|
set_callback(:commit, :after, *args, &block)
|
240
240
|
end
|
241
241
|
|
242
|
-
# Shortcut for
|
242
|
+
# Shortcut for <tt>after_commit :hook, on: :update</tt>.
|
243
243
|
def after_update_commit(*args, &block)
|
244
244
|
set_options_for_callbacks!(args, on: :update)
|
245
245
|
set_callback(:commit, :after, *args, &block)
|
246
246
|
end
|
247
247
|
|
248
|
-
# Shortcut for
|
248
|
+
# Shortcut for <tt>after_commit :hook, on: :destroy</tt>.
|
249
249
|
def after_destroy_commit(*args, &block)
|
250
250
|
set_options_for_callbacks!(args, on: :destroy)
|
251
251
|
set_callback(:commit, :after, *args, &block)
|
@@ -73,15 +73,18 @@ module ActiveRecord
|
|
73
73
|
value = value.to_s[0, column.limit]
|
74
74
|
end
|
75
75
|
|
76
|
-
value = Arel::Nodes::Quoted.new(value)
|
77
|
-
|
78
76
|
comparison = if !options[:case_sensitive] && !value.nil?
|
79
77
|
# will use SQL LOWER function before comparison, unless it detects a case insensitive collation
|
80
78
|
klass.connection.case_insensitive_comparison(table, attribute, column, value)
|
81
79
|
else
|
82
80
|
klass.connection.case_sensitive_comparison(table, attribute, column, value)
|
83
81
|
end
|
84
|
-
|
82
|
+
if value.nil?
|
83
|
+
klass.unscoped.where(comparison)
|
84
|
+
else
|
85
|
+
bind = Relation::QueryAttribute.new(attribute.to_s, value, Type::Value.new)
|
86
|
+
klass.unscoped.where(comparison, bind)
|
87
|
+
end
|
85
88
|
rescue RangeError
|
86
89
|
klass.none
|
87
90
|
end
|
@@ -19,7 +19,11 @@ class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Mi
|
|
19
19
|
def change
|
20
20
|
create_join_table :<%= join_tables.first %>, :<%= join_tables.second %> do |t|
|
21
21
|
<%- attributes.each do |attribute| -%>
|
22
|
+
<%- if attribute.reference? -%>
|
23
|
+
t.references :<%= attribute.name %><%= attribute.inject_options %>
|
24
|
+
<%- else -%>
|
22
25
|
<%= '# ' unless attribute.has_index? -%>t.index <%= attribute.index_name %><%= attribute.inject_index_options %>
|
26
|
+
<%- end -%>
|
23
27
|
<%- end -%>
|
24
28
|
end
|
25
29
|
end
|
@@ -45,7 +45,13 @@ module ActiveRecord
|
|
45
45
|
def determine_default_parent_class
|
46
46
|
application_record = nil
|
47
47
|
|
48
|
-
in_root
|
48
|
+
in_root do
|
49
|
+
application_record = if mountable_engine?
|
50
|
+
File.exist?("app/models/#{namespaced_path}/application_record.rb")
|
51
|
+
else
|
52
|
+
File.exist?('app/models/application_record.rb')
|
53
|
+
end
|
54
|
+
end
|
49
55
|
|
50
56
|
if application_record
|
51
57
|
"ApplicationRecord"
|
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.0.
|
4
|
+
version: 5.0.0.beta2
|
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: 2016-01
|
11
|
+
date: 2016-02-01 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.0.
|
19
|
+
version: 5.0.0.beta2
|
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.0.
|
26
|
+
version: 5.0.0.beta2
|
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.0.
|
33
|
+
version: 5.0.0.beta2
|
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.0.
|
40
|
+
version: 5.0.0.beta2
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: arel
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -144,12 +144,16 @@ files:
|
|
144
144
|
- lib/active_record/connection_adapters/column.rb
|
145
145
|
- lib/active_record/connection_adapters/connection_specification.rb
|
146
146
|
- lib/active_record/connection_adapters/determine_if_preparable_visitor.rb
|
147
|
+
- lib/active_record/connection_adapters/mysql/column.rb
|
148
|
+
- lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb
|
147
149
|
- lib/active_record/connection_adapters/mysql/schema_creation.rb
|
148
150
|
- lib/active_record/connection_adapters/mysql/schema_definitions.rb
|
149
151
|
- lib/active_record/connection_adapters/mysql/schema_dumper.rb
|
152
|
+
- lib/active_record/connection_adapters/mysql/type_metadata.rb
|
150
153
|
- lib/active_record/connection_adapters/mysql2_adapter.rb
|
151
154
|
- lib/active_record/connection_adapters/postgresql/column.rb
|
152
155
|
- lib/active_record/connection_adapters/postgresql/database_statements.rb
|
156
|
+
- lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb
|
153
157
|
- lib/active_record/connection_adapters/postgresql/oid.rb
|
154
158
|
- lib/active_record/connection_adapters/postgresql/oid/array.rb
|
155
159
|
- lib/active_record/connection_adapters/postgresql/oid/bit.rb
|
@@ -182,6 +186,7 @@ files:
|
|
182
186
|
- lib/active_record/connection_adapters/postgresql_adapter.rb
|
183
187
|
- lib/active_record/connection_adapters/schema_cache.rb
|
184
188
|
- lib/active_record/connection_adapters/sql_type_metadata.rb
|
189
|
+
- lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb
|
185
190
|
- lib/active_record/connection_adapters/sqlite3/schema_creation.rb
|
186
191
|
- lib/active_record/connection_adapters/sqlite3_adapter.rb
|
187
192
|
- lib/active_record/connection_adapters/statement_pool.rb
|
@@ -199,6 +204,7 @@ files:
|
|
199
204
|
- lib/active_record/gem_version.rb
|
200
205
|
- lib/active_record/inheritance.rb
|
201
206
|
- lib/active_record/integration.rb
|
207
|
+
- lib/active_record/internal_metadata.rb
|
202
208
|
- lib/active_record/legacy_yaml_adapter.rb
|
203
209
|
- lib/active_record/locale/en.yml
|
204
210
|
- lib/active_record/locking/optimistic.rb
|
@@ -317,8 +323,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
317
323
|
version: 1.3.1
|
318
324
|
requirements: []
|
319
325
|
rubyforge_project:
|
320
|
-
rubygems_version: 2.5.
|
326
|
+
rubygems_version: 2.5.2
|
321
327
|
signing_key:
|
322
328
|
specification_version: 4
|
323
329
|
summary: Object-relational mapper framework (part of Rails).
|
324
330
|
test_files: []
|
331
|
+
has_rdoc:
|