activerecord 5.2.3 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of activerecord might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +898 -532
- data/MIT-LICENSE +3 -1
- data/README.rdoc +7 -5
- data/examples/performance.rb +1 -1
- data/lib/active_record/aggregations.rb +5 -4
- data/lib/active_record/association_relation.rb +22 -12
- data/lib/active_record/associations/alias_tracker.rb +19 -16
- data/lib/active_record/associations/association.rb +95 -42
- data/lib/active_record/associations/association_scope.rb +21 -21
- data/lib/active_record/associations/belongs_to_association.rb +50 -46
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +1 -5
- data/lib/active_record/associations/builder/association.rb +23 -21
- data/lib/active_record/associations/builder/belongs_to.rb +29 -59
- data/lib/active_record/associations/builder/collection_association.rb +10 -19
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +17 -41
- data/lib/active_record/associations/builder/has_many.rb +8 -2
- data/lib/active_record/associations/builder/has_one.rb +33 -2
- data/lib/active_record/associations/builder/singular_association.rb +3 -1
- data/lib/active_record/associations/collection_association.rb +31 -29
- data/lib/active_record/associations/collection_proxy.rb +25 -21
- data/lib/active_record/associations/foreign_association.rb +20 -0
- data/lib/active_record/associations/has_many_association.rb +26 -13
- data/lib/active_record/associations/has_many_through_association.rb +27 -28
- data/lib/active_record/associations/has_one_association.rb +43 -31
- data/lib/active_record/associations/has_one_through_association.rb +5 -5
- data/lib/active_record/associations/join_dependency/join_association.rb +54 -12
- data/lib/active_record/associations/join_dependency/join_part.rb +5 -5
- data/lib/active_record/associations/join_dependency.rb +91 -60
- data/lib/active_record/associations/preloader/association.rb +71 -43
- data/lib/active_record/associations/preloader/through_association.rb +49 -40
- data/lib/active_record/associations/preloader.rb +48 -35
- data/lib/active_record/associations/singular_association.rb +3 -17
- data/lib/active_record/associations/through_association.rb +1 -1
- data/lib/active_record/associations.rb +133 -25
- data/lib/active_record/attribute_assignment.rb +17 -19
- data/lib/active_record/attribute_methods/before_type_cast.rb +13 -7
- data/lib/active_record/attribute_methods/dirty.rb +101 -40
- data/lib/active_record/attribute_methods/primary_key.rb +20 -25
- data/lib/active_record/attribute_methods/query.rb +4 -8
- data/lib/active_record/attribute_methods/read.rb +14 -56
- data/lib/active_record/attribute_methods/serialization.rb +12 -7
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +12 -15
- data/lib/active_record/attribute_methods/write.rb +18 -34
- data/lib/active_record/attribute_methods.rb +81 -143
- data/lib/active_record/attributes.rb +45 -8
- data/lib/active_record/autosave_association.rb +76 -47
- data/lib/active_record/base.rb +4 -17
- data/lib/active_record/callbacks.rb +158 -43
- data/lib/active_record/coders/yaml_column.rb +1 -2
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +293 -132
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +7 -36
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +167 -146
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +21 -17
- data/lib/active_record/connection_adapters/abstract/quoting.rb +98 -47
- data/lib/active_record/connection_adapters/abstract/savepoints.rb +3 -3
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +153 -110
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +203 -90
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +2 -4
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +381 -146
- data/lib/active_record/connection_adapters/abstract/transaction.rb +155 -68
- data/lib/active_record/connection_adapters/abstract_adapter.rb +229 -98
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +243 -275
- data/lib/active_record/connection_adapters/column.rb +30 -12
- data/lib/active_record/connection_adapters/deduplicable.rb +29 -0
- data/lib/active_record/connection_adapters/legacy_pool_manager.rb +31 -0
- data/lib/active_record/connection_adapters/mysql/column.rb +1 -1
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +86 -32
- data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +1 -2
- data/lib/active_record/connection_adapters/mysql/quoting.rb +44 -7
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +34 -10
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +48 -32
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +14 -6
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +139 -19
- data/lib/active_record/connection_adapters/mysql/type_metadata.rb +14 -9
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +53 -18
- data/lib/active_record/connection_adapters/pool_config.rb +63 -0
- data/lib/active_record/connection_adapters/pool_manager.rb +43 -0
- data/lib/active_record/connection_adapters/postgresql/column.rb +37 -28
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +38 -54
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +1 -2
- data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +1 -4
- data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +3 -5
- data/lib/active_record/connection_adapters/postgresql/oid/date.rb +2 -2
- data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +10 -2
- data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +1 -2
- data/lib/active_record/connection_adapters/postgresql/oid/interval.rb +49 -0
- data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +3 -4
- data/lib/active_record/connection_adapters/postgresql/oid/macaddr.rb +25 -0
- data/lib/active_record/connection_adapters/postgresql/oid/money.rb +2 -2
- data/lib/active_record/connection_adapters/postgresql/oid/oid.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +3 -4
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +25 -7
- data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +9 -7
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +15 -3
- data/lib/active_record/connection_adapters/postgresql/oid.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +47 -10
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +2 -2
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +19 -4
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +107 -91
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +120 -100
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +31 -26
- data/lib/active_record/connection_adapters/postgresql/utils.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +222 -112
- data/lib/active_record/connection_adapters/schema_cache.rb +127 -21
- data/lib/active_record/connection_adapters/sql_type_metadata.rb +19 -6
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +144 -0
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +42 -7
- data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +5 -1
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +77 -13
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +175 -187
- data/lib/active_record/connection_adapters/statement_pool.rb +0 -1
- data/lib/active_record/connection_adapters.rb +50 -0
- data/lib/active_record/connection_handling.rb +285 -33
- data/lib/active_record/core.rb +308 -100
- data/lib/active_record/counter_cache.rb +8 -30
- data/lib/active_record/database_configurations/connection_url_resolver.rb +98 -0
- data/lib/active_record/database_configurations/database_config.rb +80 -0
- data/lib/active_record/database_configurations/hash_config.rb +96 -0
- data/lib/active_record/database_configurations/url_config.rb +53 -0
- data/lib/active_record/database_configurations.rb +272 -0
- data/lib/active_record/delegated_type.rb +209 -0
- data/lib/active_record/destroy_association_async_job.rb +36 -0
- data/lib/active_record/dynamic_matchers.rb +3 -4
- data/lib/active_record/enum.rb +71 -17
- data/lib/active_record/errors.rb +62 -19
- data/lib/active_record/explain.rb +10 -6
- data/lib/active_record/explain_subscriber.rb +1 -1
- data/lib/active_record/fixture_set/file.rb +10 -17
- data/lib/active_record/fixture_set/model_metadata.rb +32 -0
- data/lib/active_record/fixture_set/render_context.rb +17 -0
- data/lib/active_record/fixture_set/table_row.rb +152 -0
- data/lib/active_record/fixture_set/table_rows.rb +46 -0
- data/lib/active_record/fixtures.rb +197 -481
- data/lib/active_record/gem_version.rb +3 -3
- data/lib/active_record/inheritance.rb +53 -24
- data/lib/active_record/insert_all.rb +208 -0
- data/lib/active_record/integration.rb +67 -17
- data/lib/active_record/internal_metadata.rb +26 -9
- data/lib/active_record/legacy_yaml_adapter.rb +7 -3
- data/lib/active_record/locking/optimistic.rb +26 -22
- data/lib/active_record/locking/pessimistic.rb +9 -5
- data/lib/active_record/log_subscriber.rb +34 -35
- data/lib/active_record/middleware/database_selector/resolver/session.rb +48 -0
- data/lib/active_record/middleware/database_selector/resolver.rb +92 -0
- data/lib/active_record/middleware/database_selector.rb +77 -0
- data/lib/active_record/migration/command_recorder.rb +96 -44
- data/lib/active_record/migration/compatibility.rb +141 -64
- data/lib/active_record/migration/join_table.rb +0 -1
- data/lib/active_record/migration.rb +205 -156
- data/lib/active_record/model_schema.rb +148 -22
- data/lib/active_record/nested_attributes.rb +4 -7
- data/lib/active_record/no_touching.rb +8 -1
- data/lib/active_record/null_relation.rb +0 -1
- data/lib/active_record/persistence.rb +267 -59
- data/lib/active_record/query_cache.rb +21 -4
- data/lib/active_record/querying.rb +40 -23
- data/lib/active_record/railtie.rb +115 -58
- data/lib/active_record/railties/controller_runtime.rb +30 -35
- data/lib/active_record/railties/databases.rake +402 -78
- data/lib/active_record/readonly_attributes.rb +4 -0
- data/lib/active_record/reflection.rb +113 -101
- data/lib/active_record/relation/batches/batch_enumerator.rb +25 -9
- data/lib/active_record/relation/batches.rb +44 -35
- data/lib/active_record/relation/calculations.rb +157 -93
- data/lib/active_record/relation/delegation.rb +35 -50
- data/lib/active_record/relation/finder_methods.rb +65 -40
- data/lib/active_record/relation/from_clause.rb +5 -1
- data/lib/active_record/relation/merger.rb +32 -40
- data/lib/active_record/relation/predicate_builder/array_handler.rb +13 -13
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +5 -9
- data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +1 -2
- data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +4 -7
- data/lib/active_record/relation/predicate_builder/range_handler.rb +3 -23
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +1 -1
- data/lib/active_record/relation/predicate_builder.rb +58 -40
- data/lib/active_record/relation/query_attribute.rb +13 -8
- data/lib/active_record/relation/query_methods.rb +487 -199
- data/lib/active_record/relation/record_fetch_warning.rb +3 -3
- data/lib/active_record/relation/spawn_methods.rb +9 -9
- data/lib/active_record/relation/where_clause.rb +108 -58
- data/lib/active_record/relation.rb +375 -104
- data/lib/active_record/result.rb +64 -38
- data/lib/active_record/runtime_registry.rb +2 -2
- data/lib/active_record/sanitization.rb +22 -41
- data/lib/active_record/schema.rb +2 -11
- data/lib/active_record/schema_dumper.rb +54 -9
- data/lib/active_record/schema_migration.rb +7 -9
- data/lib/active_record/scoping/default.rb +6 -8
- data/lib/active_record/scoping/named.rb +17 -24
- data/lib/active_record/scoping.rb +8 -9
- data/lib/active_record/secure_token.rb +16 -8
- data/lib/active_record/serialization.rb +5 -3
- data/lib/active_record/signed_id.rb +116 -0
- data/lib/active_record/statement_cache.rb +51 -8
- data/lib/active_record/store.rb +88 -9
- data/lib/active_record/suppressor.rb +2 -2
- data/lib/active_record/table_metadata.rb +39 -43
- data/lib/active_record/tasks/database_tasks.rb +276 -81
- data/lib/active_record/tasks/mysql_database_tasks.rb +37 -39
- data/lib/active_record/tasks/postgresql_database_tasks.rb +27 -32
- data/lib/active_record/tasks/sqlite_database_tasks.rb +14 -17
- data/lib/active_record/test_databases.rb +24 -0
- data/lib/active_record/test_fixtures.rb +246 -0
- data/lib/active_record/timestamp.rb +43 -32
- data/lib/active_record/touch_later.rb +23 -22
- data/lib/active_record/transactions.rb +59 -117
- data/lib/active_record/translation.rb +1 -1
- data/lib/active_record/type/adapter_specific_registry.rb +3 -13
- data/lib/active_record/type/hash_lookup_type_map.rb +0 -1
- data/lib/active_record/type/serialized.rb +6 -3
- data/lib/active_record/type/time.rb +10 -0
- data/lib/active_record/type/type_map.rb +0 -1
- data/lib/active_record/type/unsigned_integer.rb +0 -1
- data/lib/active_record/type.rb +10 -5
- data/lib/active_record/type_caster/connection.rb +15 -15
- data/lib/active_record/type_caster/map.rb +8 -8
- data/lib/active_record/validations/associated.rb +1 -2
- data/lib/active_record/validations/numericality.rb +35 -0
- data/lib/active_record/validations/uniqueness.rb +38 -30
- data/lib/active_record/validations.rb +4 -3
- data/lib/active_record.rb +13 -12
- data/lib/arel/alias_predication.rb +9 -0
- data/lib/arel/attributes/attribute.rb +41 -0
- data/lib/arel/collectors/bind.rb +29 -0
- data/lib/arel/collectors/composite.rb +39 -0
- data/lib/arel/collectors/plain_string.rb +20 -0
- data/lib/arel/collectors/sql_string.rb +27 -0
- data/lib/arel/collectors/substitute_binds.rb +35 -0
- data/lib/arel/crud.rb +42 -0
- data/lib/arel/delete_manager.rb +18 -0
- data/lib/arel/errors.rb +9 -0
- data/lib/arel/expressions.rb +29 -0
- data/lib/arel/factory_methods.rb +49 -0
- data/lib/arel/insert_manager.rb +49 -0
- data/lib/arel/math.rb +45 -0
- data/lib/arel/nodes/and.rb +32 -0
- data/lib/arel/nodes/ascending.rb +23 -0
- data/lib/arel/nodes/binary.rb +126 -0
- data/lib/arel/nodes/bind_param.rb +44 -0
- data/lib/arel/nodes/case.rb +55 -0
- data/lib/arel/nodes/casted.rb +62 -0
- data/lib/arel/nodes/comment.rb +29 -0
- data/lib/arel/nodes/count.rb +12 -0
- data/lib/arel/nodes/delete_statement.rb +45 -0
- data/lib/arel/nodes/descending.rb +23 -0
- data/lib/arel/nodes/equality.rb +15 -0
- data/lib/arel/nodes/extract.rb +24 -0
- data/lib/arel/nodes/false.rb +16 -0
- data/lib/arel/nodes/full_outer_join.rb +8 -0
- data/lib/arel/nodes/function.rb +44 -0
- data/lib/arel/nodes/grouping.rb +11 -0
- data/lib/arel/nodes/homogeneous_in.rb +72 -0
- data/lib/arel/nodes/in.rb +15 -0
- data/lib/arel/nodes/infix_operation.rb +92 -0
- data/lib/arel/nodes/inner_join.rb +8 -0
- data/lib/arel/nodes/insert_statement.rb +37 -0
- data/lib/arel/nodes/join_source.rb +20 -0
- data/lib/arel/nodes/matches.rb +18 -0
- data/lib/arel/nodes/named_function.rb +23 -0
- data/lib/arel/nodes/node.rb +51 -0
- data/lib/arel/nodes/node_expression.rb +13 -0
- data/lib/arel/nodes/ordering.rb +27 -0
- data/lib/arel/nodes/outer_join.rb +8 -0
- data/lib/arel/nodes/over.rb +15 -0
- data/lib/arel/nodes/regexp.rb +16 -0
- data/lib/arel/nodes/right_outer_join.rb +8 -0
- data/lib/arel/nodes/select_core.rb +67 -0
- data/lib/arel/nodes/select_statement.rb +41 -0
- data/lib/arel/nodes/sql_literal.rb +19 -0
- data/lib/arel/nodes/string_join.rb +11 -0
- data/lib/arel/nodes/table_alias.rb +31 -0
- data/lib/arel/nodes/terminal.rb +16 -0
- data/lib/arel/nodes/true.rb +16 -0
- data/lib/arel/nodes/unary.rb +44 -0
- data/lib/arel/nodes/unary_operation.rb +20 -0
- data/lib/arel/nodes/unqualified_column.rb +22 -0
- data/lib/arel/nodes/update_statement.rb +41 -0
- data/lib/arel/nodes/values_list.rb +9 -0
- data/lib/arel/nodes/window.rb +126 -0
- data/lib/arel/nodes/with.rb +11 -0
- data/lib/arel/nodes.rb +70 -0
- data/lib/arel/order_predications.rb +13 -0
- data/lib/arel/predications.rb +250 -0
- data/lib/arel/select_manager.rb +270 -0
- data/lib/arel/table.rb +118 -0
- data/lib/arel/tree_manager.rb +72 -0
- data/lib/arel/update_manager.rb +34 -0
- data/lib/arel/visitors/dot.rb +308 -0
- data/lib/arel/visitors/mysql.rb +93 -0
- data/lib/arel/visitors/postgresql.rb +120 -0
- data/lib/arel/visitors/sqlite.rb +38 -0
- data/lib/arel/visitors/to_sql.rb +899 -0
- data/lib/arel/visitors/visitor.rb +45 -0
- data/lib/arel/visitors.rb +13 -0
- data/lib/arel/window_predications.rb +9 -0
- data/lib/arel.rb +54 -0
- data/lib/rails/generators/active_record/application_record/application_record_generator.rb +0 -1
- data/lib/rails/generators/active_record/migration/migration_generator.rb +3 -5
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +3 -1
- data/lib/rails/generators/active_record/migration/templates/migration.rb.tt +7 -5
- data/lib/rails/generators/active_record/migration.rb +19 -2
- data/lib/rails/generators/active_record/model/model_generator.rb +39 -2
- data/lib/rails/generators/active_record/model/templates/abstract_base_class.rb.tt +7 -0
- data/lib/rails/generators/active_record/model/templates/model.rb.tt +10 -1
- metadata +117 -32
- data/lib/active_record/attribute_decorators.rb +0 -90
- data/lib/active_record/collection_cache_key.rb +0 -53
- data/lib/active_record/connection_adapters/connection_specification.rb +0 -287
- data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +0 -33
- data/lib/active_record/define_callbacks.rb +0 -22
- data/lib/active_record/relation/predicate_builder/base_handler.rb +0 -19
- data/lib/active_record/relation/where_clause_factory.rb +0 -34
| @@ -5,7 +5,9 @@ module ActiveRecord | |
| 5 5 | 
             
              module ConnectionAdapters
         | 
