activerecord 5.1.7 → 5.2.8.1
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 +629 -661
- data/MIT-LICENSE +1 -1
- data/README.rdoc +5 -5
- data/examples/performance.rb +2 -0
- data/examples/simple.rb +2 -0
- data/lib/active_record/aggregations.rb +6 -5
- data/lib/active_record/association_relation.rb +7 -5
- data/lib/active_record/associations/alias_tracker.rb +19 -27
- data/lib/active_record/associations/association.rb +41 -37
- data/lib/active_record/associations/association_scope.rb +38 -50
- data/lib/active_record/associations/belongs_to_association.rb +27 -8
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +8 -8
- data/lib/active_record/associations/builder/association.rb +4 -7
- data/lib/active_record/associations/builder/belongs_to.rb +12 -4
- data/lib/active_record/associations/builder/collection_association.rb +3 -3
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +3 -1
- data/lib/active_record/associations/builder/has_many.rb +2 -0
- data/lib/active_record/associations/builder/has_one.rb +2 -0
- data/lib/active_record/associations/builder/singular_association.rb +2 -0
- data/lib/active_record/associations/collection_association.rb +59 -47
- data/lib/active_record/associations/collection_proxy.rb +20 -49
- data/lib/active_record/associations/foreign_association.rb +2 -0
- data/lib/active_record/associations/has_many_association.rb +12 -1
- data/lib/active_record/associations/has_many_through_association.rb +36 -30
- data/lib/active_record/associations/has_one_association.rb +12 -1
- data/lib/active_record/associations/has_one_through_association.rb +13 -8
- data/lib/active_record/associations/join_dependency/join_association.rb +39 -63
- data/lib/active_record/associations/join_dependency/join_base.rb +9 -8
- data/lib/active_record/associations/join_dependency/join_part.rb +9 -9
- data/lib/active_record/associations/join_dependency.rb +48 -93
- data/lib/active_record/associations/preloader/association.rb +45 -61
- data/lib/active_record/associations/preloader/through_association.rb +71 -79
- data/lib/active_record/associations/preloader.rb +18 -38
- data/lib/active_record/associations/singular_association.rb +14 -16
- data/lib/active_record/associations/through_association.rb +26 -11
- data/lib/active_record/associations.rb +40 -63
- data/lib/active_record/attribute_assignment.rb +2 -5
- data/lib/active_record/attribute_decorators.rb +3 -2
- data/lib/active_record/attribute_methods/before_type_cast.rb +2 -0
- data/lib/active_record/attribute_methods/dirty.rb +30 -214
- data/lib/active_record/attribute_methods/primary_key.rb +7 -6
- data/lib/active_record/attribute_methods/query.rb +2 -0
- data/lib/active_record/attribute_methods/read.rb +9 -3
- data/lib/active_record/attribute_methods/serialization.rb +23 -0
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +6 -8
- data/lib/active_record/attribute_methods/write.rb +21 -9
- data/lib/active_record/attribute_methods.rb +65 -24
- data/lib/active_record/attributes.rb +6 -5
- data/lib/active_record/autosave_association.rb +35 -19
- data/lib/active_record/base.rb +2 -0
- data/lib/active_record/callbacks.rb +8 -6
- data/lib/active_record/coders/json.rb +2 -0
- data/lib/active_record/coders/yaml_column.rb +15 -1
- data/lib/active_record/collection_cache_key.rb +12 -8
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +139 -41
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +7 -0
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +174 -33
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +15 -5
- data/lib/active_record/connection_adapters/abstract/quoting.rb +13 -31
- data/lib/active_record/connection_adapters/abstract/savepoints.rb +2 -0
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +14 -5
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +64 -6
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +31 -53
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +152 -81
- data/lib/active_record/connection_adapters/abstract/transaction.rb +66 -21
- data/lib/active_record/connection_adapters/abstract_adapter.rb +84 -97
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +92 -165
- data/lib/active_record/connection_adapters/column.rb +3 -1
- data/lib/active_record/connection_adapters/connection_specification.rb +17 -3
- data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +13 -2
- data/lib/active_record/connection_adapters/mysql/column.rb +2 -0
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +47 -2
- data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +2 -0
- data/lib/active_record/connection_adapters/mysql/quoting.rb +9 -10
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +5 -3
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +7 -10
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +30 -30
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +106 -1
- data/lib/active_record/connection_adapters/mysql/type_metadata.rb +2 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +8 -2
- data/lib/active_record/connection_adapters/postgresql/column.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +6 -0
- data/lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/bytea.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/date.rb +23 -0
- data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/decimal.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/inet.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/money.rb +5 -3
- data/lib/active_record/connection_adapters/postgresql/oid/oid.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +4 -2
- data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +4 -2
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql/oid/vector.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/xml.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +18 -0
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +19 -25
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +50 -0
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +24 -11
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +20 -13
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +233 -111
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/utils.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +57 -73
- data/lib/active_record/connection_adapters/schema_cache.rb +4 -2
- data/lib/active_record/connection_adapters/sql_type_metadata.rb +2 -0
- data/lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb +2 -0
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +22 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +2 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +6 -15
- data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +3 -2
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +75 -1
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +81 -94
- data/lib/active_record/connection_adapters/statement_pool.rb +2 -0
- data/lib/active_record/connection_handling.rb +4 -2
- data/lib/active_record/core.rb +51 -61
- data/lib/active_record/counter_cache.rb +10 -3
- data/lib/active_record/define_callbacks.rb +5 -3
- data/lib/active_record/dynamic_matchers.rb +9 -9
- data/lib/active_record/enum.rb +18 -13
- data/lib/active_record/errors.rb +42 -3
- data/lib/active_record/explain.rb +3 -1
- data/lib/active_record/explain_registry.rb +2 -0
- data/lib/active_record/explain_subscriber.rb +2 -0
- data/lib/active_record/fixture_set/file.rb +2 -0
- data/lib/active_record/fixtures.rb +67 -60
- data/lib/active_record/gem_version.rb +5 -3
- data/lib/active_record/inheritance.rb +49 -19
- data/lib/active_record/integration.rb +58 -19
- data/lib/active_record/internal_metadata.rb +2 -0
- data/lib/active_record/legacy_yaml_adapter.rb +3 -1
- data/lib/active_record/locking/optimistic.rb +14 -17
- data/lib/active_record/locking/pessimistic.rb +9 -6
- data/lib/active_record/log_subscriber.rb +43 -0
- data/lib/active_record/migration/command_recorder.rb +11 -9
- data/lib/active_record/migration/compatibility.rb +47 -9
- data/lib/active_record/migration/join_table.rb +2 -0
- data/lib/active_record/migration.rb +189 -139
- data/lib/active_record/model_schema.rb +16 -21
- data/lib/active_record/nested_attributes.rb +18 -6
- data/lib/active_record/no_touching.rb +3 -1
- data/lib/active_record/null_relation.rb +2 -0
- data/lib/active_record/persistence.rb +167 -16
- data/lib/active_record/query_cache.rb +6 -8
- data/lib/active_record/querying.rb +4 -2
- data/lib/active_record/railtie.rb +80 -6
- data/lib/active_record/railties/console_sandbox.rb +2 -0
- data/lib/active_record/railties/controller_runtime.rb +2 -0
- data/lib/active_record/railties/databases.rake +46 -36
- data/lib/active_record/readonly_attributes.rb +3 -2
- data/lib/active_record/reflection.rb +108 -194
- data/lib/active_record/relation/batches/batch_enumerator.rb +2 -0
- data/lib/active_record/relation/batches.rb +20 -5
- data/lib/active_record/relation/calculations.rb +45 -19
- data/lib/active_record/relation/delegation.rb +45 -27
- data/lib/active_record/relation/finder_methods.rb +75 -76
- data/lib/active_record/relation/from_clause.rb +2 -8
- data/lib/active_record/relation/merger.rb +53 -23
- data/lib/active_record/relation/predicate_builder/array_handler.rb +10 -7
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +46 -0
- data/lib/active_record/relation/predicate_builder/base_handler.rb +2 -2
- data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +12 -1
- data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +56 -0
- data/lib/active_record/relation/predicate_builder/range_handler.rb +26 -9
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +6 -0
- data/lib/active_record/relation/predicate_builder.rb +60 -79
- data/lib/active_record/relation/query_attribute.rb +28 -2
- data/lib/active_record/relation/query_methods.rb +128 -99
- data/lib/active_record/relation/record_fetch_warning.rb +2 -0
- data/lib/active_record/relation/spawn_methods.rb +4 -2
- data/lib/active_record/relation/where_clause.rb +65 -68
- data/lib/active_record/relation/where_clause_factory.rb +5 -48
- data/lib/active_record/relation.rb +120 -214
- data/lib/active_record/result.rb +2 -0
- data/lib/active_record/runtime_registry.rb +2 -0
- data/lib/active_record/sanitization.rb +129 -121
- data/lib/active_record/schema.rb +4 -2
- data/lib/active_record/schema_dumper.rb +36 -26
- data/lib/active_record/schema_migration.rb +2 -0
- data/lib/active_record/scoping/default.rb +8 -9
- data/lib/active_record/scoping/named.rb +23 -7
- data/lib/active_record/scoping.rb +9 -8
- data/lib/active_record/secure_token.rb +2 -0
- data/lib/active_record/serialization.rb +2 -0
- data/lib/active_record/statement_cache.rb +23 -13
- data/lib/active_record/store.rb +3 -1
- data/lib/active_record/suppressor.rb +2 -0
- data/lib/active_record/table_metadata.rb +12 -3
- data/lib/active_record/tasks/database_tasks.rb +25 -14
- data/lib/active_record/tasks/mysql_database_tasks.rb +9 -48
- data/lib/active_record/tasks/postgresql_database_tasks.rb +10 -2
- data/lib/active_record/tasks/sqlite_database_tasks.rb +25 -3
- data/lib/active_record/timestamp.rb +6 -6
- data/lib/active_record/touch_later.rb +2 -0
- data/lib/active_record/transactions.rb +33 -28
- data/lib/active_record/translation.rb +2 -0
- data/lib/active_record/type/adapter_specific_registry.rb +2 -0
- data/lib/active_record/type/date.rb +2 -0
- data/lib/active_record/type/date_time.rb +2 -0
- data/lib/active_record/type/decimal_without_scale.rb +2 -0
- data/lib/active_record/type/hash_lookup_type_map.rb +2 -0
- data/lib/active_record/type/internal/timezone.rb +2 -0
- data/lib/active_record/type/json.rb +30 -0
- data/lib/active_record/type/serialized.rb +2 -0
- data/lib/active_record/type/text.rb +2 -0
- data/lib/active_record/type/time.rb +2 -0
- data/lib/active_record/type/type_map.rb +2 -0
- data/lib/active_record/type/unsigned_integer.rb +2 -0
- data/lib/active_record/type.rb +4 -1
- data/lib/active_record/type_caster/connection.rb +2 -0
- data/lib/active_record/type_caster/map.rb +3 -1
- data/lib/active_record/type_caster.rb +2 -0
- data/lib/active_record/validations/absence.rb +2 -0
- data/lib/active_record/validations/associated.rb +2 -0
- data/lib/active_record/validations/length.rb +2 -0
- data/lib/active_record/validations/presence.rb +2 -0
- data/lib/active_record/validations/uniqueness.rb +35 -5
- data/lib/active_record/validations.rb +2 -0
- data/lib/active_record/version.rb +2 -0
- data/lib/active_record.rb +11 -4
- data/lib/rails/generators/active_record/application_record/application_record_generator.rb +27 -0
- data/lib/rails/generators/active_record/{model/templates/application_record.rb → application_record/templates/application_record.rb.tt} +0 -0
- data/lib/rails/generators/active_record/migration/migration_generator.rb +3 -1
- data/lib/rails/generators/active_record/migration/templates/{create_table_migration.rb → create_table_migration.rb.tt} +0 -0
- data/lib/rails/generators/active_record/migration/templates/{migration.rb → migration.rb.tt} +0 -0
- data/lib/rails/generators/active_record/migration.rb +2 -0
- data/lib/rails/generators/active_record/model/model_generator.rb +2 -23
- data/lib/rails/generators/active_record/model/templates/{model.rb → model.rb.tt} +0 -0
- data/lib/rails/generators/active_record/model/templates/{module.rb → module.rb.tt} +0 -0
- data/lib/rails/generators/active_record.rb +3 -1
- metadata +26 -39
- data/lib/active_record/associations/preloader/belongs_to.rb +0 -15
- data/lib/active_record/associations/preloader/collection_association.rb +0 -17
- data/lib/active_record/associations/preloader/has_many.rb +0 -15
- data/lib/active_record/associations/preloader/has_many_through.rb +0 -19
- data/lib/active_record/associations/preloader/has_one.rb +0 -15
- data/lib/active_record/associations/preloader/has_one_through.rb +0 -9
- data/lib/active_record/associations/preloader/singular_association.rb +0 -18
- data/lib/active_record/attribute/user_provided_default.rb +0 -30
- data/lib/active_record/attribute.rb +0 -240
- data/lib/active_record/attribute_mutation_tracker.rb +0 -122
- data/lib/active_record/attribute_set/builder.rb +0 -126
- data/lib/active_record/attribute_set/yaml_encoder.rb +0 -41
- data/lib/active_record/attribute_set.rb +0 -113
- data/lib/active_record/connection_adapters/postgresql/oid/json.rb +0 -10
- data/lib/active_record/railties/jdbcmysql_error.rb +0 -16
- data/lib/active_record/relation/predicate_builder/association_query_handler.rb +0 -88
- data/lib/active_record/relation/predicate_builder/polymorphic_array_handler.rb +0 -59
- data/lib/active_record/type/internal/abstract_json.rb +0 -37
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require "active_record/connection_adapters/determine_if_preparable_visitor"
|
3
4
|
require "active_record/connection_adapters/schema_cache"
|
4
5
|
require "active_record/connection_adapters/sql_type_metadata"
|
@@ -6,7 +7,9 @@ require "active_record/connection_adapters/abstract/schema_dumper"
|
|
6
7
|
require "active_record/connection_adapters/abstract/schema_creation"
|
7
8
|
require "active_support/concurrency/load_interlock_aware_monitor"
|
8
9
|
require "arel/collectors/bind"
|
10
|
+
require "arel/collectors/composite"
|
9
11
|
require "arel/collectors/sql_string"
|
12
|
+
require "arel/collectors/substitute_binds"
|
10
13
|
|
11
14
|
module ActiveRecord
|
12
15
|
module ConnectionAdapters # :nodoc:
|
@@ -69,7 +72,6 @@ module ActiveRecord
|
|
69
72
|
include Quoting, DatabaseStatements, SchemaStatements
|
70
73
|
include DatabaseLimits
|
71
74
|
include QueryCache
|
72
|
-
include ColumnDumper
|
73
75
|
include Savepoints
|
74
76
|
|
75
77
|
SIMPLE_INT = /\A\d+\z/
|
@@ -79,7 +81,9 @@ module ActiveRecord
|
|
79
81
|
alias :in_use? :owner
|
80
82
|
|
81
83
|
def self.type_cast_config_to_integer(config)
|
82
|
-
if config
|
84
|
+
if config.is_a?(Integer)
|
85
|
+
config
|
86
|
+
elsif config =~ SIMPLE_INT
|
83
87
|
config.to_i
|
84
88
|
else
|
85
89
|
config
|
@@ -103,6 +107,7 @@ module ActiveRecord
|
|
103
107
|
@logger = logger
|
104
108
|
@config = config
|
105
109
|
@pool = nil
|
110
|
+
@idle_since = Concurrent.monotonic_time
|
106
111
|
@schema_cache = SchemaCache.new self
|
107
112
|
@quoted_column_names, @quoted_table_names = {}, {}
|
108
113
|
@visitor = arel_visitor
|
@@ -116,6 +121,14 @@ module ActiveRecord
|
|
116
121
|
end
|
117
122
|
end
|
118
123
|
|
124
|
+
def migrations_paths # :nodoc:
|
125
|
+
@config[:migrations_paths] || Migrator.migrations_paths
|
126
|
+
end
|
127
|
+
|
128
|
+
def migration_context # :nodoc:
|
129
|
+
MigrationContext.new(migrations_paths)
|
130
|
+
end
|
131
|
+
|
119
132
|
class Version
|
120
133
|
include Comparable
|
121
134
|
|
@@ -128,51 +141,14 @@ module ActiveRecord
|
|
128
141
|
end
|
129
142
|
end
|
130
143
|
|
131
|
-
class BindCollector < Arel::Collectors::Bind
|
132
|
-
def compile(bvs, conn)
|
133
|
-
casted_binds = bvs.map(&:value_for_database)
|
134
|
-
super(casted_binds.map { |value| conn.quote(value) })
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
class SQLString < Arel::Collectors::SQLString
|
139
|
-
def compile(bvs, conn)
|
140
|
-
super(bvs)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
def collector
|
145
|
-
if prepared_statements
|
146
|
-
SQLString.new
|
147
|
-
else
|
148
|
-
BindCollector.new
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
def arel_visitor # :nodoc:
|
153
|
-
Arel::Visitors::ToSql.new(self)
|
154
|
-
end
|
155
|
-
|
156
144
|
def valid_type?(type) # :nodoc:
|
157
145
|
!native_database_types[type].nil?
|
158
146
|
end
|
159
147
|
|
160
|
-
def schema_creation
|
161
|
-
SchemaCreation.new self
|
162
|
-
end
|
163
|
-
|
164
|
-
# Returns an array of +Column+ objects for the table specified by +table_name+.
|
165
|
-
def columns(table_name) # :nodoc:
|
166
|
-
table_name = table_name.to_s
|
167
|
-
column_definitions(table_name).map do |field|
|
168
|
-
new_column_from_field(table_name, field)
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
148
|
# this method must only be called while holding connection pool's mutex
|
173
149
|
def lease
|
174
150
|
if in_use?
|
175
|
-
msg = "Cannot lease connection, "
|
151
|
+
msg = "Cannot lease connection, ".dup
|
176
152
|
if @owner == Thread.current
|
177
153
|
msg << "it is already leased by the current thread."
|
178
154
|
else
|
@@ -199,6 +175,7 @@ module ActiveRecord
|
|
199
175
|
"Current thread: #{Thread.current}."
|
200
176
|
end
|
201
177
|
|
178
|
+
@idle_since = Concurrent.monotonic_time
|
202
179
|
@owner = nil
|
203
180
|
else
|
204
181
|
raise ActiveRecordError, "Cannot expire connection, it is not currently leased."
|
@@ -218,6 +195,12 @@ module ActiveRecord
|
|
218
195
|
end
|
219
196
|
end
|
220
197
|
|
198
|
+
# Seconds since this connection was returned to the pool
|
199
|
+
def seconds_idle # :nodoc:
|
200
|
+
return 0 if in_use?
|
201
|
+
Concurrent.monotonic_time - @idle_since
|
202
|
+
end
|
203
|
+
|
221
204
|
def unprepared_statement
|
222
205
|
old_prepared_statements, @prepared_statements = @prepared_statements, false
|
223
206
|
yield
|
@@ -231,16 +214,6 @@ module ActiveRecord
|
|
231
214
|
self.class::ADAPTER_NAME
|
232
215
|
end
|
233
216
|
|
234
|
-
def supports_migrations? # :nodoc:
|
235
|
-
true
|
236
|
-
end
|
237
|
-
deprecate :supports_migrations?
|
238
|
-
|
239
|
-
def supports_primary_key? # :nodoc:
|
240
|
-
true
|
241
|
-
end
|
242
|
-
deprecate :supports_primary_key?
|
243
|
-
|
244
217
|
# Does this adapter support DDL rollbacks in transactions? That is, would
|
245
218
|
# CREATE TABLE or ALTER TABLE get rolled back by a transaction?
|
246
219
|
def supports_ddl_transactions?
|
@@ -309,6 +282,11 @@ module ActiveRecord
|
|
309
282
|
false
|
310
283
|
end
|
311
284
|
|
285
|
+
# Does this adapter support creating invalid constraints?
|
286
|
+
def supports_validate_constraints?
|
287
|
+
false
|
288
|
+
end
|
289
|
+
|
312
290
|
# Does this adapter support creating foreign key constraints
|
313
291
|
# in the same statement as creating the table?
|
314
292
|
def supports_foreign_keys_in_create?
|
@@ -350,6 +328,11 @@ module ActiveRecord
|
|
350
328
|
false
|
351
329
|
end
|
352
330
|
|
331
|
+
# Does this adapter support foreign/external tables?
|
332
|
+
def supports_foreign_tables?
|
333
|
+
false
|
334
|
+
end
|
335
|
+
|
353
336
|
# This is meant to be implemented by the adapters that support extensions
|
354
337
|
def disable_extension(name)
|
355
338
|
end
|
@@ -412,6 +395,19 @@ module ActiveRecord
|
|
412
395
|
reset_transaction
|
413
396
|
end
|
414
397
|
|
398
|
+
# Immediately forget this connection ever existed. Unlike disconnect!,
|
399
|
+
# this will not communicate with the server.
|
400
|
+
#
|
401
|
+
# After calling this method, the behavior of all other methods becomes
|
402
|
+
# undefined. This is called internally just before a forked process gets
|
403
|
+
# rid of a connection that belonged to its parent.
|
404
|
+
def discard!
|
405
|
+
# This should be overridden by concrete adapters.
|
406
|
+
#
|
407
|
+
# Prevent @connection's finalizer from touching the socket, or
|
408
|
+
# otherwise communicating with its server, when it is collected.
|
409
|
+
end
|
410
|
+
|
415
411
|
# Reset the state of this connection, directing the DBMS to clear
|
416
412
|
# transactions and other connection-related server-side state. Usually a
|
417
413
|
# database-dependent operation.
|
@@ -437,10 +433,7 @@ module ActiveRecord
|
|
437
433
|
# Checks whether the connection to the database is still active (i.e. not stale).
|
438
434
|
# This is done under the hood by calling #active?. If the connection
|
439
435
|
# is no longer active, then this method will reconnect to the database.
|
440
|
-
def verify!
|
441
|
-
if ignored.size > 0
|
442
|
-
ActiveSupport::Deprecation.warn("Passing arguments to #verify method of the connection has no effect and has been deprecated. Please remove all arguments from the #verify method call.")
|
443
|
-
end
|
436
|
+
def verify!
|
444
437
|
reconnect! unless active?
|
445
438
|
end
|
446
439
|
|
@@ -476,40 +469,12 @@ module ActiveRecord
|
|
476
469
|
pool.checkin self
|
477
470
|
end
|
478
471
|
|
479
|
-
def
|
480
|
-
|
481
|
-
initialize_type_map(mapping)
|
482
|
-
end
|
483
|
-
end
|
484
|
-
|
485
|
-
def new_column(name, default, sql_type_metadata, null, table_name, default_function = nil, collation = nil) # :nodoc:
|
486
|
-
Column.new(name, default, sql_type_metadata, null, table_name, default_function, collation)
|
472
|
+
def column_name_for_operation(operation, node) # :nodoc:
|
473
|
+
column_name_from_arel_node(node)
|
487
474
|
end
|
488
475
|
|
489
|
-
def
|
490
|
-
|
491
|
-
end
|
492
|
-
|
493
|
-
def column_name_for_operation(operation, node) # :nodoc:
|
494
|
-
visitor.accept(node, collector).value
|
495
|
-
end
|
496
|
-
|
497
|
-
def combine_bind_parameters(
|
498
|
-
from_clause: [],
|
499
|
-
join_clause: [],
|
500
|
-
where_clause: [],
|
501
|
-
having_clause: [],
|
502
|
-
limit: nil,
|
503
|
-
offset: nil
|
504
|
-
) # :nodoc:
|
505
|
-
result = from_clause + join_clause + where_clause + having_clause
|
506
|
-
if limit
|
507
|
-
result << limit
|
508
|
-
end
|
509
|
-
if offset
|
510
|
-
result << offset
|
511
|
-
end
|
512
|
-
result
|
476
|
+
def column_name_from_arel_node(node) # :nodoc:
|
477
|
+
visitor.accept(node, Arel::Collectors::SQLString.new).value
|
513
478
|
end
|
514
479
|
|
515
480
|
def default_index_type?(index) # :nodoc:
|
@@ -517,8 +482,13 @@ module ActiveRecord
|
|
517
482
|
end
|
518
483
|
|
519
484
|
private
|
485
|
+
def type_map
|
486
|
+
@type_map ||= Type::TypeMap.new.tap do |mapping|
|
487
|
+
initialize_type_map(mapping)
|
488
|
+
end
|
489
|
+
end
|
520
490
|
|
521
|
-
def initialize_type_map(m)
|
491
|
+
def initialize_type_map(m = type_map)
|
522
492
|
register_class_with_limit m, %r(boolean)i, Type::Boolean
|
523
493
|
register_class_with_limit m, %r(char)i, Type::String
|
524
494
|
register_class_with_limit m, %r(binary)i, Type::Binary
|
@@ -536,6 +506,8 @@ module ActiveRecord
|
|
536
506
|
m.alias_type %r(number)i, "decimal"
|
537
507
|
m.alias_type %r(double)i, "float"
|
538
508
|
|
509
|
+
m.register_type %r(^json)i, Type::Json.new
|
510
|
+
|
539
511
|
m.register_type(%r(decimal)i) do |sql_type|
|
540
512
|
scale = extract_scale(sql_type)
|
541
513
|
precision = extract_precision(sql_type)
|
@@ -551,7 +523,7 @@ module ActiveRecord
|
|
551
523
|
|
552
524
|
def reload_type_map
|
553
525
|
type_map.clear
|
554
|
-
initialize_type_map
|
526
|
+
initialize_type_map
|
555
527
|
end
|
556
528
|
|
557
529
|
def register_class_with_limit(mapping, key, klass)
|
@@ -580,12 +552,7 @@ module ActiveRecord
|
|
580
552
|
end
|
581
553
|
|
582
554
|
def extract_limit(sql_type)
|
583
|
-
|
584
|
-
when /^bigint/i
|
585
|
-
8
|
586
|
-
when /\((.*)\)/
|
587
|
-
$1.to_i
|
588
|
-
end
|
555
|
+
$1.to_i if sql_type =~ /\((.*)\)/
|
589
556
|
end
|
590
557
|
|
591
558
|
def translate_exception_class(e, sql)
|
@@ -609,12 +576,14 @@ module ActiveRecord
|
|
609
576
|
type_casted_binds: type_casted_binds,
|
610
577
|
statement_name: statement_name,
|
611
578
|
connection_id: object_id) do
|
579
|
+
begin
|
612
580
|
@lock.synchronize do
|
613
581
|
yield
|
614
582
|
end
|
583
|
+
rescue => e
|
584
|
+
raise translate_exception_class(e, sql)
|
615
585
|
end
|
616
|
-
|
617
|
-
raise translate_exception_class(e, sql)
|
586
|
+
end
|
618
587
|
end
|
619
588
|
|
620
589
|
def translate_exception(exception, message)
|
@@ -636,6 +605,24 @@ module ActiveRecord
|
|
636
605
|
columns(table_name).detect { |c| c.name == column_name } ||
|
637
606
|
raise(ActiveRecordError, "No such column: #{table_name}.#{column_name}")
|
638
607
|
end
|
608
|
+
|
609
|
+
def collector
|
610
|
+
if prepared_statements
|
611
|
+
Arel::Collectors::Composite.new(
|
612
|
+
Arel::Collectors::SQLString.new,
|
613
|
+
Arel::Collectors::Bind.new,
|
614
|
+
)
|
615
|
+
else
|
616
|
+
Arel::Collectors::SubstituteBinds.new(
|
617
|
+
self,
|
618
|
+
Arel::Collectors::SQLString.new,
|
619
|
+
)
|
620
|
+
end
|
621
|
+
end
|
622
|
+
|
623
|
+
def arel_visitor
|
624
|
+
Arel::Visitors::ToSql.new(self)
|
625
|
+
end
|
639
626
|
end
|
640
627
|
end
|
641
628
|
end
|