activerecord 5.1.0 → 5.2.3
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 +596 -450
- 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.rb +11 -4
- data/lib/active_record/aggregations.rb +6 -5
- data/lib/active_record/association_relation.rb +7 -5
- data/lib/active_record/associations.rb +77 -85
- data/lib/active_record/associations/alias_tracker.rb +23 -32
- data/lib/active_record/associations/association.rb +49 -35
- data/lib/active_record/associations/association_scope.rb +55 -55
- data/lib/active_record/associations/belongs_to_association.rb +30 -11
- 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 +21 -8
- data/lib/active_record/associations/builder/collection_association.rb +1 -1
- 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 +66 -53
- data/lib/active_record/associations/collection_proxy.rb +30 -73
- data/lib/active_record/associations/foreign_association.rb +2 -0
- data/lib/active_record/associations/has_many_association.rb +13 -2
- data/lib/active_record/associations/has_many_through_association.rb +37 -19
- data/lib/active_record/associations/has_one_association.rb +14 -1
- data/lib/active_record/associations/has_one_through_association.rb +13 -8
- data/lib/active_record/associations/join_dependency.rb +52 -96
- data/lib/active_record/associations/join_dependency/join_association.rb +22 -75
- 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/preloader.rb +17 -37
- data/lib/active_record/associations/preloader/association.rb +53 -92
- data/lib/active_record/associations/preloader/through_association.rb +72 -73
- data/lib/active_record/associations/singular_association.rb +14 -16
- data/lib/active_record/associations/through_association.rb +27 -12
- data/lib/active_record/attribute_assignment.rb +2 -5
- data/lib/active_record/attribute_decorators.rb +3 -2
- data/lib/active_record/attribute_methods.rb +65 -24
- data/lib/active_record/attribute_methods/before_type_cast.rb +2 -0
- data/lib/active_record/attribute_methods/dirty.rb +33 -216
- data/lib/active_record/attribute_methods/primary_key.rb +10 -13
- 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 +22 -19
- data/lib/active_record/attributes.rb +7 -6
- data/lib/active_record/autosave_association.rb +15 -13
- data/lib/active_record/base.rb +2 -0
- data/lib/active_record/callbacks.rb +12 -6
- data/lib/active_record/coders/json.rb +2 -0
- data/lib/active_record/coders/yaml_column.rb +2 -0
- data/lib/active_record/collection_cache_key.rb +15 -11
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +120 -39
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +7 -0
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +192 -37
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +13 -2
- data/lib/active_record/connection_adapters/abstract/quoting.rb +15 -25
- data/lib/active_record/connection_adapters/abstract/savepoints.rb +2 -0
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +15 -6
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +65 -7
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +31 -53
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +158 -87
- data/lib/active_record/connection_adapters/abstract/transaction.rb +66 -21
- data/lib/active_record/connection_adapters/abstract_adapter.rb +86 -98
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +126 -189
- data/lib/active_record/connection_adapters/column.rb +4 -2
- 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 +45 -15
- 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 -23
- 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 +30 -1
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +6 -32
- data/lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +13 -1
- 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 +3 -1
- 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 -11
- data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/money.rb +3 -1
- 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 +8 -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/quoting.rb +22 -1
- 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 +258 -129
- 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 +75 -87
- 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 +24 -1
- 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 +90 -96
- 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 +41 -61
- data/lib/active_record/counter_cache.rb +20 -15
- 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 +60 -15
- 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 +4 -2
- 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 +30 -42
- data/lib/active_record/locking/pessimistic.rb +10 -7
- data/lib/active_record/log_subscriber.rb +46 -4
- data/lib/active_record/migration.rb +189 -139
- data/lib/active_record/migration/command_recorder.rb +11 -9
- data/lib/active_record/migration/compatibility.rb +81 -29
- data/lib/active_record/migration/join_table.rb +2 -0
- data/lib/active_record/model_schema.rb +74 -58
- 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 +199 -54
- data/lib/active_record/query_cache.rb +8 -10
- data/lib/active_record/querying.rb +5 -3
- data/lib/active_record/railtie.rb +62 -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 +48 -38
- data/lib/active_record/readonly_attributes.rb +3 -2
- data/lib/active_record/reflection.rb +137 -207
- data/lib/active_record/relation.rb +132 -207
- data/lib/active_record/relation/batches.rb +32 -17
- data/lib/active_record/relation/batches/batch_enumerator.rb +2 -0
- data/lib/active_record/relation/calculations.rb +66 -25
- data/lib/active_record/relation/delegation.rb +45 -29
- data/lib/active_record/relation/finder_methods.rb +76 -85
- 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.rb +60 -79
- 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/query_attribute.rb +28 -2
- data/lib/active_record/relation/query_methods.rb +135 -103
- 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 -67
- data/lib/active_record/relation/where_clause_factory.rb +5 -48
- 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.rb +12 -10
- data/lib/active_record/scoping/default.rb +10 -7
- data/lib/active_record/scoping/named.rb +40 -12
- data/lib/active_record/secure_token.rb +2 -0
- data/lib/active_record/serialization.rb +2 -0
- data/lib/active_record/statement_cache.rb +22 -12
- 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 +38 -26
- data/lib/active_record/tasks/mysql_database_tasks.rb +11 -50
- data/lib/active_record/tasks/postgresql_database_tasks.rb +11 -3
- data/lib/active_record/tasks/sqlite_database_tasks.rb +25 -3
- data/lib/active_record/timestamp.rb +13 -6
- data/lib/active_record/touch_later.rb +2 -0
- data/lib/active_record/transactions.rb +32 -27
- data/lib/active_record/translation.rb +2 -0
- data/lib/active_record/type.rb +4 -1
- 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 +6 -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_caster.rb +2 -0
- data/lib/active_record/type_caster/connection.rb +2 -0
- data/lib/active_record/type_caster/map.rb +3 -1
- data/lib/active_record/validations.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 +36 -6
- data/lib/active_record/version.rb +2 -0
- data/lib/rails/generators/active_record.rb +3 -1
- 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.rb +2 -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/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
- metadata +24 -36
- 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.rb +0 -240
- data/lib/active_record/attribute/user_provided_default.rb +0 -30
- data/lib/active_record/attribute_mutation_tracker.rb +0 -113
- data/lib/active_record/attribute_set.rb +0 -113
- data/lib/active_record/attribute_set/builder.rb +0 -124
- data/lib/active_record/attribute_set/yaml_encoder.rb +0 -41
- 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 -33
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_record/connection_adapters/abstract_mysql_adapter"
|
2
4
|
require "active_record/connection_adapters/mysql/database_statements"
|
3
5
|
|
4
|
-
gem "mysql2", ">= 0.
|
6
|
+
gem "mysql2", ">= 0.4.4", "< 0.6.0"
|
5
7
|
require "mysql2"
|
6
|
-
raise "mysql2 0.4.3 is not supported. Please upgrade to 0.4.4+" if Mysql2::VERSION == "0.4.3"
|
7
8
|
|
8
9
|
module ActiveRecord
|
9
10
|
module ConnectionHandling # :nodoc:
|
@@ -103,6 +104,11 @@ module ActiveRecord
|
|
103
104
|
@connection.close
|
104
105
|
end
|
105
106
|
|
107
|
+
def discard! # :nodoc:
|
108
|
+
@connection.automatic_close = false
|
109
|
+
@connection = nil
|
110
|
+
end
|
111
|
+
|
106
112
|
private
|
107
113
|
|
108
114
|
def connect
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
module ConnectionAdapters
|
3
5
|
# PostgreSQL-specific extensions to column definitions in a table.
|
@@ -5,11 +7,38 @@ module ActiveRecord
|
|
5
7
|
delegate :array, :oid, :fmod, to: :sql_type_metadata
|
6
8
|
alias :array? :array
|
7
9
|
|
10
|
+
def initialize(*, max_identifier_length: 63, **)
|
11
|
+
super
|
12
|
+
@max_identifier_length = max_identifier_length
|
13
|
+
end
|
14
|
+
|
8
15
|
def serial?
|
9
16
|
return unless default_function
|
10
17
|
|
11
|
-
%r{\Anextval\('"
|
18
|
+
if %r{\Anextval\('"?(?<sequence_name>.+_(?<suffix>seq\d*))"?'::regclass\)\z} =~ default_function
|
19
|
+
sequence_name_from_parts(table_name, name, suffix) == sequence_name
|
20
|
+
end
|
12
21
|
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
attr_reader :max_identifier_length
|
25
|
+
|
26
|
+
private
|
27
|
+
def sequence_name_from_parts(table_name, column_name, suffix)
|
28
|
+
over_length = [table_name, column_name, suffix].map(&:length).sum + 2 - max_identifier_length
|
29
|
+
|
30
|
+
if over_length > 0
|
31
|
+
column_name_length = [(max_identifier_length - suffix.length - 2) / 2, column_name.length].min
|
32
|
+
over_length -= column_name.length - column_name_length
|
33
|
+
column_name = column_name[0, column_name_length - [over_length, 0].min]
|
34
|
+
end
|
35
|
+
|
36
|
+
if over_length > 0
|
37
|
+
table_name = table_name[0, table_name.length - over_length]
|
38
|
+
end
|
39
|
+
|
40
|
+
"#{table_name}_#{column_name}_#{suffix}"
|
41
|
+
end
|
13
42
|
end
|
14
43
|
end
|
15
44
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
module ConnectionAdapters
|
3
5
|
module PostgreSQL
|
@@ -7,30 +9,6 @@ module ActiveRecord
|
|
7
9
|
PostgreSQL::ExplainPrettyPrinter.new.pp(exec_query(sql, "EXPLAIN", binds))
|
8
10
|
end
|
9
11
|
|
10
|
-
def select_value(arel, name = nil, binds = []) # :nodoc:
|
11
|
-
select_result(arel, name, binds) do |result|
|
12
|
-
result.getvalue(0, 0) if result.ntuples > 0 && result.nfields > 0
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def select_values(arel, name = nil, binds = []) # :nodoc:
|
17
|
-
select_result(arel, name, binds) do |result|
|
18
|
-
if result.nfields > 0
|
19
|
-
result.column_values(0)
|
20
|
-
else
|
21
|
-
[]
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
# Executes a SELECT query and returns an array of rows. Each row is an
|
27
|
-
# array of field values.
|
28
|
-
def select_rows(arel, name = nil, binds = []) # :nodoc:
|
29
|
-
select_result(arel, name, binds) do |result|
|
30
|
-
result.values
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
12
|
# The internal PostgreSQL identifier of the money data type.
|
35
13
|
MONEY_COLUMN_TYPE_OID = 790 #:nodoc:
|
36
14
|
# The internal PostgreSQL identifier of the BYTEA data type.
|
@@ -171,18 +149,14 @@ module ActiveRecord
|
|
171
149
|
end
|
172
150
|
|
173
151
|
private
|
152
|
+
# Returns the current ID of a table's sequence.
|
153
|
+
def last_insert_id_result(sequence_name)
|
154
|
+
exec_query("SELECT currval(#{quote(sequence_name)})", "SQL")
|
155
|
+
end
|
174
156
|
|
175
157
|
def suppress_composite_primary_key(pk)
|
176
158
|
pk unless pk.is_a?(Array)
|
177
159
|
end
|
178
|
-
|
179
|
-
def select_result(arel, name, binds)
|
180
|
-
arel, binds = binds_from_relation(arel, binds)
|
181
|
-
sql = to_sql(arel, binds)
|
182
|
-
execute_and_clear(sql, name, binds) do |result|
|
183
|
-
yield result
|
184
|
-
end
|
185
|
-
end
|
186
160
|
end
|
187
161
|
end
|
188
162
|
end
|
@@ -1,14 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_record/connection_adapters/postgresql/oid/array"
|
2
4
|
require "active_record/connection_adapters/postgresql/oid/bit"
|
3
5
|
require "active_record/connection_adapters/postgresql/oid/bit_varying"
|
4
6
|
require "active_record/connection_adapters/postgresql/oid/bytea"
|
5
7
|
require "active_record/connection_adapters/postgresql/oid/cidr"
|
8
|
+
require "active_record/connection_adapters/postgresql/oid/date"
|
6
9
|
require "active_record/connection_adapters/postgresql/oid/date_time"
|
7
10
|
require "active_record/connection_adapters/postgresql/oid/decimal"
|
8
11
|
require "active_record/connection_adapters/postgresql/oid/enum"
|
9
12
|
require "active_record/connection_adapters/postgresql/oid/hstore"
|
10
13
|
require "active_record/connection_adapters/postgresql/oid/inet"
|
11
|
-
require "active_record/connection_adapters/postgresql/oid/json"
|
12
14
|
require "active_record/connection_adapters/postgresql/oid/jsonb"
|
13
15
|
require "active_record/connection_adapters/postgresql/oid/money"
|
14
16
|
require "active_record/connection_adapters/postgresql/oid/oid"
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
module ConnectionAdapters
|
3
5
|
module PostgreSQL
|
@@ -31,7 +33,13 @@ module ActiveRecord
|
|
31
33
|
|
32
34
|
def cast(value)
|
33
35
|
if value.is_a?(::String)
|
34
|
-
value =
|
36
|
+
value = begin
|
37
|
+
@pg_decoder.decode(value)
|
38
|
+
rescue TypeError
|
39
|
+
# malformed array string is treated as [], will raise in PG 2.0 gem
|
40
|
+
# this keeps a consistent implementation
|
41
|
+
[]
|
42
|
+
end
|
35
43
|
end
|
36
44
|
type_cast_array(value, :cast)
|
37
45
|
end
|
@@ -64,6 +72,10 @@ module ActiveRecord
|
|
64
72
|
deserialize(raw_old_value) != new_value
|
65
73
|
end
|
66
74
|
|
75
|
+
def force_equality?(value)
|
76
|
+
value.is_a?(::Array)
|
77
|
+
end
|
78
|
+
|
67
79
|
private
|
68
80
|
|
69
81
|
def type_cast_array(value, method)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module ConnectionAdapters
|
5
|
+
module PostgreSQL
|
6
|
+
module OID # :nodoc:
|
7
|
+
class Date < Type::Date # :nodoc:
|
8
|
+
def cast_value(value)
|
9
|
+
case value
|
10
|
+
when "infinity" then ::Float::INFINITY
|
11
|
+
when "-infinity" then -::Float::INFINITY
|
12
|
+
when / BC$/
|
13
|
+
astronomical_year = format("%04d", -value[/^\d+/].to_i + 1)
|
14
|
+
super(value.sub(/ BC$/, "").sub(/^\d+/, astronomical_year))
|
15
|
+
else
|
16
|
+
super
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
module ConnectionAdapters
|
3
5
|
module PostgreSQL
|
4
6
|
module OID # :nodoc:
|
5
7
|
class Decimal < Type::Decimal # :nodoc:
|
6
8
|
def infinity(options = {})
|
7
|
-
BigDecimal
|
9
|
+
BigDecimal("Infinity") * (options[:negative] ? -1 : 1)
|
8
10
|
end
|
9
11
|
end
|
10
12
|
end
|
@@ -1,21 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
module ConnectionAdapters
|
3
5
|
module PostgreSQL
|
4
6
|
module OID # :nodoc:
|
5
|
-
class Jsonb < Json # :nodoc:
|
7
|
+
class Jsonb < Type::Json # :nodoc:
|
6
8
|
def type
|
7
9
|
:jsonb
|
8
10
|
end
|
9
|
-
|
10
|
-
def changed_in_place?(raw_old_value, new_value)
|
11
|
-
# Postgres does not preserve insignificant whitespaces when
|
12
|
-
# round-tripping jsonb columns. This causes some false positives for
|
13
|
-
# the comparison here. Therefore, we need to parse and re-dump the
|
14
|
-
# raw value here to ensure the insignificant whitespaces are
|
15
|
-
# consistent with our encoder's output.
|
16
|
-
raw_old_value = serialize(deserialize(raw_old_value))
|
17
|
-
super(raw_old_value, new_value)
|
18
|
-
end
|
19
11
|
end
|
20
12
|
end
|
21
13
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
module ConnectionAdapters
|
3
5
|
module PostgreSQL
|
@@ -22,7 +24,7 @@ module ActiveRecord
|
|
22
24
|
# (3) -$2.55
|
23
25
|
# (4) ($2.55)
|
24
26
|
|
25
|
-
value.sub
|
27
|
+
value = value.sub(/^\((.+)\)$/, '-\1') # (4)
|
26
28
|
case value
|
27
29
|
when /^-?\D+[\d,]+\.\d{2}$/ # (1)
|
28
30
|
value.gsub!(/[^-\d.]/, "")
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
module ConnectionAdapters
|
3
5
|
module PostgreSQL
|
@@ -33,7 +35,7 @@ module ActiveRecord
|
|
33
35
|
if value.is_a?(::Range)
|
34
36
|
from = type_cast_single_for_database(value.begin)
|
35
37
|
to = type_cast_single_for_database(value.end)
|
36
|
-
|
38
|
+
::Range.new(from, to, value.exclude_end?)
|
37
39
|
else
|
38
40
|
super
|
39
41
|
end
|
@@ -51,6 +53,10 @@ module ActiveRecord
|
|
51
53
|
::Range.new(new_begin, new_end, value.exclude_end?)
|
52
54
|
end
|
53
55
|
|
56
|
+
def force_equality?(value)
|
57
|
+
value.is_a?(::Range)
|
58
|
+
end
|
59
|
+
|
54
60
|
private
|
55
61
|
|
56
62
|
def type_cast_single(value)
|
@@ -58,7 +64,7 @@ module ActiveRecord
|
|
58
64
|
end
|
59
65
|
|
60
66
|
def type_cast_single_for_database(value)
|
61
|
-
infinity?(value) ?
|
67
|
+
infinity?(value) ? value : @subtype.serialize(value)
|
62
68
|
end
|
63
69
|
|
64
70
|
def extract_bounds(value)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
module ConnectionAdapters
|
3
5
|
module PostgreSQL
|
@@ -29,8 +31,8 @@ module ActiveRecord
|
|
29
31
|
composites.each { |row| register_composite_type(row) }
|
30
32
|
end
|
31
33
|
|
32
|
-
def query_conditions_for_initial_load
|
33
|
-
known_type_names =
|
34
|
+
def query_conditions_for_initial_load
|
35
|
+
known_type_names = @store.keys.map { |n| "'#{n}'" }
|
34
36
|
known_type_types = %w('r' 'e' 'd')
|
35
37
|
<<-SQL % [known_type_names.join(", "), known_type_types.join(", ")]
|
36
38
|
WHERE
|
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
module ConnectionAdapters
|
3
5
|
module PostgreSQL
|
4
6
|
module OID # :nodoc:
|
5
7
|
class Uuid < Type::Value # :nodoc:
|
6
|
-
ACCEPTABLE_UUID = %r{\A\{?([a-fA-F0-9]{4}-?){8}\}
|
8
|
+
ACCEPTABLE_UUID = %r{\A(\{)?([a-fA-F0-9]{4}-?){8}(?(1)\}|)\z}
|
7
9
|
|
8
10
|
alias_method :serialize, :deserialize
|
9
11
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
module ConnectionAdapters
|
3
5
|
module PostgreSQL
|
@@ -62,7 +64,7 @@ module ActiveRecord
|
|
62
64
|
def quote_default_expression(value, column) # :nodoc:
|
63
65
|
if value.is_a?(Proc)
|
64
66
|
value.call
|
65
|
-
elsif column.type == :uuid && value.
|
67
|
+
elsif column.type == :uuid && value.is_a?(String) && /\(\)/.match?(value)
|
66
68
|
value # Does not quote function default values for UUID columns
|
67
69
|
elsif column.respond_to?(:array?)
|
68
70
|
value = type_cast_from_column(column, value)
|
@@ -77,6 +79,9 @@ module ActiveRecord
|
|
77
79
|
end
|
78
80
|
|
79
81
|
private
|
82
|
+
def lookup_cast_type(sql_type)
|
83
|
+
super(query_value("SELECT #{quote(sql_type)}::regtype::oid", "SCHEMA").to_i)
|
84
|
+
end
|
80
85
|
|
81
86
|
def _quote(value)
|
82
87
|
case value
|
@@ -96,6 +101,8 @@ module ActiveRecord
|
|
96
101
|
end
|
97
102
|
when OID::Array::Data
|
98
103
|
_quote(encode_array(value))
|
104
|
+
when Range
|
105
|
+
_quote(encode_range(value))
|
99
106
|
else
|
100
107
|
super
|
101
108
|
end
|
@@ -112,6 +119,8 @@ module ActiveRecord
|
|
112
119
|
value.to_s
|
113
120
|
when OID::Array::Data
|
114
121
|
encode_array(value)
|
122
|
+
when Range
|
123
|
+
encode_range(value)
|
115
124
|
else
|
116
125
|
super
|
117
126
|
end
|
@@ -128,6 +137,10 @@ module ActiveRecord
|
|
128
137
|
result
|
129
138
|
end
|
130
139
|
|
140
|
+
def encode_range(range)
|
141
|
+
"[#{type_cast_range_value(range.first)},#{type_cast_range_value(range.last)}#{range.exclude_end? ? ')' : ']'}"
|
142
|
+
end
|
143
|
+
|
131
144
|
def determine_encoding_of_strings_in_array(value)
|
132
145
|
case value
|
133
146
|
when ::Array then determine_encoding_of_strings_in_array(value.first)
|
@@ -141,6 +154,14 @@ module ActiveRecord
|
|
141
154
|
else _type_cast(values)
|
142
155
|
end
|
143
156
|
end
|
157
|
+
|
158
|
+
def type_cast_range_value(value)
|
159
|
+
infinity?(value) ? "" : type_cast(value)
|
160
|
+
end
|
161
|
+
|
162
|
+
def infinity?(value)
|
163
|
+
value.respond_to?(:infinite?) && value.infinite?
|
164
|
+
end
|
144
165
|
end
|
145
166
|
end
|
146
167
|
end
|