| 6 6 | 
             
                # An abstract definition of a column in a table.
         | 
| 7 7 | 
             
                class Column
         | 
| 8 | 
            -
                   | 
| 8 | 
            +
                  include Deduplicable
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  attr_reader :name, :default, :sql_type_metadata, :null, :default_function, :collation, :comment
         | 
| 9 11 |  | 
| 10 12 | 
             
                  delegate :precision, :scale, :limit, :type, :sql_type, to: :sql_type_metadata, allow_nil: true
         | 
| 11 13 |  | 
| @@ -15,9 +17,8 @@ module ActiveRecord | |
| 15 17 | 
             
                  # +default+ is the type-casted default value, such as +new+ in <tt>sales_stage varchar(20) default 'new'</tt>.
         | 
| 16 18 | 
             
                  # +sql_type_metadata+ is various information about the type of the column
         | 
| 17 19 | 
             
                  # +null+ determines if this column allows +NULL+ values.
         | 
| 18 | 
            -
                  def initialize(name, default, sql_type_metadata = nil, null = true,  | 
| 20 | 
            +
                  def initialize(name, default, sql_type_metadata = nil, null = true, default_function = nil, collation: nil, comment: nil, **)
         | 
| 19 21 | 
             
                    @name = name.freeze
         | 
| 20 | 
            -
                    @table_name = table_name
         | 
| 21 22 | 
             
                    @sql_type_metadata = sql_type_metadata
         | 
| 22 23 | 
             
                    @null = null
         | 
| 23 24 | 
             
                    @default = default
         | 
| @@ -44,7 +45,6 @@ module ActiveRecord | |
| 44 45 |  | 
| 45 46 | 
             
                  def init_with(coder)
         | 
| 46 47 | 
             
                    @name = coder["name"]
         | 
| 47 | 
            -
                    @table_name = coder["table_name"]
         | 
| 48 48 | 
             
                    @sql_type_metadata = coder["sql_type_metadata"]
         | 
| 49 49 | 
             
                    @null = coder["null"]
         | 
| 50 50 | 
             
                    @default = coder["default"]
         | 
| @@ -55,7 +55,6 @@ module ActiveRecord | |
| 55 55 |  | 
| 56 56 | 
             
                  def encode_with(coder)
         | 
| 57 57 | 
             
                    coder["name"] = @name
         | 
| 58 | 
            -
                    coder["table_name"] = @table_name
         | 
| 59 58 | 
             
                    coder["sql_type_metadata"] = @sql_type_metadata
         | 
| 60 59 | 
             
                    coder["null"] = @null
         | 
| 61 60 | 
             
                    coder["default"] = @default
         | 
| @@ -66,23 +65,42 @@ module ActiveRecord | |
| 66 65 |  | 
| 67 66 | 
             
                  def ==(other)
         | 
| 68 67 | 
             
                    other.is_a?(Column) &&
         | 
| 69 | 
            -
                       | 
| 68 | 
            +
                      name == other.name &&
         | 
| 69 | 
            +
                      default == other.default &&
         | 
| 70 | 
            +
                      sql_type_metadata == other.sql_type_metadata &&
         | 
| 71 | 
            +
                      null == other.null &&
         | 
| 72 | 
            +
                      default_function == other.default_function &&
         | 
| 73 | 
            +
                      collation == other.collation &&
         | 
| 74 | 
            +
                      comment == other.comment
         | 
| 70 75 | 
             
                  end
         | 
| 71 76 | 
             
                  alias :eql? :==
         | 
| 72 77 |  | 
| 73 78 | 
             
                  def hash
         | 
| 74 | 
            -
                     | 
| 79 | 
            +
                    Column.hash ^
         | 
| 80 | 
            +
                      name.hash ^
         | 
| 81 | 
            +
                      name.encoding.hash ^
         | 
| 82 | 
            +
                      default.hash ^
         | 
| 83 | 
            +
                      sql_type_metadata.hash ^
         | 
| 84 | 
            +
                      null.hash ^
         | 
| 85 | 
            +
                      default_function.hash ^
         | 
| 86 | 
            +
                      collation.hash ^
         | 
| 87 | 
            +
                      comment.hash
         | 
| 75 88 | 
             
                  end
         | 
| 76 89 |  | 
| 77 | 
            -
                   | 
| 78 | 
            -
             | 
| 79 | 
            -
             | 
| 80 | 
            -
                       | 
| 90 | 
            +
                  private
         | 
| 91 | 
            +
                    def deduplicated
         | 
| 92 | 
            +
                      @name = -name
         | 
| 93 | 
            +
                      @sql_type_metadata = sql_type_metadata.deduplicate if sql_type_metadata
         | 
| 94 | 
            +
                      @default = -default if default
         | 
| 95 | 
            +
                      @default_function = -default_function if default_function
         | 
| 96 | 
            +
                      @collation = -collation if collation
         | 
| 97 | 
            +
                      @comment = -comment if comment
         | 
| 98 | 
            +
                      super
         | 
| 81 99 | 
             
                    end
         | 
| 82 100 | 
             
                end
         | 
| 83 101 |  | 
| 84 102 | 
             
                class NullColumn < Column
         | 
| 85 | 
            -
                  def initialize(name)
         | 
| 103 | 
            +
                  def initialize(name, **)
         | 
| 86 104 | 
             
                    super(name, nil)
         | 
| 87 105 | 
             
                  end
         | 
| 88 106 | 
             
                end
         | 
| @@ -0,0 +1,29 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module ActiveRecord
         | 
| 4 | 
            +
              module ConnectionAdapters # :nodoc:
         | 
| 5 | 
            +
                module Deduplicable
         | 
| 6 | 
            +
                  extend ActiveSupport::Concern
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  module ClassMethods
         | 
| 9 | 
            +
                    def registry
         | 
| 10 | 
            +
                      @registry ||= {}
         | 
| 11 | 
            +
                    end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                    def new(*, **)
         | 
| 14 | 
            +
                      super.deduplicate
         | 
| 15 | 
            +
                    end
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                  def deduplicate
         | 
| 19 | 
            +
                    self.class.registry[self] ||= deduplicated
         | 
| 20 | 
            +
                  end
         | 
| 21 | 
            +
                  alias :-@ :deduplicate
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                  private
         | 
| 24 | 
            +
                    def deduplicated
         | 
| 25 | 
            +
                      freeze
         | 
| 26 | 
            +
                    end
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
              end
         | 
| 29 | 
            +
            end
         | 
| @@ -0,0 +1,31 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module ActiveRecord
         | 
| 4 | 
            +
              module ConnectionAdapters
         | 
| 5 | 
            +
                class LegacyPoolManager # :nodoc:
         | 
| 6 | 
            +
                  def initialize
         | 
| 7 | 
            +
                    @name_to_pool_config = {}
         | 
| 8 | 
            +
                  end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  def shard_names
         | 
| 11 | 
            +
                    @name_to_pool_config.keys
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  def pool_configs(_ = nil)
         | 
| 15 | 
            +
                    @name_to_pool_config.values
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                  def remove_pool_config(_, shard)
         | 
| 19 | 
            +
                    @name_to_pool_config.delete(shard)
         | 
| 20 | 
            +
                  end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                  def get_pool_config(_, shard)
         | 
| 23 | 
            +
                    @name_to_pool_config[shard]
         | 
| 24 | 
            +
                  end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                  def set_pool_config(_, shard, pool_config)
         | 
| 27 | 
            +
                    @name_to_pool_config[shard] = pool_config
         | 
| 28 | 
            +
                  end
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
            end
         | 
| @@ -5,13 +5,13 @@ module ActiveRecord | |
| 5 5 | 
             
                module MySQL
         | 
| 6 6 | 
             
                  module DatabaseStatements
         | 
| 7 7 | 
             
                    # Returns an ActiveRecord::Result instance.
         | 
| 8 | 
            -
                    def select_all( | 
| 8 | 
            +
                    def select_all(*, **) # :nodoc:
         | 
| 9 9 | 
             
                      result = if ExplainRegistry.collect? && prepared_statements
         | 
| 10 10 | 
             
                        unprepared_statement { super }
         | 
| 11 11 | 
             
                      else
         | 
| 12 12 | 
             
                        super
         | 
| 13 13 | 
             
                      end
         | 
| 14 | 
            -
                       | 
| 14 | 
            +
                      @connection.abandon_results!
         | 
| 15 15 | 
             
                      result
         | 
| 16 16 | 
             
                    end
         | 
| 17 17 |  | 
| @@ -19,8 +19,30 @@ module ActiveRecord | |
| 19 19 | 
             
                      execute(sql, name).to_a
         | 
| 20 20 | 
             
                    end
         | 
| 21 21 |  | 
| 22 | 
            +
                    READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(
         | 
| 23 | 
            +
                      :desc, :describe, :set, :show, :use
         | 
| 24 | 
            +
                    ) # :nodoc:
         | 
| 25 | 
            +
                    private_constant :READ_QUERY
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                    def write_query?(sql) # :nodoc:
         | 
| 28 | 
            +
                      !READ_QUERY.match?(sql)
         | 
| 29 | 
            +
                    end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                    def explain(arel, binds = [])
         | 
| 32 | 
            +
                      sql     = "EXPLAIN #{to_sql(arel, binds)}"
         | 
| 33 | 
            +
                      start   = Concurrent.monotonic_time
         | 
| 34 | 
            +
                      result  = exec_query(sql, "EXPLAIN", binds)
         | 
| 35 | 
            +
                      elapsed = Concurrent.monotonic_time - start
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                      MySQL::ExplainPrettyPrinter.new.pp(result, elapsed)
         | 
| 38 | 
            +
                    end
         | 
| 39 | 
            +
             | 
| 22 40 | 
             
                    # Executes the SQL statement in the context of this connection.
         | 
| 23 41 | 
             
                    def execute(sql, name = nil)
         | 
| 42 | 
            +
                      if preventing_writes? && write_query?(sql)
         | 
| 43 | 
            +
                        raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}"
         | 
| 44 | 
            +
                      end
         | 
| 45 | 
            +
             | 
| 24 46 | 
             
                      # make sure we carry over any changes to ActiveRecord::Base.default_timezone that have been
         | 
| 25 47 | 
             
                      # made since we established the connection
         | 
| 26 48 | 
             
                      @connection.query_options[:database_timezone] = ActiveRecord::Base.default_timezone
         | 
| @@ -31,18 +53,28 @@ module ActiveRecord | |
| 31 53 | 
             
                    def exec_query(sql, name = "SQL", binds = [], prepare: false)
         | 
| 32 54 | 
             
                      if without_prepared_statement?(binds)
         | 
| 33 55 | 
             
                        execute_and_free(sql, name) do |result|
         | 
| 34 | 
            -
                           | 
| 56 | 
            +
                          if result
         | 
| 57 | 
            +
                            build_result(columns: result.fields, rows: result.to_a)
         | 
| 58 | 
            +
                          else
         | 
| 59 | 
            +
                            build_result(columns: [], rows: [])
         | 
| 60 | 
            +
                          end
         | 
| 35 61 | 
             
                        end
         | 
| 36 62 | 
             
                      else
         | 
| 37 63 | 
             
                        exec_stmt_and_free(sql, name, binds, cache_stmt: prepare) do |_, result|
         | 
| 38 | 
            -
                           | 
| 64 | 
            +
                          if result
         | 
| 65 | 
            +
                            build_result(columns: result.fields, rows: result.to_a)
         | 
| 66 | 
            +
                          else
         | 
| 67 | 
            +
                            build_result(columns: [], rows: [])
         | 
| 68 | 
            +
                          end
         | 
| 39 69 | 
             
                        end
         | 
| 40 70 | 
             
                      end
         | 
| 41 71 | 
             
                    end
         | 
| 42 72 |  | 
| 43 73 | 
             
                    def exec_delete(sql, name = nil, binds = [])
         | 
| 44 74 | 
             
                      if without_prepared_statement?(binds)
         | 
| 45 | 
            -
                         | 
| 75 | 
            +
                        @lock.synchronize do
         | 
| 76 | 
            +
                          execute_and_free(sql, name) { @connection.affected_rows }
         | 
| 77 | 
            +
                        end
         | 
| 46 78 | 
             
                      else
         | 
| 47 79 | 
             
                        exec_stmt_and_free(sql, name, binds) { |stmt| stmt.affected_rows }
         | 
| 48 80 | 
             
                      end
         | 
| @@ -50,55 +82,80 @@ module ActiveRecord | |
| 50 82 | 
             
                    alias :exec_update :exec_delete
         | 
| 51 83 |  | 
| 52 84 | 
             
                    private
         | 
| 85 | 
            +
                      def execute_batch(statements, name = nil)
         | 
| 86 | 
            +
                        combine_multi_statements(statements).each do |statement|
         | 
| 87 | 
            +
                          execute(statement, name)
         | 
| 88 | 
            +
                        end
         | 
| 89 | 
            +
                        @connection.abandon_results!
         | 
| 90 | 
            +
                      end
         | 
| 91 | 
            +
             | 
| 53 92 | 
             
                      def default_insert_value(column)
         | 
| 54 | 
            -
                         | 
| 93 | 
            +
                        super unless column.auto_increment?
         | 
| 55 94 | 
             
                      end
         | 
| 56 95 |  | 
| 57 96 | 
             
                      def last_inserted_id(result)
         | 
| 58 97 | 
             
                        @connection.last_id
         | 
| 59 98 | 
             
                      end
         | 
| 60 99 |  | 
| 61 | 
            -
                      def  | 
| 62 | 
            -
                         | 
| 63 | 
            -
                      end
         | 
| 100 | 
            +
                      def multi_statements_enabled?
         | 
| 101 | 
            +
                        flags = @config[:flags]
         | 
| 64 102 |  | 
| 65 | 
            -
                      def supports_set_server_option?
         | 
| 66 | 
            -
                        @connection.respond_to?(:set_server_option)
         | 
| 67 | 
            -
                      end
         | 
| 68 | 
            -
             | 
| 69 | 
            -
                      def multi_statements_enabled?(flags)
         | 
| 70 103 | 
             
                        if flags.is_a?(Array)
         | 
| 71 104 | 
             
                          flags.include?("MULTI_STATEMENTS")
         | 
| 72 105 | 
             
                        else
         | 
| 73 | 
            -
                          ( | 
| 106 | 
            +
                          flags.anybits?(Mysql2::Client::MULTI_STATEMENTS)
         | 
| 74 107 | 
             
                        end
         | 
| 75 108 | 
             
                      end
         | 
| 76 109 |  | 
| 77 110 | 
             
                      def with_multi_statements
         | 
| 78 | 
            -
                         | 
| 111 | 
            +
                        multi_statements_was = multi_statements_enabled?
         | 
| 79 112 |  | 
| 80 | 
            -
                        unless  | 
| 81 | 
            -
                           | 
| 82 | 
            -
                            @connection.set_server_option(Mysql2::Client::OPTION_MULTI_STATEMENTS_ON)
         | 
| 83 | 
            -
                          else
         | 
| 84 | 
            -
                            @config[:flags] = Mysql2::Client::MULTI_STATEMENTS
         | 
| 85 | 
            -
                            reconnect!
         | 
| 86 | 
            -
                          end
         | 
| 113 | 
            +
                        unless multi_statements_was
         | 
| 114 | 
            +
                          @connection.set_server_option(Mysql2::Client::OPTION_MULTI_STATEMENTS_ON)
         | 
| 87 115 | 
             
                        end
         | 
| 88 116 |  | 
| 89 117 | 
             
                        yield
         | 
| 90 118 | 
             
                      ensure
         | 
| 91 | 
            -
                        unless  | 
| 92 | 
            -
                           | 
| 93 | 
            -
             | 
| 119 | 
            +
                        unless multi_statements_was
         | 
| 120 | 
            +
                          @connection.set_server_option(Mysql2::Client::OPTION_MULTI_STATEMENTS_OFF)
         | 
| 121 | 
            +
                        end
         | 
| 122 | 
            +
                      end
         | 
| 123 | 
            +
             | 
| 124 | 
            +
                      def combine_multi_statements(total_sql)
         | 
| 125 | 
            +
                        total_sql.each_with_object([]) do |sql, total_sql_chunks|
         | 
| 126 | 
            +
                          previous_packet = total_sql_chunks.last
         | 
| 127 | 
            +
                          if max_allowed_packet_reached?(sql, previous_packet)
         | 
| 128 | 
            +
                            total_sql_chunks << +sql
         | 
| 94 129 | 
             
                          else
         | 
| 95 | 
            -
                             | 
| 96 | 
            -
                             | 
| 130 | 
            +
                            previous_packet << ";\n"
         | 
| 131 | 
            +
                            previous_packet << sql
         | 
| 97 132 | 
             
                          end
         | 
| 98 133 | 
             
                        end
         | 
| 99 134 | 
             
                      end
         | 
| 100 135 |  | 
| 136 | 
            +
                      def max_allowed_packet_reached?(current_packet, previous_packet)
         | 
| 137 | 
            +
                        if current_packet.bytesize > max_allowed_packet
         | 
| 138 | 
            +
                          raise ActiveRecordError,
         | 
| 139 | 
            +
                            "Fixtures set is too large #{current_packet.bytesize}. Consider increasing the max_allowed_packet variable."
         | 
| 140 | 
            +
                        elsif previous_packet.nil?
         | 
| 141 | 
            +
                          true
         | 
| 142 | 
            +
                        else
         | 
| 143 | 
            +
                          (current_packet.bytesize + previous_packet.bytesize + 2) > max_allowed_packet
         | 
| 144 | 
            +
                        end
         | 
| 145 | 
            +
                      end
         | 
| 146 | 
            +
             | 
| 147 | 
            +
                      def max_allowed_packet
         | 
| 148 | 
            +
                        @max_allowed_packet ||= show_variable("max_allowed_packet")
         | 
| 149 | 
            +
                      end
         | 
| 150 | 
            +
             | 
| 101 151 | 
             
                      def exec_stmt_and_free(sql, name, binds, cache_stmt: false)
         | 
| 152 | 
            +
                        if preventing_writes? && write_query?(sql)
         | 
| 153 | 
            +
                          raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}"
         | 
| 154 | 
            +
                        end
         | 
| 155 | 
            +
             | 
| 156 | 
            +
                        materialize_transactions
         | 
| 157 | 
            +
                        mark_transaction_written_if_write(sql)
         | 
| 158 | 
            +
             | 
| 102 159 | 
             
                        # make sure we carry over any changes to ActiveRecord::Base.default_timezone that have been
         | 
| 103 160 | 
             
                        # made since we established the connection
         | 
| 104 161 | 
             
                        @connection.query_options[:database_timezone] = ActiveRecord::Base.default_timezone
         | 
| @@ -107,10 +164,7 @@ module ActiveRecord | |
| 107 164 |  | 
| 108 165 | 
             
                        log(sql, name, binds, type_casted_binds) do
         | 
| 109 166 | 
             
                          if cache_stmt
         | 
| 110 | 
            -
                             | 
| 111 | 
            -
                              stmt: @connection.prepare(sql)
         | 
| 112 | 
            -
                            }
         | 
