activerecord 5.0.7 → 5.1.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 +5 -5
- data/CHANGELOG.md +657 -2080
- data/MIT-LICENSE +1 -1
- data/README.rdoc +1 -1
- data/examples/performance.rb +28 -28
- data/examples/simple.rb +3 -3
- data/lib/active_record/aggregations.rb +244 -244
- data/lib/active_record/association_relation.rb +5 -5
- data/lib/active_record/associations/alias_tracker.rb +10 -11
- data/lib/active_record/associations/association.rb +23 -5
- data/lib/active_record/associations/association_scope.rb +95 -81
- data/lib/active_record/associations/belongs_to_association.rb +7 -4
- data/lib/active_record/associations/builder/belongs_to.rb +30 -16
- data/lib/active_record/associations/builder/collection_association.rb +1 -2
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +27 -27
- data/lib/active_record/associations/collection_association.rb +36 -205
- data/lib/active_record/associations/collection_proxy.rb +132 -63
- data/lib/active_record/associations/has_many_association.rb +10 -19
- data/lib/active_record/associations/has_many_through_association.rb +12 -4
- data/lib/active_record/associations/has_one_association.rb +24 -28
- data/lib/active_record/associations/has_one_through_association.rb +5 -1
- data/lib/active_record/associations/join_dependency/join_association.rb +4 -28
- data/lib/active_record/associations/join_dependency/join_base.rb +1 -1
- data/lib/active_record/associations/join_dependency/join_part.rb +1 -1
- data/lib/active_record/associations/join_dependency.rb +121 -118
- data/lib/active_record/associations/preloader/association.rb +64 -64
- data/lib/active_record/associations/preloader/belongs_to.rb +0 -2
- data/lib/active_record/associations/preloader/collection_association.rb +6 -6
- data/lib/active_record/associations/preloader/has_many.rb +0 -2
- data/lib/active_record/associations/preloader/singular_association.rb +6 -8
- data/lib/active_record/associations/preloader/through_association.rb +41 -41
- data/lib/active_record/associations/preloader.rb +94 -94
- data/lib/active_record/associations/singular_association.rb +8 -25
- data/lib/active_record/associations/through_association.rb +2 -5
- data/lib/active_record/associations.rb +1591 -1562
- data/lib/active_record/attribute/user_provided_default.rb +4 -2
- data/lib/active_record/attribute.rb +98 -71
- data/lib/active_record/attribute_assignment.rb +61 -61
- data/lib/active_record/attribute_decorators.rb +35 -13
- data/lib/active_record/attribute_methods/before_type_cast.rb +7 -7
- data/lib/active_record/attribute_methods/dirty.rb +229 -46
- data/lib/active_record/attribute_methods/primary_key.rb +74 -73
- data/lib/active_record/attribute_methods/read.rb +39 -35
- data/lib/active_record/attribute_methods/serialization.rb +7 -7
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +35 -58
- data/lib/active_record/attribute_methods/write.rb +30 -33
- data/lib/active_record/attribute_methods.rb +56 -65
- data/lib/active_record/attribute_mutation_tracker.rb +63 -11
- data/lib/active_record/attribute_set/builder.rb +27 -33
- data/lib/active_record/attribute_set/yaml_encoder.rb +41 -0
- data/lib/active_record/attribute_set.rb +9 -6
- data/lib/active_record/attributes.rb +22 -22
- data/lib/active_record/autosave_association.rb +18 -13
- data/lib/active_record/base.rb +24 -22
- data/lib/active_record/callbacks.rb +56 -14
- data/lib/active_record/coders/yaml_column.rb +9 -11
- data/lib/active_record/collection_cache_key.rb +3 -4
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +330 -284
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +1 -3
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +39 -37
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +32 -27
- data/lib/active_record/connection_adapters/abstract/quoting.rb +62 -51
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +10 -20
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +74 -79
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +53 -41
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +120 -100
- data/lib/active_record/connection_adapters/abstract/transaction.rb +49 -43
- data/lib/active_record/connection_adapters/abstract_adapter.rb +165 -135
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +404 -424
- data/lib/active_record/connection_adapters/column.rb +26 -4
- data/lib/active_record/connection_adapters/connection_specification.rb +128 -118
- data/lib/active_record/connection_adapters/mysql/column.rb +6 -31
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +36 -49
- data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +22 -22
- data/lib/active_record/connection_adapters/mysql/quoting.rb +6 -12
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +49 -45
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +16 -19
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +54 -28
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +43 -0
- data/lib/active_record/connection_adapters/mysql/type_metadata.rb +7 -6
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +23 -27
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +32 -53
- data/lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb +3 -3
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +19 -9
- data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +5 -3
- data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +2 -2
- data/lib/active_record/connection_adapters/postgresql/oid/decimal.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +3 -3
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +16 -16
- data/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb +0 -10
- data/lib/active_record/connection_adapters/postgresql/oid/{rails_5_1_point.rb → legacy_point.rb} +9 -16
- data/lib/active_record/connection_adapters/postgresql/oid/money.rb +2 -2
- data/lib/active_record/connection_adapters/postgresql/oid/oid.rb +13 -0
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +28 -8
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +32 -30
- data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +2 -1
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +51 -51
- data/lib/active_record/connection_adapters/postgresql/oid.rb +22 -21
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +40 -35
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +15 -0
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +37 -24
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +19 -23
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +182 -222
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +6 -4
- data/lib/active_record/connection_adapters/postgresql/utils.rb +7 -5
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +198 -167
- data/lib/active_record/connection_adapters/schema_cache.rb +16 -7
- data/lib/active_record/connection_adapters/sql_type_metadata.rb +3 -3
- data/lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb +1 -1
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +16 -19
- data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +1 -8
- data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +28 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +17 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +32 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +184 -167
- data/lib/active_record/connection_adapters/statement_pool.rb +7 -7
- data/lib/active_record/connection_handling.rb +14 -26
- data/lib/active_record/core.rb +109 -93
- data/lib/active_record/counter_cache.rb +60 -13
- data/lib/active_record/define_callbacks.rb +20 -0
- data/lib/active_record/dynamic_matchers.rb +80 -79
- data/lib/active_record/enum.rb +8 -6
- data/lib/active_record/errors.rb +64 -15
- data/lib/active_record/explain.rb +1 -2
- data/lib/active_record/explain_registry.rb +1 -1
- data/lib/active_record/explain_subscriber.rb +7 -4
- data/lib/active_record/fixture_set/file.rb +11 -8
- data/lib/active_record/fixtures.rb +66 -53
- data/lib/active_record/gem_version.rb +1 -1
- data/lib/active_record/inheritance.rb +93 -79
- data/lib/active_record/integration.rb +7 -7
- data/lib/active_record/internal_metadata.rb +3 -16
- data/lib/active_record/legacy_yaml_adapter.rb +1 -1
- data/lib/active_record/locking/optimistic.rb +69 -74
- data/lib/active_record/locking/pessimistic.rb +10 -1
- data/lib/active_record/log_subscriber.rb +23 -28
- data/lib/active_record/migration/command_recorder.rb +94 -94
- data/lib/active_record/migration/compatibility.rb +100 -47
- data/lib/active_record/migration/join_table.rb +6 -6
- data/lib/active_record/migration.rb +153 -155
- data/lib/active_record/model_schema.rb +94 -107
- data/lib/active_record/nested_attributes.rb +200 -199
- data/lib/active_record/null_relation.rb +11 -34
- data/lib/active_record/persistence.rb +65 -50
- data/lib/active_record/query_cache.rb +2 -6
- data/lib/active_record/querying.rb +3 -4
- data/lib/active_record/railtie.rb +16 -17
- data/lib/active_record/railties/controller_runtime.rb +6 -2
- data/lib/active_record/railties/databases.rake +105 -133
- data/lib/active_record/railties/jdbcmysql_error.rb +1 -1
- data/lib/active_record/readonly_attributes.rb +2 -2
- data/lib/active_record/reflection.rb +154 -108
- data/lib/active_record/relation/batches/batch_enumerator.rb +1 -1
- data/lib/active_record/relation/batches.rb +80 -51
- data/lib/active_record/relation/calculations.rb +169 -162
- data/lib/active_record/relation/delegation.rb +32 -31
- data/lib/active_record/relation/finder_methods.rb +197 -231
- data/lib/active_record/relation/merger.rb +58 -62
- data/lib/active_record/relation/predicate_builder/array_handler.rb +7 -5
- data/lib/active_record/relation/predicate_builder/association_query_handler.rb +23 -23
- data/lib/active_record/relation/predicate_builder/base_handler.rb +3 -1
- data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +0 -8
- data/lib/active_record/relation/predicate_builder/polymorphic_array_handler.rb +12 -10
- data/lib/active_record/relation/predicate_builder/range_handler.rb +0 -8
- data/lib/active_record/relation/predicate_builder.rb +92 -89
- data/lib/active_record/relation/query_attribute.rb +1 -1
- data/lib/active_record/relation/query_methods.rb +255 -293
- data/lib/active_record/relation/record_fetch_warning.rb +3 -3
- data/lib/active_record/relation/spawn_methods.rb +4 -5
- data/lib/active_record/relation/where_clause.rb +80 -65
- data/lib/active_record/relation/where_clause_factory.rb +47 -8
- data/lib/active_record/relation.rb +93 -119
- data/lib/active_record/result.rb +41 -32
- data/lib/active_record/runtime_registry.rb +3 -3
- data/lib/active_record/sanitization.rb +176 -192
- data/lib/active_record/schema.rb +3 -3
- data/lib/active_record/schema_dumper.rb +15 -38
- data/lib/active_record/schema_migration.rb +8 -4
- data/lib/active_record/scoping/default.rb +90 -90
- data/lib/active_record/scoping/named.rb +11 -11
- data/lib/active_record/scoping.rb +6 -6
- data/lib/active_record/secure_token.rb +2 -2
- data/lib/active_record/statement_cache.rb +13 -15
- data/lib/active_record/store.rb +31 -32
- data/lib/active_record/suppressor.rb +2 -1
- data/lib/active_record/table_metadata.rb +9 -5
- data/lib/active_record/tasks/database_tasks.rb +65 -55
- data/lib/active_record/tasks/mysql_database_tasks.rb +76 -73
- data/lib/active_record/tasks/postgresql_database_tasks.rb +72 -47
- data/lib/active_record/tasks/sqlite_database_tasks.rb +18 -16
- data/lib/active_record/timestamp.rb +46 -25
- data/lib/active_record/touch_later.rb +1 -2
- data/lib/active_record/transactions.rb +97 -109
- data/lib/active_record/type/adapter_specific_registry.rb +46 -42
- data/lib/active_record/type/decimal_without_scale.rb +13 -0
- data/lib/active_record/type/hash_lookup_type_map.rb +3 -3
- data/lib/active_record/type/internal/abstract_json.rb +4 -0
- data/lib/active_record/type/serialized.rb +14 -8
- data/lib/active_record/type/text.rb +9 -0
- data/lib/active_record/type/time.rb +0 -1
- data/lib/active_record/type/type_map.rb +11 -15
- data/lib/active_record/type/unsigned_integer.rb +15 -0
- data/lib/active_record/type.rb +17 -13
- data/lib/active_record/type_caster/connection.rb +8 -6
- data/lib/active_record/type_caster/map.rb +3 -1
- data/lib/active_record/type_caster.rb +2 -2
- data/lib/active_record/validations/associated.rb +1 -1
- data/lib/active_record/validations/presence.rb +2 -2
- data/lib/active_record/validations/uniqueness.rb +8 -39
- data/lib/active_record/validations.rb +4 -4
- data/lib/active_record/version.rb +1 -1
- data/lib/active_record.rb +20 -20
- data/lib/rails/generators/active_record/migration/migration_generator.rb +37 -34
- data/lib/rails/generators/active_record/migration.rb +1 -1
- data/lib/rails/generators/active_record/model/model_generator.rb +9 -9
- data/lib/rails/generators/active_record.rb +4 -4
- metadata +24 -13
- data/lib/active_record/relation/predicate_builder/class_handler.rb +0 -27
@@ -1,6 +1,7 @@
|
|
1
|
+
|
1
2
|
module ActiveRecord
|
2
3
|
module DynamicMatchers #:nodoc:
|
3
|
-
def
|
4
|
+
def respond_to_missing?(name, include_private = false)
|
4
5
|
if self == Base
|
5
6
|
super
|
6
7
|
else
|
@@ -11,111 +12,111 @@ module ActiveRecord
|
|
11
12
|
|
12
13
|
private
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
def method_missing(name, *arguments, &block)
|
16
|
+
match = Method.match(self, name)
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
if match && match.valid?
|
19
|
+
match.define
|
20
|
+
send(name, *arguments, &block)
|
21
|
+
else
|
22
|
+
super
|
23
|
+
end
|
22
24
|
end
|
23
|
-
end
|
24
25
|
|
25
|
-
|
26
|
-
|
26
|
+
class Method
|
27
|
+
@matchers = []
|
27
28
|
|
28
|
-
|
29
|
-
|
29
|
+
class << self
|
30
|
+
attr_reader :matchers
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
def match(model, name)
|
33
|
+
klass = matchers.find { |k| k.pattern.match?(name) }
|
34
|
+
klass.new(model, name) if klass
|
35
|
+
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
def pattern
|
38
|
+
@pattern ||= /\A#{prefix}_([_a-zA-Z]\w*)#{suffix}\Z/
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
41
|
+
def prefix
|
42
|
+
raise NotImplementedError
|
43
|
+
end
|
43
44
|
|
44
|
-
|
45
|
-
|
45
|
+
def suffix
|
46
|
+
""
|
47
|
+
end
|
46
48
|
end
|
47
|
-
end
|
48
49
|
|
49
|
-
|
50
|
+
attr_reader :model, :name, :attribute_names
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
def initialize(model, name)
|
53
|
+
@model = model
|
54
|
+
@name = name.to_s
|
55
|
+
@attribute_names = @name.match(self.class.pattern)[1].split("_and_")
|
56
|
+
@attribute_names.map! { |n| @model.attribute_aliases[n] || n }
|
57
|
+
end
|
57
58
|
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
def valid?
|
60
|
+
attribute_names.all? { |name| model.columns_hash[name] || model.reflect_on_aggregation(name.to_sym) }
|
61
|
+
end
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
63
|
+
def define
|
64
|
+
model.class_eval <<-CODE, __FILE__, __LINE__ + 1
|
65
|
+
def self.#{name}(#{signature})
|
66
|
+
#{body}
|
67
|
+
end
|
68
|
+
CODE
|
69
|
+
end
|
69
70
|
|
70
|
-
|
71
|
+
private
|
71
72
|
|
72
|
-
|
73
|
-
|
74
|
-
|
73
|
+
def body
|
74
|
+
"#{finder}(#{attributes_hash})"
|
75
|
+
end
|
75
76
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
77
|
+
# The parameters in the signature may have reserved Ruby words, in order
|
78
|
+
# to prevent errors, we start each param name with `_`.
|
79
|
+
def signature
|
80
|
+
attribute_names.map { |name| "_#{name}" }.join(", ")
|
81
|
+
end
|
81
82
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
83
|
+
# Given that the parameters starts with `_`, the finder needs to use the
|
84
|
+
# same parameter name.
|
85
|
+
def attributes_hash
|
86
|
+
"{" + attribute_names.map { |name| ":#{name} => _#{name}" }.join(",") + "}"
|
87
|
+
end
|
87
88
|
|
88
|
-
|
89
|
-
|
89
|
+
def finder
|
90
|
+
raise NotImplementedError
|
91
|
+
end
|
90
92
|
end
|
91
|
-
end
|
92
93
|
|
93
|
-
|
94
|
-
|
94
|
+
class FindBy < Method
|
95
|
+
Method.matchers << self
|
95
96
|
|
96
|
-
|
97
|
-
|
98
|
-
|
97
|
+
def self.prefix
|
98
|
+
"find_by"
|
99
|
+
end
|
99
100
|
|
100
|
-
|
101
|
-
|
101
|
+
def finder
|
102
|
+
"find_by"
|
103
|
+
end
|
102
104
|
end
|
103
|
-
end
|
104
105
|
|
105
|
-
|
106
|
-
|
106
|
+
class FindByBang < Method
|
107
|
+
Method.matchers << self
|
107
108
|
|
108
|
-
|
109
|
-
|
110
|
-
|
109
|
+
def self.prefix
|
110
|
+
"find_by"
|
111
|
+
end
|
111
112
|
|
112
|
-
|
113
|
-
|
114
|
-
|
113
|
+
def self.suffix
|
114
|
+
"!"
|
115
|
+
end
|
115
116
|
|
116
|
-
|
117
|
-
|
117
|
+
def finder
|
118
|
+
"find_by!"
|
119
|
+
end
|
118
120
|
end
|
119
|
-
end
|
120
121
|
end
|
121
122
|
end
|
data/lib/active_record/enum.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "active_support/core_ext/object/deep_dup"
|
2
2
|
|
3
3
|
module ActiveRecord
|
4
4
|
# Declare an enum attribute where the values map to integers in the database,
|
@@ -140,9 +140,11 @@ module ActiveRecord
|
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
143
|
+
# TODO Change this to private once we've dropped Ruby 2.2 support.
|
144
|
+
# Workaround for Ruby 2.2 "private attribute?" warning.
|
143
145
|
protected
|
144
146
|
|
145
|
-
|
147
|
+
attr_reader :name, :mapping, :subtype
|
146
148
|
end
|
147
149
|
|
148
150
|
def enum(definitions)
|
@@ -216,18 +218,18 @@ module ActiveRecord
|
|
216
218
|
|
217
219
|
def detect_enum_conflict!(enum_name, method_name, klass_method = false)
|
218
220
|
if klass_method && dangerous_class_method?(method_name)
|
219
|
-
raise_conflict_error(enum_name, method_name, type:
|
221
|
+
raise_conflict_error(enum_name, method_name, type: "class")
|
220
222
|
elsif !klass_method && dangerous_attribute_method?(method_name)
|
221
223
|
raise_conflict_error(enum_name, method_name)
|
222
224
|
elsif !klass_method && method_defined_within?(method_name, _enum_methods_module, Module)
|
223
|
-
raise_conflict_error(enum_name, method_name, source:
|
225
|
+
raise_conflict_error(enum_name, method_name, source: "another enum")
|
224
226
|
end
|
225
227
|
end
|
226
228
|
|
227
|
-
def raise_conflict_error(enum_name, method_name, type:
|
229
|
+
def raise_conflict_error(enum_name, method_name, type: "instance", source: "Active Record")
|
228
230
|
raise ArgumentError, ENUM_CONFLICT_MESSAGE % {
|
229
231
|
enum: enum_name,
|
230
|
-
klass:
|
232
|
+
klass: name,
|
231
233
|
type: type,
|
232
234
|
method: method_name,
|
233
235
|
source: source
|
data/lib/active_record/errors.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
module ActiveRecord
|
2
|
-
|
3
2
|
# = Active Record Errors
|
4
3
|
#
|
5
4
|
# Generic Active Record exception class.
|
@@ -44,7 +43,7 @@ module ActiveRecord
|
|
44
43
|
|
45
44
|
# Raised when connection to the database could not been established (for example when
|
46
45
|
# {ActiveRecord::Base.connection=}[rdoc-ref:ConnectionHandling#connection]
|
47
|
-
# is given a nil object).
|
46
|
+
# is given a +nil+ object).
|
48
47
|
class ConnectionNotEstablished < ActiveRecordError
|
49
48
|
end
|
50
49
|
|
@@ -96,20 +95,9 @@ module ActiveRecord
|
|
96
95
|
#
|
97
96
|
# Wraps the underlying database error as +cause+.
|
98
97
|
class StatementInvalid < ActiveRecordError
|
99
|
-
|
100
|
-
def initialize(message = nil, original_exception = nil)
|
101
|
-
if original_exception
|
102
|
-
ActiveSupport::Deprecation.warn("Passing #original_exception is deprecated and has no effect. " \
|
103
|
-
"Exceptions will automatically capture the original exception.", caller)
|
104
|
-
end
|
105
|
-
|
98
|
+
def initialize(message = nil)
|
106
99
|
super(message || $!.try(:message))
|
107
100
|
end
|
108
|
-
|
109
|
-
def original_exception
|
110
|
-
ActiveSupport::Deprecation.warn("#original_exception is deprecated. Use #cause instead.", caller)
|
111
|
-
cause
|
112
|
-
end
|
113
101
|
end
|
114
102
|
|
115
103
|
# Defunct wrapper class kept for compatibility.
|
@@ -125,10 +113,52 @@ module ActiveRecord
|
|
125
113
|
class InvalidForeignKey < WrappedDatabaseException
|
126
114
|
end
|
127
115
|
|
116
|
+
# Raised when a foreign key constraint cannot be added because the column type does not match the referenced column type.
|
117
|
+
class MismatchedForeignKey < StatementInvalid
|
118
|
+
def initialize(
|
119
|
+
adapter = nil,
|
120
|
+
message: nil,
|
121
|
+
sql: nil,
|
122
|
+
binds: nil,
|
123
|
+
table: nil,
|
124
|
+
foreign_key: nil,
|
125
|
+
target_table: nil,
|
126
|
+
primary_key: nil,
|
127
|
+
primary_key_column: nil
|
128
|
+
)
|
129
|
+
if table
|
130
|
+
type = primary_key_column.bigint? ? :bigint : primary_key_column.type
|
131
|
+
msg = <<-EOM.squish
|
132
|
+
Column `#{foreign_key}` on table `#{table}` does not match column `#{primary_key}` on `#{target_table}`,
|
133
|
+
which has type `#{primary_key_column.sql_type}`.
|
134
|
+
To resolve this issue, change the type of the `#{foreign_key}` column on `#{table}` to be :#{type}.
|
135
|
+
(For example `t.#{type} :#{foreign_key}`).
|
136
|
+
EOM
|
137
|
+
else
|
138
|
+
msg = <<-EOM.squish
|
139
|
+
There is a mismatch between the foreign key and primary key column types.
|
140
|
+
Verify that the foreign key column type and the primary key of the associated table match types.
|
141
|
+
EOM
|
142
|
+
end
|
143
|
+
if message
|
144
|
+
msg << "\nOriginal message: #{message}"
|
145
|
+
end
|
146
|
+
super(msg)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
# Raised when a record cannot be inserted or updated because it would violate a not null constraint.
|
151
|
+
class NotNullViolation < StatementInvalid
|
152
|
+
end
|
153
|
+
|
128
154
|
# Raised when a record cannot be inserted or updated because a value too long for a column type.
|
129
155
|
class ValueTooLong < StatementInvalid
|
130
156
|
end
|
131
157
|
|
158
|
+
# Raised when values that executed are out of range.
|
159
|
+
class RangeError < StatementInvalid
|
160
|
+
end
|
161
|
+
|
132
162
|
# Raised when number of bind variables in statement given to +:condition+ key
|
133
163
|
# (for example, when using {ActiveRecord::Base.find}[rdoc-ref:FinderMethods#find] method)
|
134
164
|
# does not match number of expected values supplied.
|
@@ -166,7 +196,6 @@ module ActiveRecord
|
|
166
196
|
super("Stale object error.")
|
167
197
|
end
|
168
198
|
end
|
169
|
-
|
170
199
|
end
|
171
200
|
|
172
201
|
# Raised when association is being configured improperly or user tries to use
|
@@ -285,6 +314,26 @@ module ActiveRecord
|
|
285
314
|
class TransactionIsolationError < ActiveRecordError
|
286
315
|
end
|
287
316
|
|
317
|
+
# TransactionRollbackError will be raised when a transaction is rolled
|
318
|
+
# back by the database due to a serialization failure or a deadlock.
|
319
|
+
#
|
320
|
+
# See the following:
|
321
|
+
#
|
322
|
+
# * http://www.postgresql.org/docs/current/static/transaction-iso.html
|
323
|
+
# * https://dev.mysql.com/doc/refman/5.7/en/error-messages-server.html#error_er_lock_deadlock
|
324
|
+
class TransactionRollbackError < StatementInvalid
|
325
|
+
end
|
326
|
+
|
327
|
+
# SerializationFailure will be raised when a transaction is rolled
|
328
|
+
# back by the database due to a serialization failure.
|
329
|
+
class SerializationFailure < TransactionRollbackError
|
330
|
+
end
|
331
|
+
|
332
|
+
# Deadlocked will be raised when a transaction is rolled
|
333
|
+
# back by the database when a deadlock is encountered.
|
334
|
+
class Deadlocked < TransactionRollbackError
|
335
|
+
end
|
336
|
+
|
288
337
|
# IrreversibleOrderError is raised when a relation's order is too complex for
|
289
338
|
# +reverse_order+ to automatically reverse.
|
290
339
|
class IrreversibleOrderError < ActiveRecordError
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "active_support/notifications"
|
2
|
+
require "active_record/explain_registry"
|
3
3
|
|
4
4
|
module ActiveRecord
|
5
5
|
class ExplainSubscriber # :nodoc:
|
@@ -18,10 +18,13 @@ module ActiveRecord
|
|
18
18
|
#
|
19
19
|
# On the other hand, we want to monitor the performance of our real database
|
20
20
|
# queries, not the performance of the access to the query cache.
|
21
|
-
IGNORED_PAYLOADS = %w(SCHEMA EXPLAIN
|
21
|
+
IGNORED_PAYLOADS = %w(SCHEMA EXPLAIN)
|
22
22
|
EXPLAINED_SQLS = /\A\s*(with|select|update|delete|insert)\b/i
|
23
23
|
def ignore_payload?(payload)
|
24
|
-
payload[:exception] ||
|
24
|
+
payload[:exception] ||
|
25
|
+
payload[:cached] ||
|
26
|
+
IGNORED_PAYLOADS.include?(payload[:name]) ||
|
27
|
+
payload[:sql] !~ EXPLAINED_SQLS
|
25
28
|
end
|
26
29
|
|
27
30
|
ActiveSupport::Notifications.subscribe("sql.active_record", new)
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "erb"
|
2
|
+
require "yaml"
|
3
3
|
|
4
4
|
module ActiveRecord
|
5
5
|
class FixtureSet
|
@@ -24,21 +24,21 @@ module ActiveRecord
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def model_class
|
27
|
-
config_row[
|
27
|
+
config_row["model_class"]
|
28
28
|
end
|
29
29
|
|
30
30
|
private
|
31
31
|
def rows
|
32
|
-
@rows ||= raw_rows.reject { |fixture_name, _| fixture_name ==
|
32
|
+
@rows ||= raw_rows.reject { |fixture_name, _| fixture_name == "_fixture" }
|
33
33
|
end
|
34
34
|
|
35
35
|
def config_row
|
36
36
|
@config_row ||= begin
|
37
|
-
row = raw_rows.find { |fixture_name, _| fixture_name ==
|
37
|
+
row = raw_rows.find { |fixture_name, _| fixture_name == "_fixture" }
|
38
38
|
if row
|
39
39
|
row.last
|
40
40
|
else
|
41
|
-
{'model_class': nil}
|
41
|
+
{ 'model_class': nil }
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -66,10 +66,13 @@ module ActiveRecord
|
|
66
66
|
# Validate our unmarshalled data.
|
67
67
|
def validate(data)
|
68
68
|
unless Hash === data || YAML::Omap === data
|
69
|
-
raise Fixture::FormatError,
|
69
|
+
raise Fixture::FormatError, "fixture is not a hash: #{@file}"
|
70
70
|
end
|
71
71
|
|
72
|
-
|
72
|
+
invalid = data.reject { |_, row| Hash === row }
|
73
|
+
if invalid.any?
|
74
|
+
raise Fixture::FormatError, "fixture key is not a hash: #{@file}, keys: #{invalid.keys.inspect}"
|
75
|
+
end
|
73
76
|
data
|
74
77
|
end
|
75
78
|
end
|