activerecord 6.0.0 → 7.2.3
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +996 -594
- data/MIT-LICENSE +1 -1
- data/README.rdoc +34 -34
- data/examples/performance.rb +2 -2
- data/lib/active_record/aggregations.rb +22 -20
- data/lib/active_record/association_relation.rb +22 -12
- data/lib/active_record/associations/alias_tracker.rb +41 -30
- data/lib/active_record/associations/association.rb +106 -41
- data/lib/active_record/associations/association_scope.rb +30 -21
- data/lib/active_record/associations/belongs_to_association.rb +69 -14
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +20 -6
- data/lib/active_record/associations/builder/association.rb +39 -6
- data/lib/active_record/associations/builder/belongs_to.rb +47 -17
- data/lib/active_record/associations/builder/collection_association.rb +14 -6
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +3 -10
- data/lib/active_record/associations/builder/has_many.rb +7 -3
- data/lib/active_record/associations/builder/has_one.rb +13 -16
- data/lib/active_record/associations/builder/singular_association.rb +7 -3
- data/lib/active_record/associations/collection_association.rb +90 -53
- data/lib/active_record/associations/collection_proxy.rb +54 -19
- data/lib/active_record/associations/disable_joins_association_scope.rb +59 -0
- data/lib/active_record/associations/errors.rb +265 -0
- data/lib/active_record/associations/foreign_association.rb +21 -1
- data/lib/active_record/associations/has_many_association.rb +41 -10
- data/lib/active_record/associations/has_many_through_association.rb +29 -12
- data/lib/active_record/associations/has_one_association.rb +33 -9
- data/lib/active_record/associations/has_one_through_association.rb +1 -1
- data/lib/active_record/associations/join_dependency/join_association.rb +41 -17
- data/lib/active_record/associations/join_dependency/join_part.rb +3 -3
- data/lib/active_record/associations/join_dependency.rb +97 -54
- data/lib/active_record/associations/nested_error.rb +47 -0
- data/lib/active_record/associations/preloader/association.rb +237 -54
- data/lib/active_record/associations/preloader/batch.rb +48 -0
- data/lib/active_record/associations/preloader/branch.rb +153 -0
- data/lib/active_record/associations/preloader/through_association.rb +51 -17
- data/lib/active_record/associations/preloader.rb +55 -121
- data/lib/active_record/associations/singular_association.rb +16 -4
- data/lib/active_record/associations/through_association.rb +26 -15
- data/lib/active_record/associations.rb +454 -440
- data/lib/active_record/asynchronous_queries_tracker.rb +60 -0
- data/lib/active_record/attribute_assignment.rb +11 -14
- data/lib/active_record/attribute_methods/before_type_cast.rb +36 -11
- data/lib/active_record/attribute_methods/composite_primary_key.rb +84 -0
- data/lib/active_record/attribute_methods/dirty.rb +75 -34
- data/lib/active_record/attribute_methods/primary_key.rb +53 -31
- data/lib/active_record/attribute_methods/query.rb +31 -22
- data/lib/active_record/attribute_methods/read.rb +16 -17
- data/lib/active_record/attribute_methods/serialization.rb +177 -35
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +18 -15
- data/lib/active_record/attribute_methods/write.rb +16 -28
- data/lib/active_record/attribute_methods.rb +227 -100
- data/lib/active_record/attributes.rb +94 -56
- data/lib/active_record/autosave_association.rb +119 -73
- data/lib/active_record/base.rb +31 -21
- data/lib/active_record/callbacks.rb +168 -55
- data/lib/active_record/coders/column_serializer.rb +61 -0
- data/lib/active_record/coders/json.rb +1 -1
- data/lib/active_record/coders/yaml_column.rb +70 -25
- data/lib/active_record/connection_adapters/abstract/connection_handler.rb +284 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb +211 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool/reaper.rb +79 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +367 -565
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +3 -57
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +277 -89
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +241 -69
- data/lib/active_record/connection_adapters/abstract/quoting.rb +122 -134
- data/lib/active_record/connection_adapters/abstract/savepoints.rb +4 -3
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +153 -116
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +324 -72
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +17 -4
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +611 -211
- data/lib/active_record/connection_adapters/abstract/transaction.rb +425 -82
- data/lib/active_record/connection_adapters/abstract_adapter.rb +698 -211
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +464 -239
- data/lib/active_record/connection_adapters/column.rb +28 -1
- data/lib/active_record/connection_adapters/deduplicable.rb +29 -0
- data/lib/active_record/connection_adapters/mysql/column.rb +2 -1
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +32 -137
- data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +1 -2
- data/lib/active_record/connection_adapters/mysql/quoting.rb +90 -43
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +41 -7
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +18 -1
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +13 -4
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +53 -15
- data/lib/active_record/connection_adapters/mysql/type_metadata.rb +10 -1
- data/lib/active_record/connection_adapters/mysql2/database_statements.rb +152 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +127 -63
- data/lib/active_record/connection_adapters/pool_config.rb +83 -0
- data/lib/active_record/connection_adapters/pool_manager.rb +57 -0
- data/lib/active_record/connection_adapters/postgresql/column.rb +54 -2
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +127 -100
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +1 -2
- data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +9 -5
- data/lib/active_record/connection_adapters/postgresql/oid/date.rb +10 -2
- data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +15 -2
- data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +53 -15
- data/lib/active_record/connection_adapters/postgresql/oid/interval.rb +49 -0
- data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +2 -3
- data/lib/active_record/connection_adapters/postgresql/oid/macaddr.rb +25 -0
- data/lib/active_record/connection_adapters/postgresql/oid/money.rb +5 -4
- data/lib/active_record/connection_adapters/postgresql/oid/oid.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +2 -3
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +35 -8
- data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/timestamp.rb +15 -0
- data/lib/active_record/connection_adapters/postgresql/oid/timestamp_with_time_zone.rb +30 -0
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +18 -6
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +23 -4
- data/lib/active_record/connection_adapters/postgresql/oid.rb +4 -0
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +139 -106
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +30 -2
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +98 -4
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +176 -4
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +78 -1
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +462 -118
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +8 -0
- data/lib/active_record/connection_adapters/postgresql/utils.rb +9 -11
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +585 -295
- data/lib/active_record/connection_adapters/schema_cache.rb +399 -60
- data/lib/active_record/connection_adapters/sql_type_metadata.rb +8 -0
- data/lib/active_record/connection_adapters/sqlite3/column.rb +62 -0
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +99 -48
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +80 -54
- data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +27 -1
- data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +20 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +16 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +102 -24
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +425 -174
- data/lib/active_record/connection_adapters/statement_pool.rb +7 -1
- data/lib/active_record/connection_adapters/trilogy/database_statements.rb +99 -0
- data/lib/active_record/connection_adapters/trilogy_adapter.rb +229 -0
- data/lib/active_record/connection_adapters.rb +176 -0
- data/lib/active_record/connection_handling.rb +243 -115
- data/lib/active_record/core.rb +481 -199
- data/lib/active_record/counter_cache.rb +69 -32
- data/lib/active_record/database_configurations/connection_url_resolver.rb +107 -0
- data/lib/active_record/database_configurations/database_config.rb +77 -10
- data/lib/active_record/database_configurations/hash_config.rb +148 -26
- data/lib/active_record/database_configurations/url_config.rb +44 -45
- data/lib/active_record/database_configurations.rb +190 -114
- data/lib/active_record/delegated_type.rb +279 -0
- data/lib/active_record/deprecator.rb +7 -0
- data/lib/active_record/destroy_association_async_job.rb +38 -0
- data/lib/active_record/disable_joins_association_relation.rb +39 -0
- data/lib/active_record/dynamic_matchers.rb +5 -6
- data/lib/active_record/encryption/auto_filtered_parameters.rb +66 -0
- data/lib/active_record/encryption/cipher/aes256_gcm.rb +101 -0
- data/lib/active_record/encryption/cipher.rb +53 -0
- data/lib/active_record/encryption/config.rb +68 -0
- data/lib/active_record/encryption/configurable.rb +60 -0
- data/lib/active_record/encryption/context.rb +42 -0
- data/lib/active_record/encryption/contexts.rb +76 -0
- data/lib/active_record/encryption/derived_secret_key_provider.rb +18 -0
- data/lib/active_record/encryption/deterministic_key_provider.rb +14 -0
- data/lib/active_record/encryption/encryptable_record.rb +230 -0
- data/lib/active_record/encryption/encrypted_attribute_type.rb +175 -0
- data/lib/active_record/encryption/encrypted_fixtures.rb +38 -0
- data/lib/active_record/encryption/encrypting_only_encryptor.rb +12 -0
- data/lib/active_record/encryption/encryptor.rb +171 -0
- data/lib/active_record/encryption/envelope_encryption_key_provider.rb +55 -0
- data/lib/active_record/encryption/errors.rb +15 -0
- data/lib/active_record/encryption/extended_deterministic_queries.rb +157 -0
- data/lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb +28 -0
- data/lib/active_record/encryption/key.rb +28 -0
- data/lib/active_record/encryption/key_generator.rb +53 -0
- data/lib/active_record/encryption/key_provider.rb +46 -0
- data/lib/active_record/encryption/message.rb +33 -0
- data/lib/active_record/encryption/message_pack_message_serializer.rb +76 -0
- data/lib/active_record/encryption/message_serializer.rb +96 -0
- data/lib/active_record/encryption/null_encryptor.rb +25 -0
- data/lib/active_record/encryption/properties.rb +76 -0
- data/lib/active_record/encryption/read_only_null_encryptor.rb +28 -0
- data/lib/active_record/encryption/scheme.rb +100 -0
- data/lib/active_record/encryption.rb +58 -0
- data/lib/active_record/enum.rb +224 -73
- data/lib/active_record/errors.rb +254 -36
- data/lib/active_record/explain.rb +30 -17
- data/lib/active_record/explain_registry.rb +11 -6
- data/lib/active_record/explain_subscriber.rb +2 -2
- data/lib/active_record/fixture_set/file.rb +22 -15
- data/lib/active_record/fixture_set/model_metadata.rb +15 -6
- data/lib/active_record/fixture_set/render_context.rb +3 -1
- data/lib/active_record/fixture_set/table_row.rb +88 -16
- data/lib/active_record/fixture_set/table_rows.rb +4 -5
- data/lib/active_record/fixtures.rb +229 -116
- data/lib/active_record/future_result.rb +178 -0
- data/lib/active_record/gem_version.rb +4 -4
- data/lib/active_record/inheritance.rb +121 -48
- data/lib/active_record/insert_all.rb +178 -29
- data/lib/active_record/integration.rb +16 -14
- data/lib/active_record/internal_metadata.rb +132 -21
- data/lib/active_record/legacy_yaml_adapter.rb +3 -36
- data/lib/active_record/locking/optimistic.rb +64 -33
- data/lib/active_record/locking/pessimistic.rb +21 -8
- data/lib/active_record/log_subscriber.rb +61 -30
- data/lib/active_record/marshalling.rb +59 -0
- data/lib/active_record/message_pack.rb +124 -0
- data/lib/active_record/middleware/database_selector/resolver/session.rb +3 -0
- data/lib/active_record/middleware/database_selector/resolver.rb +19 -19
- data/lib/active_record/middleware/database_selector.rb +25 -13
- data/lib/active_record/middleware/shard_selector.rb +62 -0
- data/lib/active_record/migration/command_recorder.rb +160 -55
- data/lib/active_record/migration/compatibility.rb +286 -43
- data/lib/active_record/migration/default_strategy.rb +22 -0
- data/lib/active_record/migration/execution_strategy.rb +19 -0
- data/lib/active_record/migration/join_table.rb +1 -2
- data/lib/active_record/migration/pending_migration_connection.rb +21 -0
- data/lib/active_record/migration.rb +421 -193
- data/lib/active_record/model_schema.rb +217 -125
- data/lib/active_record/nested_attributes.rb +62 -27
- data/lib/active_record/no_touching.rb +4 -4
- data/lib/active_record/normalization.rb +163 -0
- data/lib/active_record/persistence.rb +322 -319
- data/lib/active_record/promise.rb +84 -0
- data/lib/active_record/query_cache.rb +18 -15
- data/lib/active_record/query_logs.rb +193 -0
- data/lib/active_record/query_logs_formatter.rb +41 -0
- data/lib/active_record/querying.rb +54 -14
- data/lib/active_record/railtie.rb +250 -72
- data/lib/active_record/railties/console_sandbox.rb +2 -4
- data/lib/active_record/railties/controller_runtime.rb +25 -11
- data/lib/active_record/railties/databases.rake +312 -197
- data/lib/active_record/railties/job_runtime.rb +23 -0
- data/lib/active_record/readonly_attributes.rb +45 -3
- data/lib/active_record/reflection.rb +389 -146
- data/lib/active_record/relation/batches/batch_enumerator.rb +61 -16
- data/lib/active_record/relation/batches.rb +214 -73
- data/lib/active_record/relation/calculations.rb +379 -124
- data/lib/active_record/relation/delegation.rb +36 -23
- data/lib/active_record/relation/finder_methods.rb +159 -49
- data/lib/active_record/relation/from_clause.rb +5 -1
- data/lib/active_record/relation/merger.rb +41 -33
- data/lib/active_record/relation/predicate_builder/array_handler.rb +10 -11
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +42 -7
- data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +20 -13
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +5 -1
- data/lib/active_record/relation/predicate_builder.rb +79 -53
- data/lib/active_record/relation/query_attribute.rb +30 -12
- data/lib/active_record/relation/query_methods.rb +1156 -279
- data/lib/active_record/relation/record_fetch_warning.rb +12 -11
- data/lib/active_record/relation/spawn_methods.rb +10 -9
- data/lib/active_record/relation/where_clause.rb +100 -66
- data/lib/active_record/relation.rb +829 -194
- data/lib/active_record/result.rb +76 -56
- data/lib/active_record/runtime_registry.rb +71 -13
- data/lib/active_record/sanitization.rb +86 -47
- data/lib/active_record/schema.rb +39 -23
- data/lib/active_record/schema_dumper.rb +140 -33
- data/lib/active_record/schema_migration.rb +74 -29
- data/lib/active_record/scoping/default.rb +73 -19
- data/lib/active_record/scoping/named.rb +10 -28
- data/lib/active_record/scoping.rb +65 -35
- data/lib/active_record/secure_password.rb +60 -0
- data/lib/active_record/secure_token.rb +34 -8
- data/lib/active_record/serialization.rb +11 -4
- data/lib/active_record/signed_id.rb +138 -0
- data/lib/active_record/statement_cache.rb +26 -10
- data/lib/active_record/store.rb +19 -14
- data/lib/active_record/suppressor.rb +15 -17
- data/lib/active_record/table_metadata.rb +46 -36
- data/lib/active_record/tasks/database_tasks.rb +371 -205
- data/lib/active_record/tasks/mysql_database_tasks.rb +43 -36
- data/lib/active_record/tasks/postgresql_database_tasks.rb +54 -41
- data/lib/active_record/tasks/sqlite_database_tasks.rb +25 -13
- data/lib/active_record/test_databases.rb +5 -4
- data/lib/active_record/test_fixtures.rb +189 -104
- data/lib/active_record/testing/query_assertions.rb +121 -0
- data/lib/active_record/timestamp.rb +35 -25
- data/lib/active_record/token_for.rb +123 -0
- data/lib/active_record/touch_later.rb +31 -27
- data/lib/active_record/transaction.rb +132 -0
- data/lib/active_record/transactions.rb +131 -99
- data/lib/active_record/translation.rb +3 -5
- data/lib/active_record/type/adapter_specific_registry.rb +33 -18
- data/lib/active_record/type/hash_lookup_type_map.rb +34 -2
- data/lib/active_record/type/internal/timezone.rb +7 -2
- data/lib/active_record/type/serialized.rb +11 -6
- data/lib/active_record/type/time.rb +14 -0
- data/lib/active_record/type/type_map.rb +17 -21
- data/lib/active_record/type/unsigned_integer.rb +0 -1
- data/lib/active_record/type.rb +7 -2
- data/lib/active_record/type_caster/connection.rb +4 -5
- data/lib/active_record/type_caster/map.rb +8 -5
- data/lib/active_record/validations/absence.rb +1 -1
- data/lib/active_record/validations/associated.rb +13 -8
- data/lib/active_record/validations/numericality.rb +36 -0
- data/lib/active_record/validations/presence.rb +5 -28
- data/lib/active_record/validations/uniqueness.rb +88 -18
- data/lib/active_record/validations.rb +15 -8
- data/lib/active_record/version.rb +1 -1
- data/lib/active_record.rb +446 -40
- data/lib/arel/alias_predication.rb +1 -1
- data/lib/arel/attributes/attribute.rb +4 -8
- data/lib/arel/collectors/bind.rb +8 -1
- data/lib/arel/collectors/composite.rb +15 -0
- data/lib/arel/collectors/sql_string.rb +7 -0
- data/lib/arel/collectors/substitute_binds.rb +7 -0
- data/lib/arel/crud.rb +30 -22
- data/lib/arel/delete_manager.rb +23 -4
- data/lib/arel/errors.rb +10 -0
- data/lib/arel/factory_methods.rb +4 -0
- data/lib/arel/filter_predications.rb +9 -0
- data/lib/arel/insert_manager.rb +2 -3
- data/lib/arel/nodes/binary.rb +82 -9
- data/lib/arel/nodes/bind_param.rb +8 -0
- data/lib/arel/nodes/bound_sql_literal.rb +65 -0
- data/lib/arel/nodes/casted.rb +22 -10
- data/lib/arel/nodes/cte.rb +36 -0
- data/lib/arel/nodes/delete_statement.rb +14 -13
- data/lib/arel/nodes/equality.rb +6 -9
- data/lib/arel/nodes/filter.rb +10 -0
- data/lib/arel/nodes/fragments.rb +35 -0
- data/lib/arel/nodes/function.rb +1 -0
- data/lib/arel/nodes/grouping.rb +3 -0
- data/lib/arel/nodes/homogeneous_in.rb +68 -0
- data/lib/arel/nodes/in.rb +8 -1
- data/lib/arel/nodes/infix_operation.rb +13 -1
- data/lib/arel/nodes/insert_statement.rb +2 -2
- data/lib/arel/nodes/join_source.rb +1 -1
- data/lib/arel/nodes/leading_join.rb +8 -0
- data/lib/arel/nodes/{and.rb → nary.rb} +9 -2
- data/lib/arel/nodes/node.rb +122 -11
- data/lib/arel/nodes/ordering.rb +27 -0
- data/lib/arel/nodes/select_core.rb +2 -2
- data/lib/arel/nodes/select_statement.rb +2 -2
- data/lib/arel/nodes/sql_literal.rb +16 -0
- data/lib/arel/nodes/table_alias.rb +11 -3
- data/lib/arel/nodes/unary.rb +0 -1
- data/lib/arel/nodes/update_statement.rb +11 -4
- data/lib/arel/nodes.rb +10 -3
- data/lib/arel/predications.rb +31 -28
- data/lib/arel/select_manager.rb +18 -9
- data/lib/arel/table.rb +21 -10
- data/lib/arel/tree_manager.rb +8 -15
- data/lib/arel/update_manager.rb +25 -5
- data/lib/arel/visitors/dot.rb +94 -90
- data/lib/arel/visitors/mysql.rb +34 -6
- data/lib/arel/visitors/postgresql.rb +5 -16
- data/lib/arel/visitors/sqlite.rb +25 -1
- data/lib/arel/visitors/to_sql.rb +227 -81
- data/lib/arel/visitors/visitor.rb +2 -3
- data/lib/arel/visitors.rb +0 -7
- data/lib/arel.rb +37 -15
- data/lib/rails/generators/active_record/application_record/USAGE +8 -0
- data/lib/rails/generators/active_record/application_record/application_record_generator.rb +0 -1
- data/lib/rails/generators/active_record/application_record/templates/application_record.rb.tt +1 -1
- data/lib/rails/generators/active_record/migration/migration_generator.rb +1 -0
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +6 -1
- data/lib/rails/generators/active_record/migration/templates/migration.rb.tt +4 -4
- data/lib/rails/generators/active_record/migration.rb +9 -3
- data/lib/rails/generators/active_record/model/USAGE +113 -0
- data/lib/rails/generators/active_record/model/model_generator.rb +49 -4
- 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 +1 -1
- data/lib/rails/generators/active_record/model/templates/module.rb.tt +2 -2
- data/lib/rails/generators/active_record/multi_db/multi_db_generator.rb +16 -0
- data/lib/rails/generators/active_record/multi_db/templates/multi_db.rb.tt +44 -0
- metadata +117 -30
- data/lib/active_record/attribute_decorators.rb +0 -90
- data/lib/active_record/connection_adapters/connection_specification.rb +0 -297
- data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +0 -29
- data/lib/active_record/define_callbacks.rb +0 -22
- data/lib/active_record/null_relation.rb +0 -68
- data/lib/active_record/railties/collection_cache_association_loading.rb +0 -34
- data/lib/active_record/relation/predicate_builder/base_handler.rb +0 -18
- data/lib/active_record/relation/where_clause_factory.rb +0 -33
- data/lib/arel/attributes.rb +0 -22
- data/lib/arel/visitors/depth_first.rb +0 -204
- data/lib/arel/visitors/ibm_db.rb +0 -34
- data/lib/arel/visitors/informix.rb +0 -62
- data/lib/arel/visitors/mssql.rb +0 -157
- data/lib/arel/visitors/oracle.rb +0 -159
- data/lib/arel/visitors/oracle12.rb +0 -66
- data/lib/arel/visitors/where_sql.rb +0 -23
|
@@ -4,8 +4,10 @@ require "active_record/middleware/database_selector/resolver"
|
|
|
4
4
|
|
|
5
5
|
module ActiveRecord
|
|
6
6
|
module Middleware
|
|
7
|
+
# = Database Selector \Middleware
|
|
8
|
+
#
|
|
7
9
|
# The DatabaseSelector Middleware provides a framework for automatically
|
|
8
|
-
# swapping from the primary to the replica database connection. Rails
|
|
10
|
+
# swapping from the primary to the replica database connection. \Rails
|
|
9
11
|
# provides a basic framework to determine when to swap and allows for
|
|
10
12
|
# applications to write custom strategy classes to override the default
|
|
11
13
|
# behavior.
|
|
@@ -15,18 +17,26 @@ module ActiveRecord
|
|
|
15
17
|
# resolver context class that sets a value that helps the resolver class
|
|
16
18
|
# decide when to switch.
|
|
17
19
|
#
|
|
18
|
-
# Rails default middleware uses the request's session to set a timestamp
|
|
20
|
+
# \Rails default middleware uses the request's session to set a timestamp
|
|
19
21
|
# that informs the application when to read from a primary or read from a
|
|
20
22
|
# replica.
|
|
21
23
|
#
|
|
22
|
-
# To use the DatabaseSelector in your application with default settings
|
|
23
|
-
# the
|
|
24
|
+
# To use the DatabaseSelector in your application with default settings,
|
|
25
|
+
# run the provided generator.
|
|
24
26
|
#
|
|
25
|
-
#
|
|
26
|
-
#
|
|
27
|
-
#
|
|
27
|
+
# $ bin/rails g active_record:multi_db
|
|
28
|
+
#
|
|
29
|
+
# This will create a file named +config/initializers/multi_db.rb+ with the
|
|
30
|
+
# following contents:
|
|
31
|
+
#
|
|
32
|
+
# Rails.application.configure do
|
|
33
|
+
# config.active_record.database_selector = { delay: 2.seconds }
|
|
34
|
+
# config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
|
|
35
|
+
# config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
|
|
36
|
+
# end
|
|
28
37
|
#
|
|
29
|
-
#
|
|
38
|
+
# Alternatively you can set the options in your environment config or
|
|
39
|
+
# any other config file loaded on boot.
|
|
30
40
|
#
|
|
31
41
|
# The default behavior can be changed by setting the config options to a
|
|
32
42
|
# custom class:
|
|
@@ -34,6 +44,10 @@ module ActiveRecord
|
|
|
34
44
|
# config.active_record.database_selector = { delay: 2.seconds }
|
|
35
45
|
# config.active_record.database_resolver = MyResolver
|
|
36
46
|
# config.active_record.database_resolver_context = MyResolver::MySession
|
|
47
|
+
#
|
|
48
|
+
# Note: If you are using <tt>rails new my_app --minimal</tt> you will need
|
|
49
|
+
# to call <tt>require "active_support/core_ext/integer/time"</tt> to load
|
|
50
|
+
# the core extension in order to use +2.seconds+
|
|
37
51
|
class DatabaseSelector
|
|
38
52
|
def initialize(app, resolver_klass = nil, context_klass = nil, options = {})
|
|
39
53
|
@app = app
|
|
@@ -55,20 +69,18 @@ module ActiveRecord
|
|
|
55
69
|
end
|
|
56
70
|
|
|
57
71
|
private
|
|
58
|
-
|
|
59
72
|
def select_database(request, &blk)
|
|
60
73
|
context = context_klass.call(request)
|
|
61
74
|
resolver = resolver_klass.call(context, options)
|
|
62
75
|
|
|
63
|
-
if reading_request?(request)
|
|
76
|
+
response = if resolver.reading_request?(request)
|
|
64
77
|
resolver.read(&blk)
|
|
65
78
|
else
|
|
66
79
|
resolver.write(&blk)
|
|
67
80
|
end
|
|
68
|
-
end
|
|
69
81
|
|
|
70
|
-
|
|
71
|
-
|
|
82
|
+
resolver.update_context(response)
|
|
83
|
+
response
|
|
72
84
|
end
|
|
73
85
|
end
|
|
74
86
|
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ActiveRecord
|
|
4
|
+
module Middleware
|
|
5
|
+
# = Shard Selector \Middleware
|
|
6
|
+
#
|
|
7
|
+
# The ShardSelector Middleware provides a framework for automatically
|
|
8
|
+
# swapping shards. \Rails provides a basic framework to determine which
|
|
9
|
+
# shard to switch to and allows for applications to write custom strategies
|
|
10
|
+
# for swapping if needed.
|
|
11
|
+
#
|
|
12
|
+
# The ShardSelector takes a set of options (currently only +lock+ is supported)
|
|
13
|
+
# that can be used by the middleware to alter behavior. +lock+ is
|
|
14
|
+
# true by default and will prohibit the request from switching shards once
|
|
15
|
+
# inside the block. If +lock+ is false, then shard swapping will be allowed.
|
|
16
|
+
# For tenant based sharding, +lock+ should always be true to prevent application
|
|
17
|
+
# code from mistakenly switching between tenants.
|
|
18
|
+
#
|
|
19
|
+
# Options can be set in the config:
|
|
20
|
+
#
|
|
21
|
+
# config.active_record.shard_selector = { lock: true }
|
|
22
|
+
#
|
|
23
|
+
# Applications must also provide the code for the resolver as it depends on application
|
|
24
|
+
# specific models. An example resolver would look like this:
|
|
25
|
+
#
|
|
26
|
+
# config.active_record.shard_resolver = ->(request) {
|
|
27
|
+
# subdomain = request.subdomain
|
|
28
|
+
# tenant = Tenant.find_by_subdomain!(subdomain)
|
|
29
|
+
# tenant.shard
|
|
30
|
+
# }
|
|
31
|
+
class ShardSelector
|
|
32
|
+
def initialize(app, resolver, options = {})
|
|
33
|
+
@app = app
|
|
34
|
+
@resolver = resolver
|
|
35
|
+
@options = options
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
attr_reader :resolver, :options
|
|
39
|
+
|
|
40
|
+
def call(env)
|
|
41
|
+
request = ActionDispatch::Request.new(env)
|
|
42
|
+
|
|
43
|
+
shard = selected_shard(request)
|
|
44
|
+
|
|
45
|
+
set_shard(shard) do
|
|
46
|
+
@app.call(env)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
def selected_shard(request)
|
|
52
|
+
resolver.call(request)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def set_shard(shard, &block)
|
|
56
|
+
ActiveRecord::Base.connected_to(shard: shard.to_sym) do
|
|
57
|
+
ActiveRecord::Base.prohibit_shard_swapping(options.fetch(:lock, true), &block)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -2,43 +2,59 @@
|
|
|
2
2
|
|
|
3
3
|
module ActiveRecord
|
|
4
4
|
class Migration
|
|
5
|
-
#
|
|
5
|
+
# = \Migration Command Recorder
|
|
6
|
+
#
|
|
7
|
+
# +ActiveRecord::Migration::CommandRecorder+ records commands done during
|
|
6
8
|
# a migration and knows how to reverse those commands. The CommandRecorder
|
|
7
9
|
# knows how to invert the following commands:
|
|
8
10
|
#
|
|
9
11
|
# * add_column
|
|
10
12
|
# * add_foreign_key
|
|
13
|
+
# * add_check_constraint
|
|
14
|
+
# * add_exclusion_constraint
|
|
15
|
+
# * add_unique_constraint
|
|
11
16
|
# * add_index
|
|
12
17
|
# * add_reference
|
|
13
18
|
# * add_timestamps
|
|
14
|
-
# *
|
|
15
|
-
# * change_column_default (must supply a :from and :to option)
|
|
19
|
+
# * change_column_default (must supply a +:from+ and +:to+ option)
|
|
16
20
|
# * change_column_null
|
|
17
|
-
# * change_column_comment (must supply a
|
|
18
|
-
# * change_table_comment (must supply a
|
|
21
|
+
# * change_column_comment (must supply a +:from+ and +:to+ option)
|
|
22
|
+
# * change_table_comment (must supply a +:from+ and +:to+ option)
|
|
23
|
+
# * create_enum
|
|
19
24
|
# * create_join_table
|
|
20
25
|
# * create_table
|
|
21
26
|
# * disable_extension
|
|
27
|
+
# * drop_enum (must supply a list of values)
|
|
22
28
|
# * drop_join_table
|
|
23
29
|
# * drop_table (must supply a block)
|
|
24
30
|
# * enable_extension
|
|
25
31
|
# * remove_column (must supply a type)
|
|
26
|
-
# * remove_columns (must
|
|
32
|
+
# * remove_columns (must supply a +:type+ option)
|
|
27
33
|
# * remove_foreign_key (must supply a second table)
|
|
34
|
+
# * remove_check_constraint
|
|
35
|
+
# * remove_exclusion_constraint
|
|
36
|
+
# * remove_unique_constraint
|
|
28
37
|
# * remove_index
|
|
29
38
|
# * remove_reference
|
|
30
39
|
# * remove_timestamps
|
|
31
40
|
# * rename_column
|
|
41
|
+
# * rename_enum (must supply a +:to+ option)
|
|
42
|
+
# * rename_enum_value (must supply a +:from+ and +:to+ option)
|
|
32
43
|
# * rename_index
|
|
33
44
|
# * rename_table
|
|
34
45
|
class CommandRecorder
|
|
35
|
-
ReversibleAndIrreversibleMethods = [
|
|
46
|
+
ReversibleAndIrreversibleMethods = [
|
|
47
|
+
:create_table, :create_join_table, :rename_table, :add_column, :remove_column,
|
|
36
48
|
:rename_index, :rename_column, :add_index, :remove_index, :add_timestamps, :remove_timestamps,
|
|
37
49
|
:change_column_default, :add_reference, :remove_reference, :transaction,
|
|
38
50
|
:drop_join_table, :drop_table, :execute_block, :enable_extension, :disable_extension,
|
|
39
51
|
:change_column, :execute, :remove_columns, :change_column_null,
|
|
40
52
|
:add_foreign_key, :remove_foreign_key,
|
|
41
|
-
:change_column_comment, :change_table_comment
|
|
53
|
+
:change_column_comment, :change_table_comment,
|
|
54
|
+
:add_check_constraint, :remove_check_constraint,
|
|
55
|
+
:add_exclusion_constraint, :remove_exclusion_constraint,
|
|
56
|
+
:add_unique_constraint, :remove_unique_constraint,
|
|
57
|
+
:create_enum, :drop_enum, :rename_enum, :add_enum_value, :rename_enum_value,
|
|
42
58
|
]
|
|
43
59
|
include JoinTable
|
|
44
60
|
|
|
@@ -84,6 +100,11 @@ module ActiveRecord
|
|
|
84
100
|
# recorder.inverse_of(:rename_table, [:old, :new])
|
|
85
101
|
# # => [:rename_table, [:new, :old]]
|
|
86
102
|
#
|
|
103
|
+
# If the inverse of a command requires several commands, returns array of commands.
|
|
104
|
+
#
|
|
105
|
+
# recorder.inverse_of(:remove_columns, [:some_table, :foo, :bar, type: :string])
|
|
106
|
+
# # => [[:add_column, :some_table, :foo, :string], [:add_column, :some_table, :bar, :string]]
|
|
107
|
+
#
|
|
87
108
|
# This method will raise an +IrreversibleMigration+ exception if it cannot
|
|
88
109
|
# invert the +command+.
|
|
89
110
|
def inverse_of(command, args, &block)
|
|
@@ -103,12 +124,21 @@ module ActiveRecord
|
|
|
103
124
|
record(:"#{method}", args, &block) # record(:create_table, args, &block)
|
|
104
125
|
end # end
|
|
105
126
|
EOV
|
|
127
|
+
ruby2_keywords(method)
|
|
106
128
|
end
|
|
107
129
|
alias :add_belongs_to :add_reference
|
|
108
130
|
alias :remove_belongs_to :remove_reference
|
|
109
131
|
|
|
110
|
-
def change_table(table_name, options
|
|
111
|
-
|
|
132
|
+
def change_table(table_name, **options) # :nodoc:
|
|
133
|
+
if delegate.supports_bulk_alter? && options[:bulk]
|
|
134
|
+
recorder = self.class.new(self.delegate)
|
|
135
|
+
recorder.reverting = @reverting
|
|
136
|
+
yield recorder.delegate.update_table_definition(table_name, recorder)
|
|
137
|
+
commands = recorder.commands
|
|
138
|
+
@commands << [:change_table, [table_name], -> t { bulk_change_table(table_name, commands) }]
|
|
139
|
+
else
|
|
140
|
+
yield delegate.update_table_definition(table_name, self)
|
|
141
|
+
end
|
|
112
142
|
end
|
|
113
143
|
|
|
114
144
|
def replay(migration)
|
|
@@ -118,7 +148,6 @@ module ActiveRecord
|
|
|
118
148
|
end
|
|
119
149
|
|
|
120
150
|
private
|
|
121
|
-
|
|
122
151
|
module StraightReversions # :nodoc:
|
|
123
152
|
private
|
|
124
153
|
{
|
|
@@ -126,9 +155,15 @@ module ActiveRecord
|
|
|
126
155
|
create_table: :drop_table,
|
|
127
156
|
create_join_table: :drop_join_table,
|
|
128
157
|
add_column: :remove_column,
|
|
158
|
+
add_index: :remove_index,
|
|
129
159
|
add_timestamps: :remove_timestamps,
|
|
130
160
|
add_reference: :remove_reference,
|
|
131
|
-
|
|
161
|
+
add_foreign_key: :remove_foreign_key,
|
|
162
|
+
add_check_constraint: :remove_check_constraint,
|
|
163
|
+
add_exclusion_constraint: :remove_exclusion_constraint,
|
|
164
|
+
add_unique_constraint: :remove_unique_constraint,
|
|
165
|
+
enable_extension: :disable_extension,
|
|
166
|
+
create_enum: :drop_enum
|
|
132
167
|
}.each do |cmd, inv|
|
|
133
168
|
[[inv, cmd], [cmd, inv]].uniq.each do |method, inverse|
|
|
134
169
|
class_eval <<-EOV, __FILE__, __LINE__ + 1
|
|
@@ -142,9 +177,9 @@ module ActiveRecord
|
|
|
142
177
|
|
|
143
178
|
include StraightReversions
|
|
144
179
|
|
|
145
|
-
def invert_transaction(args)
|
|
180
|
+
def invert_transaction(args, &block)
|
|
146
181
|
sub_recorder = CommandRecorder.new(delegate)
|
|
147
|
-
sub_recorder.revert
|
|
182
|
+
sub_recorder.revert(&block)
|
|
148
183
|
|
|
149
184
|
invertions_proc = proc {
|
|
150
185
|
sub_recorder.replay(self)
|
|
@@ -153,7 +188,17 @@ module ActiveRecord
|
|
|
153
188
|
[:transaction, args, invertions_proc]
|
|
154
189
|
end
|
|
155
190
|
|
|
191
|
+
def invert_create_table(args, &block)
|
|
192
|
+
if args.last.is_a?(Hash)
|
|
193
|
+
args.last.delete(:if_not_exists)
|
|
194
|
+
end
|
|
195
|
+
super
|
|
196
|
+
end
|
|
197
|
+
|
|
156
198
|
def invert_drop_table(args, &block)
|
|
199
|
+
if args.last.is_a?(Hash)
|
|
200
|
+
args.last.delete(:if_exists)
|
|
201
|
+
end
|
|
157
202
|
if args.size == 1 && block == nil
|
|
158
203
|
raise ActiveRecord::IrreversibleMigration, "To avoid mistakes, drop_table is only reversible if given options or a block (can be empty)."
|
|
159
204
|
end
|
|
@@ -161,7 +206,10 @@ module ActiveRecord
|
|
|
161
206
|
end
|
|
162
207
|
|
|
163
208
|
def invert_rename_table(args)
|
|
164
|
-
|
|
209
|
+
old_name, new_name, options = args
|
|
210
|
+
args = [new_name, old_name]
|
|
211
|
+
args << options if options
|
|
212
|
+
[:rename_table, args]
|
|
165
213
|
end
|
|
166
214
|
|
|
167
215
|
def invert_remove_column(args)
|
|
@@ -169,44 +217,49 @@ module ActiveRecord
|
|
|
169
217
|
super
|
|
170
218
|
end
|
|
171
219
|
|
|
220
|
+
def invert_remove_columns(args)
|
|
221
|
+
unless args[-1].is_a?(Hash) && args[-1].has_key?(:type)
|
|
222
|
+
raise ActiveRecord::IrreversibleMigration, "remove_columns is only reversible if given a type."
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
[:add_columns, args]
|
|
226
|
+
end
|
|
227
|
+
|
|
172
228
|
def invert_rename_index(args)
|
|
173
|
-
|
|
229
|
+
table_name, old_name, new_name = args
|
|
230
|
+
[:rename_index, [table_name, new_name, old_name]]
|
|
174
231
|
end
|
|
175
232
|
|
|
176
233
|
def invert_rename_column(args)
|
|
177
|
-
|
|
234
|
+
table_name, old_name, new_name = args
|
|
235
|
+
[:rename_column, [table_name, new_name, old_name]]
|
|
178
236
|
end
|
|
179
237
|
|
|
180
|
-
def
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
options_hash = options.slice(:name, :algorithm)
|
|
185
|
-
options_hash[:column] = columns if !options_hash[:name]
|
|
238
|
+
def invert_remove_index(args)
|
|
239
|
+
options = args.extract_options!
|
|
240
|
+
table, columns = args
|
|
186
241
|
|
|
187
|
-
|
|
188
|
-
end
|
|
242
|
+
columns ||= options.delete(:column)
|
|
189
243
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
if (options = options_or_column).is_a?(Hash)
|
|
193
|
-
unless options[:column]
|
|
194
|
-
raise ActiveRecord::IrreversibleMigration, "remove_index is only reversible if given a :column option."
|
|
195
|
-
end
|
|
196
|
-
options = options.dup
|
|
197
|
-
[:add_index, [table, options.delete(:column), options]]
|
|
198
|
-
elsif (column = options_or_column).present?
|
|
199
|
-
[:add_index, [table, column]]
|
|
244
|
+
unless columns
|
|
245
|
+
raise ActiveRecord::IrreversibleMigration, "remove_index is only reversible if given a :column option."
|
|
200
246
|
end
|
|
247
|
+
|
|
248
|
+
options.delete(:if_exists)
|
|
249
|
+
|
|
250
|
+
args = [table, columns]
|
|
251
|
+
args << options unless options.empty?
|
|
252
|
+
|
|
253
|
+
[:add_index, args]
|
|
201
254
|
end
|
|
202
255
|
|
|
203
256
|
alias :invert_add_belongs_to :invert_add_reference
|
|
204
257
|
alias :invert_remove_belongs_to :invert_remove_reference
|
|
205
258
|
|
|
206
259
|
def invert_change_column_default(args)
|
|
207
|
-
table, column, options =
|
|
260
|
+
table, column, options = args
|
|
208
261
|
|
|
209
|
-
unless options
|
|
262
|
+
unless options.is_a?(Hash) && options.has_key?(:from) && options.has_key?(:to)
|
|
210
263
|
raise ActiveRecord::IrreversibleMigration, "change_column_default is only reversible if given a :from and :to option."
|
|
211
264
|
end
|
|
212
265
|
|
|
@@ -219,18 +272,8 @@ module ActiveRecord
|
|
|
219
272
|
end
|
|
220
273
|
|
|
221
274
|
def invert_add_foreign_key(args)
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
if add_options[:name]
|
|
226
|
-
options = { name: add_options[:name] }
|
|
227
|
-
elsif add_options[:column]
|
|
228
|
-
options = { column: add_options[:column] }
|
|
229
|
-
else
|
|
230
|
-
options = to_table
|
|
231
|
-
end
|
|
232
|
-
|
|
233
|
-
[:remove_foreign_key, [from_table, options]]
|
|
275
|
+
args.last.delete(:validate) if args.last.is_a?(Hash)
|
|
276
|
+
super
|
|
234
277
|
end
|
|
235
278
|
|
|
236
279
|
def invert_remove_foreign_key(args)
|
|
@@ -248,9 +291,9 @@ module ActiveRecord
|
|
|
248
291
|
end
|
|
249
292
|
|
|
250
293
|
def invert_change_column_comment(args)
|
|
251
|
-
table, column, options =
|
|
294
|
+
table, column, options = args
|
|
252
295
|
|
|
253
|
-
unless options
|
|
296
|
+
unless options.is_a?(Hash) && options.has_key?(:from) && options.has_key?(:to)
|
|
254
297
|
raise ActiveRecord::IrreversibleMigration, "change_column_comment is only reversible if given a :from and :to option."
|
|
255
298
|
end
|
|
256
299
|
|
|
@@ -258,23 +301,85 @@ module ActiveRecord
|
|
|
258
301
|
end
|
|
259
302
|
|
|
260
303
|
def invert_change_table_comment(args)
|
|
261
|
-
table, options =
|
|
304
|
+
table, options = args
|
|
262
305
|
|
|
263
|
-
unless options
|
|
306
|
+
unless options.is_a?(Hash) && options.has_key?(:from) && options.has_key?(:to)
|
|
264
307
|
raise ActiveRecord::IrreversibleMigration, "change_table_comment is only reversible if given a :from and :to option."
|
|
265
308
|
end
|
|
266
309
|
|
|
267
310
|
[:change_table_comment, [table, from: options[:to], to: options[:from]]]
|
|
268
311
|
end
|
|
269
312
|
|
|
313
|
+
def invert_add_check_constraint(args)
|
|
314
|
+
if (options = args.last).is_a?(Hash)
|
|
315
|
+
options.delete(:validate)
|
|
316
|
+
options[:if_exists] = options.delete(:if_not_exists) if options.key?(:if_not_exists)
|
|
317
|
+
end
|
|
318
|
+
super
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
def invert_remove_check_constraint(args)
|
|
322
|
+
raise ActiveRecord::IrreversibleMigration, "remove_check_constraint is only reversible if given an expression." if args.size < 2
|
|
323
|
+
|
|
324
|
+
if (options = args.last).is_a?(Hash)
|
|
325
|
+
options[:if_not_exists] = options.delete(:if_exists) if options.key?(:if_exists)
|
|
326
|
+
end
|
|
327
|
+
super
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
def invert_remove_exclusion_constraint(args)
|
|
331
|
+
raise ActiveRecord::IrreversibleMigration, "remove_exclusion_constraint is only reversible if given an expression." if args.size < 2
|
|
332
|
+
super
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
def invert_add_unique_constraint(args)
|
|
336
|
+
options = args.dup.extract_options!
|
|
337
|
+
|
|
338
|
+
raise ActiveRecord::IrreversibleMigration, "add_unique_constraint is not reversible if given an using_index." if options[:using_index]
|
|
339
|
+
super
|
|
340
|
+
end
|
|
341
|
+
|
|
342
|
+
def invert_remove_unique_constraint(args)
|
|
343
|
+
_table, columns = args.dup.tap(&:extract_options!)
|
|
344
|
+
|
|
345
|
+
raise ActiveRecord::IrreversibleMigration, "remove_unique_constraint is only reversible if given an column_name." if columns.blank?
|
|
346
|
+
super
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
def invert_drop_enum(args)
|
|
350
|
+
_enum, values = args.dup.tap(&:extract_options!)
|
|
351
|
+
raise ActiveRecord::IrreversibleMigration, "drop_enum is only reversible if given a list of enum values." unless values
|
|
352
|
+
super
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
def invert_rename_enum(args)
|
|
356
|
+
name, options = args
|
|
357
|
+
|
|
358
|
+
unless options.is_a?(Hash) && options.has_key?(:to)
|
|
359
|
+
raise ActiveRecord::IrreversibleMigration, "rename_enum is only reversible if given a :to option."
|
|
360
|
+
end
|
|
361
|
+
|
|
362
|
+
[:rename_enum, [options[:to], to: name]]
|
|
363
|
+
end
|
|
364
|
+
|
|
365
|
+
def invert_rename_enum_value(args)
|
|
366
|
+
type_name, options = args
|
|
367
|
+
|
|
368
|
+
unless options.is_a?(Hash) && options.has_key?(:from) && options.has_key?(:to)
|
|
369
|
+
raise ActiveRecord::IrreversibleMigration, "rename_enum_value is only reversible if given a :from and :to option."
|
|
370
|
+
end
|
|
371
|
+
|
|
372
|
+
[:rename_enum_value, [type_name, from: options[:to], to: options[:from]]]
|
|
373
|
+
end
|
|
374
|
+
|
|
270
375
|
def respond_to_missing?(method, _)
|
|
271
376
|
super || delegate.respond_to?(method)
|
|
272
377
|
end
|
|
273
378
|
|
|
274
379
|
# Forwards any missing method call to the \target.
|
|
275
|
-
def method_missing(method,
|
|
380
|
+
def method_missing(method, ...)
|
|
276
381
|
if delegate.respond_to?(method)
|
|
277
|
-
delegate.public_send(method,
|
|
382
|
+
delegate.public_send(method, ...)
|
|
278
383
|
else
|
|
279
384
|
super
|
|
280
385
|
end
|