| 113 | 
            -
                            stmt = cache[:stmt]
         | 
| 167 | 
            +
                            stmt = @statements[sql] ||= @connection.prepare(sql)
         | 
| 114 168 | 
             
                          else
         | 
| 115 169 | 
             
                            stmt = @connection.prepare(sql)
         | 
| 116 170 | 
             
                          end
         | 
| @@ -37,7 +37,6 @@ module ActiveRecord | |
| 37 37 | 
             
                    end
         | 
| 38 38 |  | 
| 39 39 | 
             
                    private
         | 
| 40 | 
            -
             | 
| 41 40 | 
             
                      def compute_column_widths(result)
         | 
| 42 41 | 
             
                        [].tap do |widths|
         | 
| 43 42 | 
             
                          result.columns.each_with_index do |column, i|
         | 
| @@ -57,7 +56,7 @@ module ActiveRecord | |
| 57 56 | 
             
                        items.each_with_index do |item, i|
         | 
| 58 57 | 
             
                          item = "NULL" if item.nil?
         | 
| 59 58 | 
             
                          justifier = item.is_a?(Numeric) ? "rjust" : "ljust"
         | 
| 60 | 
            -
                          cells << item.to_s. | 
| 59 | 
            +
                          cells << item.to_s.public_send(justifier, widths[i])
         | 
