activerecord 4.2.9 → 6.1.4.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activerecord might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/CHANGELOG.md +964 -1382
- data/MIT-LICENSE +4 -2
- data/README.rdoc +15 -14
- data/examples/performance.rb +33 -32
- data/examples/simple.rb +5 -4
- data/lib/active_record/aggregations.rb +266 -251
- data/lib/active_record/association_relation.rb +40 -15
- data/lib/active_record/associations/alias_tracker.rb +40 -43
- data/lib/active_record/associations/association.rb +162 -69
- data/lib/active_record/associations/association_scope.rb +105 -130
- data/lib/active_record/associations/belongs_to_association.rb +83 -65
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +13 -12
- data/lib/active_record/associations/builder/association.rb +57 -43
- data/lib/active_record/associations/builder/belongs_to.rb +74 -57
- data/lib/active_record/associations/builder/collection_association.rb +15 -37
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +49 -66
- data/lib/active_record/associations/builder/has_many.rb +13 -5
- data/lib/active_record/associations/builder/has_one.rb +44 -6
- data/lib/active_record/associations/builder/singular_association.rb +16 -10
- data/lib/active_record/associations/collection_association.rb +148 -287
- data/lib/active_record/associations/collection_proxy.rb +252 -150
- data/lib/active_record/associations/foreign_association.rb +23 -1
- data/lib/active_record/associations/has_many_association.rb +56 -98
- data/lib/active_record/associations/has_many_through_association.rb +68 -89
- data/lib/active_record/associations/has_one_association.rb +73 -47
- data/lib/active_record/associations/has_one_through_association.rb +20 -11
- data/lib/active_record/associations/join_dependency/join_association.rb +54 -81
- data/lib/active_record/associations/join_dependency/join_base.rb +10 -9
- data/lib/active_record/associations/join_dependency/join_part.rb +14 -14
- data/lib/active_record/associations/join_dependency.rb +174 -169
- data/lib/active_record/associations/preloader/association.rb +108 -115
- data/lib/active_record/associations/preloader/through_association.rb +85 -65
- data/lib/active_record/associations/preloader.rb +97 -94
- data/lib/active_record/associations/singular_association.rb +18 -39
- data/lib/active_record/associations/through_association.rb +39 -19
- data/lib/active_record/associations.rb +1845 -1598
- data/lib/active_record/attribute_assignment.rb +59 -185
- data/lib/active_record/attribute_methods/before_type_cast.rb +18 -10
- data/lib/active_record/attribute_methods/dirty.rb +168 -148
- data/lib/active_record/attribute_methods/primary_key.rb +93 -83
- data/lib/active_record/attribute_methods/query.rb +8 -10
- data/lib/active_record/attribute_methods/read.rb +19 -79
- data/lib/active_record/attribute_methods/serialization.rb +49 -24
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +55 -36
- data/lib/active_record/attribute_methods/write.rb +24 -55
- data/lib/active_record/attribute_methods.rb +149 -154
- data/lib/active_record/attributes.rb +234 -78
- data/lib/active_record/autosave_association.rb +133 -60
- data/lib/active_record/base.rb +46 -46
- data/lib/active_record/callbacks.rb +234 -79
- data/lib/active_record/coders/json.rb +3 -1
- data/lib/active_record/coders/yaml_column.rb +34 -13
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +887 -323
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +17 -41
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +292 -124
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +78 -24
- data/lib/active_record/connection_adapters/abstract/quoting.rb +177 -60
- data/lib/active_record/connection_adapters/abstract/savepoints.rb +8 -6
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +157 -93
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +473 -255
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +79 -36
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +869 -286
- data/lib/active_record/connection_adapters/abstract/transaction.rb +257 -91
- data/lib/active_record/connection_adapters/abstract_adapter.rb +483 -230
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +557 -640
- data/lib/active_record/connection_adapters/column.rb +67 -40
- data/lib/active_record/connection_adapters/deduplicable.rb +29 -0
- data/lib/active_record/connection_adapters/legacy_pool_manager.rb +35 -0
- data/lib/active_record/connection_adapters/mysql/column.rb +27 -0
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +194 -0
- data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +71 -0
- data/lib/active_record/connection_adapters/mysql/quoting.rb +96 -0
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +97 -0
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +103 -0
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +91 -0
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +268 -0
- data/lib/active_record/connection_adapters/mysql/type_metadata.rb +40 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +80 -192
- data/lib/active_record/connection_adapters/pool_config.rb +73 -0
- data/lib/active_record/connection_adapters/pool_manager.rb +47 -0
- data/lib/active_record/connection_adapters/postgresql/column.rb +44 -11
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +75 -160
- data/lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb +44 -0
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +49 -58
- data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +9 -8
- data/lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/bytea.rb +4 -2
- data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +8 -6
- data/lib/active_record/connection_adapters/postgresql/oid/date.rb +13 -1
- data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +14 -19
- data/lib/active_record/connection_adapters/postgresql/oid/decimal.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +5 -4
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +31 -20
- data/lib/active_record/connection_adapters/postgresql/oid/inet.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/interval.rb +49 -0
- data/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb +3 -11
- data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +44 -0
- data/lib/active_record/connection_adapters/postgresql/oid/macaddr.rb +25 -0
- data/lib/active_record/connection_adapters/postgresql/oid/money.rb +7 -9
- data/lib/active_record/connection_adapters/postgresql/oid/{infinity.rb → oid.rb} +5 -3
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +32 -11
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +70 -34
- data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +4 -5
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +58 -54
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +18 -4
- data/lib/active_record/connection_adapters/postgresql/oid/vector.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql/oid/xml.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql/oid.rb +25 -25
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +145 -48
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +27 -14
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +80 -0
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +178 -108
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +49 -0
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +496 -298
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +44 -0
- data/lib/active_record/connection_adapters/postgresql/utils.rb +11 -8
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +588 -375
- data/lib/active_record/connection_adapters/schema_cache.rb +167 -29
- data/lib/active_record/connection_adapters/sql_type_metadata.rb +45 -0
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +144 -0
- data/lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb +21 -0
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +102 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +21 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +19 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +18 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +170 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +322 -373
- data/lib/active_record/connection_adapters/statement_pool.rb +33 -13
- data/lib/active_record/connection_adapters.rb +52 -0
- data/lib/active_record/connection_handling.rb +314 -41
- data/lib/active_record/core.rb +458 -241
- data/lib/active_record/counter_cache.rb +70 -49
- 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 +87 -106
- data/lib/active_record/enum.rb +211 -92
- data/lib/active_record/errors.rb +224 -54
- data/lib/active_record/explain.rb +27 -11
- data/lib/active_record/explain_registry.rb +4 -2
- data/lib/active_record/explain_subscriber.rb +10 -5
- data/lib/active_record/fixture_set/file.rb +33 -14
- 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 +275 -500
- data/lib/active_record/gem_version.rb +6 -4
- data/lib/active_record/inheritance.rb +175 -110
- data/lib/active_record/insert_all.rb +212 -0
- data/lib/active_record/integration.rb +121 -29
- data/lib/active_record/internal_metadata.rb +62 -0
- data/lib/active_record/legacy_yaml_adapter.rb +27 -5
- data/lib/active_record/locale/en.yml +3 -2
- data/lib/active_record/locking/optimistic.rb +98 -92
- data/lib/active_record/locking/pessimistic.rb +22 -6
- data/lib/active_record/log_subscriber.rb +93 -31
- 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 +185 -90
- data/lib/active_record/migration/compatibility.rb +295 -0
- data/lib/active_record/migration/join_table.rb +8 -7
- data/lib/active_record/migration.rb +673 -325
- data/lib/active_record/model_schema.rb +418 -113
- data/lib/active_record/nested_attributes.rb +263 -224
- data/lib/active_record/no_touching.rb +15 -2
- data/lib/active_record/null_relation.rb +24 -38
- data/lib/active_record/persistence.rb +572 -136
- data/lib/active_record/query_cache.rb +29 -23
- data/lib/active_record/querying.rb +50 -31
- data/lib/active_record/railtie.rb +170 -51
- data/lib/active_record/railties/console_sandbox.rb +3 -3
- data/lib/active_record/railties/controller_runtime.rb +34 -33
- data/lib/active_record/railties/databases.rake +523 -199
- data/lib/active_record/readonly_attributes.rb +9 -4
- data/lib/active_record/reflection.rb +454 -291
- data/lib/active_record/relation/batches/batch_enumerator.rb +85 -0
- data/lib/active_record/relation/batches.rb +217 -59
- data/lib/active_record/relation/calculations.rb +324 -249
- data/lib/active_record/relation/delegation.rb +76 -84
- data/lib/active_record/relation/finder_methods.rb +316 -242
- data/lib/active_record/relation/from_clause.rb +30 -0
- data/lib/active_record/relation/merger.rb +95 -103
- data/lib/active_record/relation/predicate_builder/array_handler.rb +26 -26
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +42 -0
- data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +19 -0
- data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +57 -0
- data/lib/active_record/relation/predicate_builder/range_handler.rb +22 -0
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +7 -1
- data/lib/active_record/relation/predicate_builder.rb +136 -122
- data/lib/active_record/relation/query_attribute.rb +50 -0
- data/lib/active_record/relation/query_methods.rb +757 -413
- data/lib/active_record/relation/record_fetch_warning.rb +51 -0
- data/lib/active_record/relation/spawn_methods.rb +18 -20
- data/lib/active_record/relation/where_clause.rb +239 -0
- data/lib/active_record/relation.rb +554 -343
- data/lib/active_record/result.rb +91 -47
- data/lib/active_record/runtime_registry.rb +6 -4
- data/lib/active_record/sanitization.rb +134 -122
- data/lib/active_record/schema.rb +21 -24
- data/lib/active_record/schema_dumper.rb +141 -92
- data/lib/active_record/schema_migration.rb +24 -23
- data/lib/active_record/scoping/default.rb +96 -83
- data/lib/active_record/scoping/named.rb +78 -36
- data/lib/active_record/scoping.rb +45 -27
- data/lib/active_record/secure_token.rb +48 -0
- data/lib/active_record/serialization.rb +8 -6
- data/lib/active_record/signed_id.rb +116 -0
- data/lib/active_record/statement_cache.rb +89 -36
- data/lib/active_record/store.rb +128 -43
- data/lib/active_record/suppressor.rb +61 -0
- data/lib/active_record/table_metadata.rb +81 -0
- data/lib/active_record/tasks/database_tasks.rb +364 -130
- data/lib/active_record/tasks/mysql_database_tasks.rb +67 -113
- data/lib/active_record/tasks/postgresql_database_tasks.rb +86 -49
- data/lib/active_record/tasks/sqlite_database_tasks.rb +44 -19
- data/lib/active_record/test_databases.rb +24 -0
- data/lib/active_record/test_fixtures.rb +287 -0
- data/lib/active_record/timestamp.rb +86 -43
- data/lib/active_record/touch_later.rb +65 -0
- data/lib/active_record/transactions.rb +182 -163
- data/lib/active_record/translation.rb +3 -1
- data/lib/active_record/type/adapter_specific_registry.rb +126 -0
- data/lib/active_record/type/date.rb +4 -45
- data/lib/active_record/type/date_time.rb +4 -49
- data/lib/active_record/type/decimal_without_scale.rb +6 -2
- data/lib/active_record/type/hash_lookup_type_map.rb +5 -4
- data/lib/active_record/type/internal/timezone.rb +17 -0
- data/lib/active_record/type/json.rb +30 -0
- data/lib/active_record/type/serialized.rb +27 -15
- data/lib/active_record/type/text.rb +2 -2
- data/lib/active_record/type/time.rb +21 -16
- data/lib/active_record/type/type_map.rb +16 -19
- data/lib/active_record/type/unsigned_integer.rb +9 -8
- data/lib/active_record/type.rb +84 -23
- data/lib/active_record/type_caster/connection.rb +33 -0
- data/lib/active_record/type_caster/map.rb +23 -0
- data/lib/active_record/type_caster.rb +9 -0
- data/lib/active_record/validations/absence.rb +25 -0
- data/lib/active_record/validations/associated.rb +12 -4
- data/lib/active_record/validations/length.rb +26 -0
- data/lib/active_record/validations/numericality.rb +35 -0
- data/lib/active_record/validations/presence.rb +14 -13
- data/lib/active_record/validations/uniqueness.rb +63 -56
- data/lib/active_record/validations.rb +39 -35
- data/lib/active_record/version.rb +3 -1
- data/lib/active_record.rb +42 -29
- 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 +76 -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 +26 -0
- data/lib/rails/generators/active_record/application_record/templates/application_record.rb.tt +5 -0
- data/lib/rails/generators/active_record/migration/migration_generator.rb +43 -37
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +26 -0
- data/lib/rails/generators/active_record/migration/templates/{migration.rb → migration.rb.tt} +13 -4
- data/lib/rails/generators/active_record/migration.rb +35 -1
- data/lib/rails/generators/active_record/model/model_generator.rb +55 -22
- 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 +22 -0
- data/lib/rails/generators/active_record/model/templates/{module.rb → module.rb.tt} +0 -0
- data/lib/rails/generators/active_record.rb +7 -5
- metadata +172 -65
- data/lib/active_record/associations/preloader/belongs_to.rb +0 -17
- data/lib/active_record/associations/preloader/collection_association.rb +0 -24
- data/lib/active_record/associations/preloader/has_many.rb +0 -17
- data/lib/active_record/associations/preloader/has_many_through.rb +0 -19
- data/lib/active_record/associations/preloader/has_one.rb +0 -23
- data/lib/active_record/associations/preloader/has_one_through.rb +0 -9
- data/lib/active_record/associations/preloader/singular_association.rb +0 -21
- data/lib/active_record/attribute.rb +0 -163
- data/lib/active_record/attribute_decorators.rb +0 -66
- data/lib/active_record/attribute_set/builder.rb +0 -106
- data/lib/active_record/attribute_set.rb +0 -81
- data/lib/active_record/connection_adapters/connection_specification.rb +0 -275
- data/lib/active_record/connection_adapters/mysql_adapter.rb +0 -491
- data/lib/active_record/connection_adapters/postgresql/array_parser.rb +0 -93
- data/lib/active_record/connection_adapters/postgresql/oid/float.rb +0 -21
- data/lib/active_record/connection_adapters/postgresql/oid/integer.rb +0 -11
- data/lib/active_record/connection_adapters/postgresql/oid/json.rb +0 -35
- data/lib/active_record/connection_adapters/postgresql/oid/time.rb +0 -11
- data/lib/active_record/railties/jdbcmysql_error.rb +0 -16
- data/lib/active_record/serializers/xml_serializer.rb +0 -193
- data/lib/active_record/type/big_integer.rb +0 -13
- data/lib/active_record/type/binary.rb +0 -50
- data/lib/active_record/type/boolean.rb +0 -31
- data/lib/active_record/type/decimal.rb +0 -64
- data/lib/active_record/type/decorator.rb +0 -14
- data/lib/active_record/type/float.rb +0 -19
- data/lib/active_record/type/integer.rb +0 -59
- data/lib/active_record/type/mutable.rb +0 -16
- data/lib/active_record/type/numeric.rb +0 -36
- data/lib/active_record/type/string.rb +0 -40
- data/lib/active_record/type/time_value.rb +0 -38
- data/lib/active_record/type/value.rb +0 -110
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb +0 -19
- data/lib/rails/generators/active_record/model/templates/model.rb +0 -10
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
class Migration
|
3
5
|
# <tt>ActiveRecord::Migration::CommandRecorder</tt> records commands done during
|
@@ -5,15 +7,43 @@ module ActiveRecord
|
|
5
7
|
# knows how to invert the following commands:
|
6
8
|
#
|
7
9
|
# * add_column
|
10
|
+
# * add_foreign_key
|
11
|
+
# * add_check_constraint
|
8
12
|
# * add_index
|
13
|
+
# * add_reference
|
9
14
|
# * add_timestamps
|
10
|
-
# *
|
15
|
+
# * change_column
|
16
|
+
# * change_column_default (must supply a :from and :to option)
|
17
|
+
# * change_column_null
|
18
|
+
# * change_column_comment (must supply a :from and :to option)
|
19
|
+
# * change_table_comment (must supply a :from and :to option)
|
11
20
|
# * create_join_table
|
21
|
+
# * create_table
|
22
|
+
# * disable_extension
|
23
|
+
# * drop_join_table
|
24
|
+
# * drop_table (must supply a block)
|
25
|
+
# * enable_extension
|
26
|
+
# * remove_column (must supply a type)
|
27
|
+
# * remove_columns (must specify at least one column name or more)
|
28
|
+
# * remove_foreign_key (must supply a second table)
|
29
|
+
# * remove_check_constraint
|
30
|
+
# * remove_index
|
31
|
+
# * remove_reference
|
12
32
|
# * remove_timestamps
|
13
33
|
# * rename_column
|
14
34
|
# * rename_index
|
15
35
|
# * rename_table
|
16
36
|
class CommandRecorder
|
37
|
+
ReversibleAndIrreversibleMethods = [
|
38
|
+
:create_table, :create_join_table, :rename_table, :add_column, :remove_column,
|
39
|
+
:rename_index, :rename_column, :add_index, :remove_index, :add_timestamps, :remove_timestamps,
|
40
|
+
:change_column_default, :add_reference, :remove_reference, :transaction,
|
41
|
+
:drop_join_table, :drop_table, :execute_block, :enable_extension, :disable_extension,
|
42
|
+
:change_column, :execute, :remove_columns, :change_column_null,
|
43
|
+
:add_foreign_key, :remove_foreign_key,
|
44
|
+
:change_column_comment, :change_table_comment,
|
45
|
+
:add_check_constraint, :remove_check_constraint
|
46
|
+
]
|
17
47
|
include JoinTable
|
18
48
|
|
19
49
|
attr_accessor :commands, :delegate, :reverting
|
@@ -41,7 +71,7 @@ module ActiveRecord
|
|
41
71
|
@reverting = !@reverting
|
42
72
|
end
|
43
73
|
|
44
|
-
#
|
74
|
+
# Record +command+. +command+ should be a method name and arguments.
|
45
75
|
# For example:
|
46
76
|
#
|
47
77
|
# recorder.record(:method_name, [:arg1, :arg2])
|
@@ -58,140 +88,205 @@ module ActiveRecord
|
|
58
88
|
# recorder.inverse_of(:rename_table, [:old, :new])
|
59
89
|
# # => [:rename_table, [:new, :old]]
|
60
90
|
#
|
91
|
+
# If the inverse of a command requires several commands, returns array of commands.
|
92
|
+
#
|
93
|
+
# recorder.inverse_of(:remove_columns, [:some_table, :foo, :bar, type: :string])
|
94
|
+
# # => [[:add_column, :some_table, :foo, :string], [:add_column, :some_table, :bar, :string]]
|
95
|
+
#
|
61
96
|
# This method will raise an +IrreversibleMigration+ exception if it cannot
|
62
97
|
# invert the +command+.
|
63
98
|
def inverse_of(command, args, &block)
|
64
99
|
method = :"invert_#{command}"
|
65
|
-
raise IrreversibleMigration unless respond_to?(method, true)
|
100
|
+
raise IrreversibleMigration, <<~MSG unless respond_to?(method, true)
|
101
|
+
This migration uses #{command}, which is not automatically reversible.
|
102
|
+
To make the migration reversible you can either:
|
103
|
+
1. Define #up and #down methods in place of the #change method.
|
104
|
+
2. Use the #reversible method to define reversible behavior.
|
105
|
+
MSG
|
66
106
|
send(method, args, &block)
|
67
107
|
end
|
68
108
|
|
69
|
-
|
70
|
-
super || delegate.respond_to?(*args)
|
71
|
-
end
|
72
|
-
|
73
|
-
[:create_table, :create_join_table, :rename_table, :add_column, :remove_column,
|
74
|
-
:rename_index, :rename_column, :add_index, :remove_index, :add_timestamps, :remove_timestamps,
|
75
|
-
:change_column_default, :add_reference, :remove_reference, :transaction,
|
76
|
-
:drop_join_table, :drop_table, :execute_block, :enable_extension,
|
77
|
-
:change_column, :execute, :remove_columns, :change_column_null,
|
78
|
-
:add_foreign_key, :remove_foreign_key
|
79
|
-
# irreversible methods need to be here too
|
80
|
-
].each do |method|
|
109
|
+
ReversibleAndIrreversibleMethods.each do |method|
|
81
110
|
class_eval <<-EOV, __FILE__, __LINE__ + 1
|
82
111
|
def #{method}(*args, &block) # def create_table(*args, &block)
|
83
112
|
record(:"#{method}", args, &block) # record(:create_table, args, &block)
|
84
113
|
end # end
|
85
114
|
EOV
|
115
|
+
ruby2_keywords(method) if respond_to?(:ruby2_keywords, true)
|
86
116
|
end
|
87
117
|
alias :add_belongs_to :add_reference
|
88
118
|
alias :remove_belongs_to :remove_reference
|
89
119
|
|
90
|
-
def change_table(table_name, options
|
120
|
+
def change_table(table_name, **options) # :nodoc:
|
91
121
|
yield delegate.update_table_definition(table_name, self)
|
92
122
|
end
|
93
123
|
|
124
|
+
def replay(migration)
|
125
|
+
commands.each do |cmd, args, block|
|
126
|
+
migration.send(cmd, *args, &block)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
94
130
|
private
|
131
|
+
module StraightReversions # :nodoc:
|
132
|
+
private
|
133
|
+
{
|
134
|
+
execute_block: :execute_block,
|
135
|
+
create_table: :drop_table,
|
136
|
+
create_join_table: :drop_join_table,
|
137
|
+
add_column: :remove_column,
|
138
|
+
add_index: :remove_index,
|
139
|
+
add_timestamps: :remove_timestamps,
|
140
|
+
add_reference: :remove_reference,
|
141
|
+
add_foreign_key: :remove_foreign_key,
|
142
|
+
add_check_constraint: :remove_check_constraint,
|
143
|
+
enable_extension: :disable_extension
|
144
|
+
}.each do |cmd, inv|
|
145
|
+
[[inv, cmd], [cmd, inv]].uniq.each do |method, inverse|
|
146
|
+
class_eval <<-EOV, __FILE__, __LINE__ + 1
|
147
|
+
def invert_#{method}(args, &block) # def invert_create_table(args, &block)
|
148
|
+
[:#{inverse}, args, block] # [:drop_table, args, block]
|
149
|
+
end # end
|
150
|
+
EOV
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
95
154
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
EOV
|
155
|
+
include StraightReversions
|
156
|
+
|
157
|
+
def invert_transaction(args)
|
158
|
+
sub_recorder = CommandRecorder.new(delegate)
|
159
|
+
sub_recorder.revert { yield }
|
160
|
+
|
161
|
+
invertions_proc = proc {
|
162
|
+
sub_recorder.replay(self)
|
163
|
+
}
|
164
|
+
|
165
|
+
[:transaction, args, invertions_proc]
|
166
|
+
end
|
167
|
+
|
168
|
+
def invert_drop_table(args, &block)
|
169
|
+
if args.size == 1 && block == nil
|
170
|
+
raise ActiveRecord::IrreversibleMigration, "To avoid mistakes, drop_table is only reversible if given options or a block (can be empty)."
|
113
171
|
end
|
172
|
+
super
|
114
173
|
end
|
115
|
-
end
|
116
174
|
|
117
|
-
|
175
|
+
def invert_rename_table(args)
|
176
|
+
[:rename_table, args.reverse]
|
177
|
+
end
|
118
178
|
|
119
|
-
|
120
|
-
|
121
|
-
|
179
|
+
def invert_remove_column(args)
|
180
|
+
raise ActiveRecord::IrreversibleMigration, "remove_column is only reversible if given a type." if args.size <= 2
|
181
|
+
super
|
122
182
|
end
|
123
|
-
super
|
124
|
-
end
|
125
183
|
|
126
|
-
|
127
|
-
|
128
|
-
|
184
|
+
def invert_remove_columns(args)
|
185
|
+
unless args[-1].is_a?(Hash) && args[-1].has_key?(:type)
|
186
|
+
raise ActiveRecord::IrreversibleMigration, "remove_columns is only reversible if given a type."
|
187
|
+
end
|
129
188
|
|
130
|
-
|
131
|
-
|
132
|
-
super
|
133
|
-
end
|
189
|
+
[:add_columns, args]
|
190
|
+
end
|
134
191
|
|
135
|
-
|
136
|
-
|
137
|
-
|
192
|
+
def invert_rename_index(args)
|
193
|
+
table_name, old_name, new_name = args
|
194
|
+
[:rename_index, [table_name, new_name, old_name]]
|
195
|
+
end
|
138
196
|
|
139
|
-
|
140
|
-
|
141
|
-
|
197
|
+
def invert_rename_column(args)
|
198
|
+
table_name, old_name, new_name = args
|
199
|
+
[:rename_column, [table_name, new_name, old_name]]
|
200
|
+
end
|
142
201
|
|
143
|
-
|
144
|
-
|
145
|
-
|
202
|
+
def invert_remove_index(args)
|
203
|
+
options = args.extract_options!
|
204
|
+
table, columns = args
|
146
205
|
|
147
|
-
|
148
|
-
options_hash = index_name ? { name: index_name } : { column: columns }
|
206
|
+
columns ||= options.delete(:column)
|
149
207
|
|
150
|
-
|
151
|
-
|
208
|
+
unless columns
|
209
|
+
raise ActiveRecord::IrreversibleMigration, "remove_index is only reversible if given a :column option."
|
210
|
+
end
|
211
|
+
|
212
|
+
options.delete(:if_exists)
|
152
213
|
|
153
|
-
|
154
|
-
|
214
|
+
args = [table, columns]
|
215
|
+
args << options unless options.empty?
|
155
216
|
|
156
|
-
|
157
|
-
raise ActiveRecord::IrreversibleMigration, "remove_index is only reversible if given a :column option."
|
217
|
+
[:add_index, args]
|
158
218
|
end
|
159
219
|
|
160
|
-
|
161
|
-
|
162
|
-
end
|
220
|
+
alias :invert_add_belongs_to :invert_add_reference
|
221
|
+
alias :invert_remove_belongs_to :invert_remove_reference
|
163
222
|
|
164
|
-
|
165
|
-
|
223
|
+
def invert_change_column_default(args)
|
224
|
+
table, column, options = args
|
166
225
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
end
|
226
|
+
unless options.is_a?(Hash) && options.has_key?(:from) && options.has_key?(:to)
|
227
|
+
raise ActiveRecord::IrreversibleMigration, "change_column_default is only reversible if given a :from and :to option."
|
228
|
+
end
|
171
229
|
|
172
|
-
|
173
|
-
|
174
|
-
add_options ||= {}
|
230
|
+
[:change_column_default, [table, column, from: options[:to], to: options[:from]]]
|
231
|
+
end
|
175
232
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
options = { column: add_options[:column] }
|
180
|
-
else
|
181
|
-
options = to_table
|
233
|
+
def invert_change_column_null(args)
|
234
|
+
args[2] = !args[2]
|
235
|
+
[:change_column_null, args]
|
182
236
|
end
|
183
237
|
|
184
|
-
|
185
|
-
|
238
|
+
def invert_remove_foreign_key(args)
|
239
|
+
options = args.extract_options!
|
240
|
+
from_table, to_table = args
|
186
241
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
242
|
+
to_table ||= options.delete(:to_table)
|
243
|
+
|
244
|
+
raise ActiveRecord::IrreversibleMigration, "remove_foreign_key is only reversible if given a second table" if to_table.nil?
|
245
|
+
|
246
|
+
reversed_args = [from_table, to_table]
|
247
|
+
reversed_args << options unless options.empty?
|
248
|
+
|
249
|
+
[:add_foreign_key, reversed_args]
|
250
|
+
end
|
251
|
+
|
252
|
+
def invert_change_column_comment(args)
|
253
|
+
table, column, options = args
|
254
|
+
|
255
|
+
unless options.is_a?(Hash) && options.has_key?(:from) && options.has_key?(:to)
|
256
|
+
raise ActiveRecord::IrreversibleMigration, "change_column_comment is only reversible if given a :from and :to option."
|
257
|
+
end
|
258
|
+
|
259
|
+
[:change_column_comment, [table, column, from: options[:to], to: options[:from]]]
|
260
|
+
end
|
261
|
+
|
262
|
+
def invert_change_table_comment(args)
|
263
|
+
table, options = args
|
264
|
+
|
265
|
+
unless options.is_a?(Hash) && options.has_key?(:from) && options.has_key?(:to)
|
266
|
+
raise ActiveRecord::IrreversibleMigration, "change_table_comment is only reversible if given a :from and :to option."
|
267
|
+
end
|
268
|
+
|
269
|
+
[:change_table_comment, [table, from: options[:to], to: options[:from]]]
|
270
|
+
end
|
271
|
+
|
272
|
+
def invert_remove_check_constraint(args)
|
273
|
+
raise ActiveRecord::IrreversibleMigration, "remove_check_constraint is only reversible if given an expression." if args.size < 2
|
192
274
|
super
|
193
275
|
end
|
194
|
-
|
276
|
+
|
277
|
+
def respond_to_missing?(method, _)
|
278
|
+
super || delegate.respond_to?(method)
|
279
|
+
end
|
280
|
+
|
281
|
+
# Forwards any missing method call to the \target.
|
282
|
+
def method_missing(method, *args, &block)
|
283
|
+
if delegate.respond_to?(method)
|
284
|
+
delegate.public_send(method, *args, &block)
|
285
|
+
else
|
286
|
+
super
|
287
|
+
end
|
288
|
+
end
|
289
|
+
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
|
195
290
|
end
|
196
291
|
end
|
197
292
|
end
|
@@ -0,0 +1,295 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
class Migration
|
5
|
+
module Compatibility # :nodoc: all
|
6
|
+
def self.find(version)
|
7
|
+
version = version.to_s
|
8
|
+
name = "V#{version.tr('.', '_')}"
|
9
|
+
unless const_defined?(name)
|
10
|
+
versions = constants.grep(/\AV[0-9_]+\z/).map { |s| s.to_s.delete("V").tr("_", ".").inspect }
|
11
|
+
raise ArgumentError, "Unknown migration version #{version.inspect}; expected one of #{versions.sort.join(', ')}"
|
12
|
+
end
|
13
|
+
const_get(name)
|
14
|
+
end
|
15
|
+
|
16
|
+
V6_1 = Current
|
17
|
+
|
18
|
+
class V6_0 < V6_1
|
19
|
+
class ReferenceDefinition < ConnectionAdapters::ReferenceDefinition
|
20
|
+
def index_options(table_name)
|
21
|
+
as_options(index)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module TableDefinition
|
26
|
+
def references(*args, **options)
|
27
|
+
args.each do |ref_name|
|
28
|
+
ReferenceDefinition.new(ref_name, **options).add_to(self)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
alias :belongs_to :references
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_table(table_name, **options)
|
35
|
+
if block_given?
|
36
|
+
super { |t| yield compatible_table_definition(t) }
|
37
|
+
else
|
38
|
+
super
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def change_table(table_name, **options)
|
43
|
+
if block_given?
|
44
|
+
super { |t| yield compatible_table_definition(t) }
|
45
|
+
else
|
46
|
+
super
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def create_join_table(table_1, table_2, **options)
|
51
|
+
if block_given?
|
52
|
+
super { |t| yield compatible_table_definition(t) }
|
53
|
+
else
|
54
|
+
super
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def add_reference(table_name, ref_name, **options)
|
59
|
+
ReferenceDefinition.new(ref_name, **options)
|
60
|
+
.add_to(connection.update_table_definition(table_name, self))
|
61
|
+
end
|
62
|
+
alias :add_belongs_to :add_reference
|
63
|
+
|
64
|
+
private
|
65
|
+
def compatible_table_definition(t)
|
66
|
+
class << t
|
67
|
+
prepend TableDefinition
|
68
|
+
end
|
69
|
+
t
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class V5_2 < V6_0
|
74
|
+
module TableDefinition
|
75
|
+
def timestamps(**options)
|
76
|
+
options[:precision] ||= nil
|
77
|
+
super
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
module CommandRecorder
|
82
|
+
def invert_transaction(args, &block)
|
83
|
+
[:transaction, args, block]
|
84
|
+
end
|
85
|
+
|
86
|
+
def invert_change_column_comment(args)
|
87
|
+
[:change_column_comment, args]
|
88
|
+
end
|
89
|
+
|
90
|
+
def invert_change_table_comment(args)
|
91
|
+
[:change_table_comment, args]
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def create_table(table_name, **options)
|
96
|
+
if block_given?
|
97
|
+
super { |t| yield compatible_table_definition(t) }
|
98
|
+
else
|
99
|
+
super
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def change_table(table_name, **options)
|
104
|
+
if block_given?
|
105
|
+
super { |t| yield compatible_table_definition(t) }
|
106
|
+
else
|
107
|
+
super
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def create_join_table(table_1, table_2, **options)
|
112
|
+
if block_given?
|
113
|
+
super { |t| yield compatible_table_definition(t) }
|
114
|
+
else
|
115
|
+
super
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def add_timestamps(table_name, **options)
|
120
|
+
options[:precision] ||= nil
|
121
|
+
super
|
122
|
+
end
|
123
|
+
|
124
|
+
private
|
125
|
+
def compatible_table_definition(t)
|
126
|
+
class << t
|
127
|
+
prepend TableDefinition
|
128
|
+
end
|
129
|
+
t
|
130
|
+
end
|
131
|
+
|
132
|
+
def command_recorder
|
133
|
+
recorder = super
|
134
|
+
class << recorder
|
135
|
+
prepend CommandRecorder
|
136
|
+
end
|
137
|
+
recorder
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
class V5_1 < V5_2
|
142
|
+
def change_column(table_name, column_name, type, **options)
|
143
|
+
if connection.adapter_name == "PostgreSQL"
|
144
|
+
super(table_name, column_name, type, **options.except(:default, :null, :comment))
|
145
|
+
connection.change_column_default(table_name, column_name, options[:default]) if options.key?(:default)
|
146
|
+
connection.change_column_null(table_name, column_name, options[:null], options[:default]) if options.key?(:null)
|
147
|
+
connection.change_column_comment(table_name, column_name, options[:comment]) if options.key?(:comment)
|
148
|
+
else
|
149
|
+
super
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def create_table(table_name, **options)
|
154
|
+
if connection.adapter_name == "Mysql2"
|
155
|
+
super(table_name, options: "ENGINE=InnoDB", **options)
|
156
|
+
else
|
157
|
+
super
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
class V5_0 < V5_1
|
163
|
+
module TableDefinition
|
164
|
+
def primary_key(name, type = :primary_key, **options)
|
165
|
+
type = :integer if type == :primary_key
|
166
|
+
super
|
167
|
+
end
|
168
|
+
|
169
|
+
def references(*args, **options)
|
170
|
+
super(*args, type: :integer, **options)
|
171
|
+
end
|
172
|
+
alias :belongs_to :references
|
173
|
+
end
|
174
|
+
|
175
|
+
def create_table(table_name, **options)
|
176
|
+
if connection.adapter_name == "PostgreSQL"
|
177
|
+
if options[:id] == :uuid && !options.key?(:default)
|
178
|
+
options[:default] = "uuid_generate_v4()"
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
unless connection.adapter_name == "Mysql2" && options[:id] == :bigint
|
183
|
+
if [:integer, :bigint].include?(options[:id]) && !options.key?(:default)
|
184
|
+
options[:default] = nil
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
# Since 5.1 PostgreSQL adapter uses bigserial type for primary
|
189
|
+
# keys by default and MySQL uses bigint. This compat layer makes old migrations utilize
|
190
|
+
# serial/int type instead -- the way it used to work before 5.1.
|
191
|
+
unless options.key?(:id)
|
192
|
+
options[:id] = :integer
|
193
|
+
end
|
194
|
+
|
195
|
+
super
|
196
|
+
end
|
197
|
+
|
198
|
+
def create_join_table(table_1, table_2, column_options: {}, **options)
|
199
|
+
column_options.reverse_merge!(type: :integer)
|
200
|
+
super
|
201
|
+
end
|
202
|
+
|
203
|
+
def add_column(table_name, column_name, type, **options)
|
204
|
+
if type == :primary_key
|
205
|
+
type = :integer
|
206
|
+
options[:primary_key] = true
|
207
|
+
end
|
208
|
+
super
|
209
|
+
end
|
210
|
+
|
211
|
+
def add_reference(table_name, ref_name, **options)
|
212
|
+
super(table_name, ref_name, type: :integer, **options)
|
213
|
+
end
|
214
|
+
alias :add_belongs_to :add_reference
|
215
|
+
|
216
|
+
private
|
217
|
+
def compatible_table_definition(t)
|
218
|
+
class << t
|
219
|
+
prepend TableDefinition
|
220
|
+
end
|
221
|
+
super
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
class V4_2 < V5_0
|
226
|
+
module TableDefinition
|
227
|
+
def references(*, **options)
|
228
|
+
options[:index] ||= false
|
229
|
+
super
|
230
|
+
end
|
231
|
+
alias :belongs_to :references
|
232
|
+
|
233
|
+
def timestamps(**options)
|
234
|
+
options[:null] = true if options[:null].nil?
|
235
|
+
super
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
def add_reference(table_name, ref_name, **options)
|
240
|
+
options[:index] ||= false
|
241
|
+
super
|
242
|
+
end
|
243
|
+
alias :add_belongs_to :add_reference
|
244
|
+
|
245
|
+
def add_timestamps(table_name, **options)
|
246
|
+
options[:null] = true if options[:null].nil?
|
247
|
+
super
|
248
|
+
end
|
249
|
+
|
250
|
+
def index_exists?(table_name, column_name, **options)
|
251
|
+
column_names = Array(column_name).map(&:to_s)
|
252
|
+
options[:name] =
|
253
|
+
if options[:name].present?
|
254
|
+
options[:name].to_s
|
255
|
+
else
|
256
|
+
connection.index_name(table_name, column: column_names)
|
257
|
+
end
|
258
|
+
super
|
259
|
+
end
|
260
|
+
|
261
|
+
def remove_index(table_name, column_name = nil, **options)
|
262
|
+
options[:name] = index_name_for_remove(table_name, column_name, options)
|
263
|
+
super
|
264
|
+
end
|
265
|
+
|
266
|
+
private
|
267
|
+
def compatible_table_definition(t)
|
268
|
+
class << t
|
269
|
+
prepend TableDefinition
|
270
|
+
end
|
271
|
+
super
|
272
|
+
end
|
273
|
+
|
274
|
+
def index_name_for_remove(table_name, column_name, options)
|
275
|
+
index_name = connection.index_name(table_name, column_name || options)
|
276
|
+
|
277
|
+
unless connection.index_name_exists?(table_name, index_name)
|
278
|
+
if options.key?(:name)
|
279
|
+
options_without_column = options.except(:column)
|
280
|
+
index_name_without_column = connection.index_name(table_name, options_without_column)
|
281
|
+
|
282
|
+
if connection.index_name_exists?(table_name, index_name_without_column)
|
283
|
+
return index_name_without_column
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' does not exist"
|
288
|
+
end
|
289
|
+
|
290
|
+
index_name
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end
|
@@ -1,15 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
class Migration
|
3
5
|
module JoinTable #:nodoc:
|
4
6
|
private
|
7
|
+
def find_join_table_name(table_1, table_2, options = {})
|
8
|
+
options.delete(:table_name) || join_table_name(table_1, table_2)
|
9
|
+
end
|
5
10
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
def join_table_name(table_1, table_2)
|
11
|
-
ModelSchema.derive_join_table_name(table_1, table_2).to_sym
|
12
|
-
end
|
11
|
+
def join_table_name(table_1, table_2)
|
12
|
+
ModelSchema.derive_join_table_name(table_1, table_2).to_sym
|
13
|
+
end
|
13
14
|
end
|
14
15
|
end
|
15
16
|
end
|