| 61 60 | 
             
                        end
         | 
| 62 61 | 
             
                        "| " + cells.join(" | ") + " |"
         | 
| 63 62 | 
             
                      end
         | 
| @@ -5,11 +5,11 @@ module ActiveRecord | |
| 5 5 | 
             
                module MySQL
         | 
| 6 6 | 
             
                  module Quoting # :nodoc:
         | 
| 7 7 | 
             
                    def quote_column_name(name)
         | 
| 8 | 
            -
                       | 
| 8 | 
            +
                      self.class.quoted_column_names[name] ||= "`#{super.gsub('`', '``')}`"
         | 
| 9 9 | 
             
                    end
         | 
| 10 10 |  | 
| 11 11 | 
             
                    def quote_table_name(name)
         | 
| 12 | 
            -
                       | 
| 12 | 
            +
                      self.class.quoted_table_names[name] ||= super.gsub(".", "`.`").freeze
         | 
| 13 13 | 
             
                    end
         | 
| 14 14 |  | 
| 15 15 | 
             
                    def unquoted_true
         | 
| @@ -32,12 +32,49 @@ module ActiveRecord | |
| 32 32 | 
             
                      "x'#{value.hex}'"
         | 
| 33 33 | 
             
                    end
         | 
| 34 34 |  | 
| 35 | 
            -
                    def  | 
| 36 | 
            -
                       | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 35 | 
            +
                    def column_name_matcher
         | 
| 36 | 
            +
                      COLUMN_NAME
         | 
| 37 | 
            +
                    end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                    def column_name_with_order_matcher
         | 
| 40 | 
            +
                      COLUMN_NAME_WITH_ORDER
         | 
| 40 41 | 
             
                    end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                    COLUMN_NAME = /
         | 
| 44 | 
            +
                      \A
         | 
| 45 | 
            +
                      (
         | 
| 46 | 
            +
                        (?:
         | 
| 47 | 
            +
                          # `table_name`.`column_name` | function(one or no argument)
         | 
| 48 | 
            +
                          ((?:\w+\.|`\w+`\.)?(?:\w+|`\w+`)) | \w+\((?:|\g<2>)\)
         | 
| 49 | 
            +
                        )
         | 
| 50 | 
            +
                        (?:(?:\s+AS)?\s+(?:\w+|`\w+`))?
         | 
| 51 | 
            +
                      )
         | 
| 52 | 
            +
                      (?:\s*,\s*\g<1>)*
         | 
| 53 | 
            +
                      \z
         | 
| 54 | 
            +
                    /ix
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                    COLUMN_NAME_WITH_ORDER = /
         | 
| 57 | 
            +
                      \A
         | 
| 58 | 
            +
                      (
         | 
| 59 | 
            +
                        (?:
         | 
| 60 | 
            +
                          # `table_name`.`column_name` | function(one or no argument)
         | 
| 61 | 
            +
                          ((?:\w+\.|`\w+`\.)?(?:\w+|`\w+`)) | \w+\((?:|\g<2>)\)
         | 
| 62 | 
            +
                        )
         | 
| 63 | 
            +
                        (?:\s+ASC|\s+DESC)?
         | 
| 64 | 
            +
                      )
         | 
| 65 | 
            +
                      (?:\s*,\s*\g<1>)*
         | 
| 66 | 
            +
                      \z
         | 
| 67 | 
            +
                    /ix
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                    private_constant :COLUMN_NAME, :COLUMN_NAME_WITH_ORDER
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                    private
         | 
| 72 | 
            +
                      def _type_cast(value)
         | 
| 73 | 
            +
                        case value
         | 
| 74 | 
            +
                        when Date, Time then value
         | 
| 75 | 
            +
                        else super
         | 
| 76 | 
            +
                        end
         | 
| 77 | 
            +
                      end
         | 
| 41 78 | 
             
                  end
         | 
| 42 79 | 
             
                end
         | 
| 43 80 | 
             
              end
         | 
| @@ -3,34 +3,58 @@ | |
| 3 3 | 
             
            module ActiveRecord
         | 
| 4 4 | 
             
              module ConnectionAdapters
         | 
| 5 5 | 
             
                module MySQL
         | 
| 6 | 
            -
                  class SchemaCreation <  | 
| 7 | 
            -
                    delegate :add_sql_comment!, :mariadb?, to: :@conn
         | 
| 8 | 
            -
                    private :add_sql_comment!, :mariadb?
         | 
| 6 | 
            +
                  class SchemaCreation < SchemaCreation # :nodoc:
         | 
| 7 | 
            +
                    delegate :add_sql_comment!, :mariadb?, to: :@conn, private: true
         | 
| 9 8 |  | 
| 10 9 | 
             
                    private
         | 
| 11 | 
            -
             | 
| 12 10 | 
             
                      def visit_DropForeignKey(name)
         | 
| 13 11 | 
             
                        "DROP FOREIGN KEY #{name}"
         | 
| 14 12 | 
             
                      end
         | 
| 15 13 |  | 
| 14 | 
            +
                      def visit_DropCheckConstraint(name)
         | 
| 15 | 
            +
                        "DROP #{mariadb? ? 'CONSTRAINT' : 'CHECK'} #{name}"
         | 
| 16 | 
            +
                      end
         | 
| 17 | 
            +
             | 
| 16 18 | 
             
                      def visit_AddColumnDefinition(o)
         | 
| 17 19 | 
             
                        add_column_position!(super, column_options(o.column))
         | 
| 18 20 | 
             
                      end
         | 
| 19 21 |  | 
| 20 22 | 
             
                      def visit_ChangeColumnDefinition(o)
         | 
| 21 | 
            -
                        change_column_sql = "CHANGE #{quote_column_name(o.name)} #{accept(o.column)}" | 
| 23 | 
            +
                        change_column_sql = +"CHANGE #{quote_column_name(o.name)} #{accept(o.column)}"
         | 
| 22 24 | 
             
                        add_column_position!(change_column_sql, column_options(o.column))
         | 
| 23 25 | 
             
                      end
         | 
| 24 26 |  | 
| 25 | 
            -
                      def  | 
| 26 | 
            -
                         | 
| 27 | 
            +
                      def visit_CreateIndexDefinition(o)
         | 
| 28 | 
            +
                        sql = visit_IndexDefinition(o.index, true)
         | 
| 29 | 
            +
                        sql << " #{o.algorithm}" if o.algorithm
         | 
| 30 | 
            +
                        sql
         | 
| 31 | 
            +
                      end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                      def visit_IndexDefinition(o, create = false)
         | 
| 34 | 
            +
                        index_type = o.type&.to_s&.upcase || o.unique && "UNIQUE"
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                        sql = create ? ["CREATE"] : []
         | 
| 37 | 
            +
                        sql << index_type if index_type
         | 
| 38 | 
            +
                        sql << "INDEX"
         | 
| 39 | 
            +
                        sql << quote_column_name(o.name)
         | 
| 40 | 
            +
                        sql << "USING #{o.using}" if o.using
         | 
| 41 | 
            +
                        sql << "ON #{quote_table_name(o.table)}" if create
         | 
| 42 | 
            +
                        sql << "(#{quoted_columns(o)})"
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                        add_sql_comment!(sql.join(" "), o.comment)
         | 
| 45 | 
            +
                      end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                      def add_table_options!(create_sql, o)
         | 
| 48 | 
            +
                        create_sql << " DEFAULT CHARSET=#{o.charset}" if o.charset
         | 
| 49 | 
            +
                        create_sql << " COLLATE=#{o.collation}" if o.collation
         | 
| 50 | 
            +
                        add_sql_comment!(super, o.comment)
         | 
| 27 51 | 
             
                      end
         | 
| 28 52 |  | 
| 29 53 | 
             
                      def add_column_options!(sql, options)
         | 
| 30 54 | 
             
                        # By default, TIMESTAMP columns are NOT NULL, cannot contain NULL values,
         | 
| 31 55 | 
             
                        # and assigning NULL assigns the current timestamp. To permit a TIMESTAMP
         | 
| 32 56 | 
             
                        # column to contain NULL, explicitly declare it with the NULL attribute.
         | 
| 33 | 
            -
                        # See https://dev.mysql.com/doc/refman/ | 
| 57 | 
            +
                        # See https://dev.mysql.com/doc/refman/en/timestamp-initialization.html
         | 
| 34 58 | 
             
                        if /\Atimestamp\b/.match?(options[:column].sql_type) && !options[:primary_key]
         | 
| 35 59 | 
             
                          sql << " NULL" unless options[:null] == false || options_include_default?(options)
         | 
| 36 60 | 
             
                        end
         | 
| @@ -64,8 +88,8 @@ module ActiveRecord | |
| 64 88 | 
             
                      end
         | 
| 65 89 |  | 
| 66 90 | 
             
                      def index_in_create(table_name, column_name, options)
         | 
| 67 | 
            -
                         | 
| 68 | 
            -
                         | 
| 91 | 
            +
                        index, _ = @conn.add_index_options(table_name, column_name, **options)
         | 
| 92 | 
            +
                        accept(index)
         | 
| 69 93 | 
             
                      end
         | 
| 70 94 | 
             
                  end
         | 
| 71 95 | 
             
                end
         | 
| @@ -4,54 +4,70 @@ module ActiveRecord | |
| 4 4 | 
             
              module ConnectionAdapters
         | 
| 5 5 | 
             
                module MySQL
         | 
| 6 6 | 
             
                  module ColumnMethods
         | 
| 7 | 
            -
                     | 
| 8 | 
            -
                      args.each { |name| column(name, :blob, options) }
         | 
| 9 | 
            -
                    end
         | 
| 7 | 
            +
                    extend ActiveSupport::Concern
         | 
| 10 8 |  | 
| 11 | 
            -
                     | 
| 12 | 
            -
             | 
| 13 | 
            -
                     | 
| 9 | 
            +
                    ##
         | 
| 10 | 
            +
                    # :method: blob
         | 
| 11 | 
            +
                    # :call-seq: blob(*names, **options)
         | 
| 14 12 |  | 
| 15 | 
            -
                     | 
| 16 | 
            -
             | 
| 17 | 
            -
                     | 
| 13 | 
            +
                    ##
         | 
| 14 | 
            +
                    # :method: tinyblob
         | 
| 15 | 
            +
                    # :call-seq: tinyblob(*names, **options)
         | 
| 18 16 |  | 
| 19 | 
            -
                     | 
| 20 | 
            -
             | 
| 21 | 
            -
                     | 
| 17 | 
            +
                    ##
         | 
| 18 | 
            +
                    # :method: mediumblob
         | 
| 19 | 
            +
                    # :call-seq: mediumblob(*names, **options)
         | 
| 22 20 |  | 
| 23 | 
            -
                     | 
| 24 | 
            -
             | 
| 25 | 
            -
                     | 
| 21 | 
            +
                    ##
         | 
| 22 | 
            +
                    # :method: longblob
         | 
| 23 | 
            +
                    # :call-seq: longblob(*names, **options)
         | 
| 26 24 |  | 
| 27 | 
            -
                     | 
| 28 | 
            -
             | 
| 29 | 
            -
                     | 
| 25 | 
            +
                    ##
         | 
| 26 | 
            +
                    # :method: tinytext
         | 
| 27 | 
            +
                    # :call-seq: tinytext(*names, **options)
         | 
| 30 28 |  | 
| 31 | 
            -
                     | 
| 32 | 
            -
             | 
| 33 | 
            -
                     | 
| 29 | 
            +
                    ##
         | 
| 30 | 
            +
                    # :method: mediumtext
         | 
| 31 | 
            +
                    # :call-seq: mediumtext(*names, **options)
         | 
| 34 32 |  | 
| 35 | 
            -
                     | 
| 36 | 
            -
             | 
| 37 | 
            -
                     | 
| 33 | 
            +
                    ##
         | 
| 34 | 
            +
                    # :method: longtext
         | 
| 35 | 
            +
                    # :call-seq: longtext(*names, **options)
         | 
| 38 36 |  | 
| 39 | 
            -
                     | 
| 40 | 
            -
             | 
| 41 | 
            -
                     | 
| 37 | 
            +
                    ##
         | 
| 38 | 
            +
                    # :method: unsigned_integer
         | 
| 39 | 
            +
                    # :call-seq: unsigned_integer(*names, **options)
         | 
| 42 40 |  | 
| 43 | 
            -
                     | 
| 44 | 
            -
             | 
| 45 | 
            -
                     | 
| 41 | 
            +
                    ##
         | 
| 42 | 
            +
                    # :method: unsigned_bigint
         | 
| 43 | 
            +
                    # :call-seq: unsigned_bigint(*names, **options)
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                    ##
         | 
| 46 | 
            +
                    # :method: unsigned_float
         | 
| 47 | 
            +
                    # :call-seq: unsigned_float(*names, **options)
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                    ##
         | 
| 50 | 
            +
                    # :method: unsigned_decimal
         | 
| 51 | 
            +
                    # :call-seq: unsigned_decimal(*names, **options)
         | 
| 46 52 |  | 
| 47 | 
            -
                     | 
| 48 | 
            -
                       | 
| 53 | 
            +
                    included do
         | 
| 54 | 
            +
                      define_column_methods :blob, :tinyblob, :mediumblob, :longblob,
         | 
| 55 | 
            +
                        :tinytext, :mediumtext, :longtext, :unsigned_integer, :unsigned_bigint,
         | 
| 56 | 
            +
                        :unsigned_float, :unsigned_decimal
         | 
| 49 57 | 
             
                    end
         | 
| 50 58 | 
             
                  end
         | 
| 51 59 |  | 
| 52 60 | 
             
                  class TableDefinition < ActiveRecord::ConnectionAdapters::TableDefinition
         | 
| 53 61 | 
             
                    include ColumnMethods
         | 
| 54 62 |  | 
| 63 | 
            +
                    attr_reader :charset, :collation
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                    def initialize(conn, name, charset: nil, collation: nil, **)
         | 
| 66 | 
            +
                      super
         | 
| 67 | 
            +
                      @charset = charset
         | 
| 68 | 
            +
                      @collation = collation
         | 
| 69 | 
            +
                    end
         | 
| 70 | 
            +
             | 
| 55 71 | 
             
                    def new_column_definition(name, type, **options) # :nodoc:
         | 
| 56 72 | 
             
                      case type
         | 
| 57 73 | 
             
                      when :virtual
         | 
| @@ -10,6 +10,10 @@ module ActiveRecord | |
| 10 10 | 
             
                        spec[:unsigned] = "true" if column.unsigned?
         | 
| 11 11 | 
             
                        spec[:auto_increment] = "true" if column.auto_increment?
         | 
| 12 12 |  | 
| 13 | 
            +
                        if /\A(?<size>tiny|medium|long)(?:text|blob)/ =~ column.sql_type
         | 
| 14 | 
            +
                          spec = { size: size.to_sym.inspect }.merge!(spec)
         | 
| 15 | 
            +
                        end
         | 
| 16 | 
            +
             | 
| 13 17 | 
             
                        if @connection.supports_virtual_columns? && column.virtual?
         | 
| 14 18 | 
             
                          spec[:as] = extract_expression_for_virtual_column(column)
         | 
| 15 19 | 
             
                          spec[:stored] = "true" if /\b(?:STORED|PERSISTENT)\b/.match?(column.extra)
         | 
| @@ -37,19 +41,23 @@ module ActiveRecord | |
| 37 41 | 
             
                        case column.sql_type
         | 
| 38 42 | 
             
                        when /\Atimestamp\b/
         | 
| 39 43 | 
             
                          :timestamp
         | 
| 40 | 
            -
                        when  | 
| 41 | 
            -
                           | 
| 44 | 
            +
                        when /\A(?:enum|set)\b/
         | 
| 45 | 
            +
                          column.sql_type
         | 
| 42 46 | 
             
                        else
         | 
| 43 47 | 
             
                          super
         | 
| 44 48 | 
             
                        end
         | 
| 45 49 | 
             
                      end
         | 
| 46 50 |  | 
| 51 | 
            +
                      def schema_limit(column)
         | 
| 52 | 
            +
                        super unless /\A(?:tiny|medium|long)?(?:text|blob)\b/.match?(column.sql_type)
         | 
| 53 | 
            +
                      end
         | 
| 54 | 
            +
             | 
| 47 55 | 
             
                      def schema_precision(column)
         | 
| 48 56 | 
             
                        super unless /\A(?:date)?time(?:stamp)?\b/.match?(column.sql_type) && column.precision == 0
         | 
| 49 57 | 
             
                      end
         | 
| 50 58 |  | 
| 51 59 | 
             
                      def schema_collation(column)
         | 
| 52 | 
            -
                        if column.collation | 
| 60 | 
            +
                        if column.collation
         | 
| 53 61 | 
             
                          @table_collation_cache ||= {}
         | 
| 54 62 | 
             
                          @table_collation_cache[table_name] ||=
         | 
| 55 63 | 
             
                            @connection.exec_query("SHOW TABLE STATUS LIKE #{@connection.quote(table_name)}", "SCHEMA").first["Collation"]
         | 
| @@ -58,14 +66,14 @@ module ActiveRecord | |
| 58 66 | 
             
                      end
         | 
| 59 67 |  | 
| 60 68 | 
             
                      def extract_expression_for_virtual_column(column)
         | 
| 61 | 
            -
                        if @connection.mariadb? && @connection. | 
| 62 | 
            -
                          create_table_info = @connection.send(:create_table_info,  | 
| 69 | 
            +
                        if @connection.mariadb? && @connection.database_version < "10.2.5"
         | 
| 70 | 
            +
                          create_table_info = @connection.send(:create_table_info, table_name)
         | 
| 63 71 | 
             
                          column_name = @connection.quote_column_name(column.name)
         | 
| 64 72 | 
             
                          if %r/#{column_name} #{Regexp.quote(column.sql_type)}(?: COLLATE \w+)? AS \((?<expression>.+?)\) #{column.extra}/ =~ create_table_info
         | 
| 65 73 | 
             
                            $~[:expression].inspect
         | 
| 66 74 | 
             
                          end
         | 
| 67 75 | 
             
                        else
         | 
| 68 | 
            -
                          scope = @connection.send(:quoted_scope,  | 
| 76 | 
            +
                          scope = @connection.send(:quoted_scope, table_name)
         | 
| 69 77 | 
             
                          column_name = @connection.quote(column.name)
         | 
| 70 78 | 
             
                          sql = "SELECT generation_expression FROM information_schema.columns" \
         | 
| 71 79 | 
             
                                " WHERE table_schema = #{scope[:schema]}" \
         |