activerecord 5.0.7.2 → 6.1.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activerecord might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +829 -2015
- data/MIT-LICENSE +3 -1
- data/README.rdoc +11 -9
- data/examples/performance.rb +31 -29
- data/examples/simple.rb +5 -3
- data/lib/active_record.rb +37 -29
- data/lib/active_record/aggregations.rb +249 -247
- data/lib/active_record/association_relation.rb +30 -18
- data/lib/active_record/associations.rb +1714 -1596
- data/lib/active_record/associations/alias_tracker.rb +36 -42
- data/lib/active_record/associations/association.rb +143 -68
- data/lib/active_record/associations/association_scope.rb +98 -94
- data/lib/active_record/associations/belongs_to_association.rb +76 -46
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +13 -12
- data/lib/active_record/associations/builder/association.rb +27 -28
- data/lib/active_record/associations/builder/belongs_to.rb +52 -60
- data/lib/active_record/associations/builder/collection_association.rb +12 -22
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +40 -62
- data/lib/active_record/associations/builder/has_many.rb +10 -2
- data/lib/active_record/associations/builder/has_one.rb +35 -2
- data/lib/active_record/associations/builder/singular_association.rb +5 -1
- data/lib/active_record/associations/collection_association.rb +104 -259
- data/lib/active_record/associations/collection_proxy.rb +169 -125
- data/lib/active_record/associations/foreign_association.rb +22 -0
- data/lib/active_record/associations/has_many_association.rb +46 -31
- data/lib/active_record/associations/has_many_through_association.rb +66 -46
- data/lib/active_record/associations/has_one_association.rb +71 -52
- data/lib/active_record/associations/has_one_through_association.rb +20 -11
- data/lib/active_record/associations/join_dependency.rb +169 -180
- data/lib/active_record/associations/join_dependency/join_association.rb +53 -79
- 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/preloader.rb +97 -104
- data/lib/active_record/associations/preloader/association.rb +109 -97
- data/lib/active_record/associations/preloader/through_association.rb +77 -76
- data/lib/active_record/associations/singular_association.rb +12 -45
- data/lib/active_record/associations/through_association.rb +27 -15
- data/lib/active_record/attribute_assignment.rb +55 -60
- data/lib/active_record/attribute_methods.rb +111 -141
- data/lib/active_record/attribute_methods/before_type_cast.rb +17 -9
- data/lib/active_record/attribute_methods/dirty.rb +172 -112
- data/lib/active_record/attribute_methods/primary_key.rb +88 -91
- data/lib/active_record/attribute_methods/query.rb +6 -8
- data/lib/active_record/attribute_methods/read.rb +18 -50
- data/lib/active_record/attribute_methods/serialization.rb +38 -10
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +38 -66
- data/lib/active_record/attribute_methods/write.rb +25 -32
- data/lib/active_record/attributes.rb +69 -31
- data/lib/active_record/autosave_association.rb +102 -66
- data/lib/active_record/base.rb +16 -25
- data/lib/active_record/callbacks.rb +202 -43
- data/lib/active_record/coders/json.rb +2 -0
- data/lib/active_record/coders/yaml_column.rb +11 -12
- data/lib/active_record/connection_adapters.rb +50 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +661 -375
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +14 -38
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +269 -105
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +54 -35
- data/lib/active_record/connection_adapters/abstract/quoting.rb +137 -93
- data/lib/active_record/connection_adapters/abstract/savepoints.rb +5 -3
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +155 -113
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +328 -162
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +68 -80
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +591 -259
- data/lib/active_record/connection_adapters/abstract/transaction.rb +229 -91
- data/lib/active_record/connection_adapters/abstract_adapter.rb +392 -244
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +457 -582
- data/lib/active_record/connection_adapters/column.rb +55 -13
- 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 +8 -31
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +135 -49
- data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +24 -23
- data/lib/active_record/connection_adapters/mysql/quoting.rb +50 -20
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +79 -49
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +66 -56
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +70 -36
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +268 -0
- data/lib/active_record/connection_adapters/mysql/type_metadata.rb +20 -12
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +74 -37
- 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 +39 -28
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +70 -101
- data/lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb +5 -3
- data/lib/active_record/connection_adapters/postgresql/oid.rb +26 -21
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +22 -11
- data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +6 -5
- data/lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/bytea.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +6 -6
- data/lib/active_record/connection_adapters/postgresql/oid/date.rb +23 -0
- data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +14 -4
- 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 +19 -18
- 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 -5
- data/lib/active_record/connection_adapters/postgresql/oid/{json.rb → oid.rb} +6 -1
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +30 -9
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +52 -30
- data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +4 -1
- 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 +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/xml.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +98 -38
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +21 -27
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +80 -0
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +147 -105
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +34 -32
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +426 -324
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +32 -23
- data/lib/active_record/connection_adapters/postgresql/utils.rb +9 -6
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +418 -293
- data/lib/active_record/connection_adapters/schema_cache.rb +135 -18
- data/lib/active_record/connection_adapters/sql_type_metadata.rb +22 -7
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +144 -0
- data/lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb +3 -1
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +72 -18
- data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +5 -6
- 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 +282 -290
- data/lib/active_record/connection_adapters/statement_pool.rb +9 -8
- data/lib/active_record/connection_handling.rb +287 -45
- data/lib/active_record/core.rb +385 -181
- data/lib/active_record/counter_cache.rb +60 -28
- data/lib/active_record/database_configurations.rb +272 -0
- 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/delegated_type.rb +209 -0
- data/lib/active_record/destroy_association_async_job.rb +36 -0
- data/lib/active_record/dynamic_matchers.rb +87 -87
- data/lib/active_record/enum.rb +122 -47
- data/lib/active_record/errors.rb +153 -22
- data/lib/active_record/explain.rb +13 -8
- data/lib/active_record/explain_registry.rb +3 -1
- data/lib/active_record/explain_subscriber.rb +9 -4
- data/lib/active_record/fixture_set/file.rb +20 -22
- 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 +246 -507
- data/lib/active_record/gem_version.rb +6 -4
- data/lib/active_record/inheritance.rb +168 -95
- data/lib/active_record/insert_all.rb +208 -0
- data/lib/active_record/integration.rb +114 -25
- data/lib/active_record/internal_metadata.rb +30 -24
- data/lib/active_record/legacy_yaml_adapter.rb +11 -5
- data/lib/active_record/locking/optimistic.rb +81 -85
- data/lib/active_record/locking/pessimistic.rb +22 -6
- data/lib/active_record/log_subscriber.rb +68 -31
- data/lib/active_record/middleware/database_selector.rb +77 -0
- data/lib/active_record/middleware/database_selector/resolver.rb +92 -0
- data/lib/active_record/middleware/database_selector/resolver/session.rb +48 -0
- data/lib/active_record/migration.rb +439 -342
- data/lib/active_record/migration/command_recorder.rb +152 -98
- data/lib/active_record/migration/compatibility.rb +229 -60
- data/lib/active_record/migration/join_table.rb +8 -7
- data/lib/active_record/model_schema.rb +230 -122
- data/lib/active_record/nested_attributes.rb +213 -203
- data/lib/active_record/no_touching.rb +11 -2
- data/lib/active_record/null_relation.rb +12 -34
- data/lib/active_record/persistence.rb +471 -97
- data/lib/active_record/query_cache.rb +23 -12
- data/lib/active_record/querying.rb +43 -25
- data/lib/active_record/railtie.rb +155 -43
- data/lib/active_record/railties/console_sandbox.rb +2 -0
- data/lib/active_record/railties/controller_runtime.rb +34 -33
- data/lib/active_record/railties/databases.rake +507 -195
- data/lib/active_record/readonly_attributes.rb +9 -4
- data/lib/active_record/reflection.rb +245 -269
- data/lib/active_record/relation.rb +475 -324
- data/lib/active_record/relation/batches.rb +125 -72
- data/lib/active_record/relation/batches/batch_enumerator.rb +28 -10
- data/lib/active_record/relation/calculations.rb +267 -171
- data/lib/active_record/relation/delegation.rb +73 -69
- data/lib/active_record/relation/finder_methods.rb +238 -248
- data/lib/active_record/relation/from_clause.rb +7 -9
- data/lib/active_record/relation/merger.rb +95 -77
- data/lib/active_record/relation/predicate_builder.rb +109 -110
- data/lib/active_record/relation/predicate_builder/array_handler.rb +22 -17
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +42 -0
- data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +6 -4
- data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +55 -0
- data/lib/active_record/relation/predicate_builder/range_handler.rb +7 -18
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +7 -1
- data/lib/active_record/relation/query_attribute.rb +33 -2
- data/lib/active_record/relation/query_methods.rb +654 -374
- data/lib/active_record/relation/record_fetch_warning.rb +8 -6
- data/lib/active_record/relation/spawn_methods.rb +15 -14
- data/lib/active_record/relation/where_clause.rb +171 -109
- data/lib/active_record/result.rb +88 -51
- data/lib/active_record/runtime_registry.rb +5 -3
- data/lib/active_record/sanitization.rb +73 -100
- data/lib/active_record/schema.rb +7 -14
- data/lib/active_record/schema_dumper.rb +101 -69
- data/lib/active_record/schema_migration.rb +16 -12
- data/lib/active_record/scoping.rb +20 -20
- data/lib/active_record/scoping/default.rb +92 -95
- data/lib/active_record/scoping/named.rb +39 -30
- data/lib/active_record/secure_token.rb +19 -9
- data/lib/active_record/serialization.rb +7 -3
- data/lib/active_record/signed_id.rb +116 -0
- data/lib/active_record/statement_cache.rb +80 -29
- data/lib/active_record/store.rb +122 -42
- data/lib/active_record/suppressor.rb +6 -3
- data/lib/active_record/table_metadata.rb +51 -39
- data/lib/active_record/tasks/database_tasks.rb +332 -115
- data/lib/active_record/tasks/mysql_database_tasks.rb +66 -104
- data/lib/active_record/tasks/postgresql_database_tasks.rb +84 -56
- data/lib/active_record/tasks/sqlite_database_tasks.rb +40 -19
- data/lib/active_record/test_databases.rb +24 -0
- data/lib/active_record/test_fixtures.rb +246 -0
- data/lib/active_record/timestamp.rb +70 -38
- data/lib/active_record/touch_later.rb +26 -24
- data/lib/active_record/transactions.rb +121 -184
- data/lib/active_record/translation.rb +3 -1
- data/lib/active_record/type.rb +29 -17
- data/lib/active_record/type/adapter_specific_registry.rb +44 -48
- data/lib/active_record/type/date.rb +2 -0
- data/lib/active_record/type/date_time.rb +2 -0
- data/lib/active_record/type/decimal_without_scale.rb +15 -0
- data/lib/active_record/type/hash_lookup_type_map.rb +5 -4
- data/lib/active_record/type/internal/timezone.rb +2 -0
- data/lib/active_record/type/json.rb +30 -0
- data/lib/active_record/type/serialized.rb +20 -9
- data/lib/active_record/type/text.rb +11 -0
- data/lib/active_record/type/time.rb +12 -1
- data/lib/active_record/type/type_map.rb +14 -17
- data/lib/active_record/type/unsigned_integer.rb +16 -0
- data/lib/active_record/type_caster.rb +4 -2
- data/lib/active_record/type_caster/connection.rb +17 -13
- data/lib/active_record/type_caster/map.rb +10 -6
- data/lib/active_record/validations.rb +8 -5
- data/lib/active_record/validations/absence.rb +2 -0
- data/lib/active_record/validations/associated.rb +4 -3
- data/lib/active_record/validations/length.rb +2 -0
- data/lib/active_record/validations/numericality.rb +35 -0
- data/lib/active_record/validations/presence.rb +4 -2
- data/lib/active_record/validations/uniqueness.rb +52 -45
- data/lib/active_record/version.rb +3 -1
- data/lib/arel.rb +54 -0
- 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.rb +70 -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/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.rb +13 -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/window_predications.rb +9 -0
- data/lib/rails/generators/active_record.rb +7 -5
- data/lib/rails/generators/active_record/application_record/application_record_generator.rb +26 -0
- data/lib/rails/generators/active_record/{model/templates/application_record.rb → application_record/templates/application_record.rb.tt} +0 -0
- data/lib/rails/generators/active_record/migration.rb +22 -3
- data/lib/rails/generators/active_record/migration/migration_generator.rb +38 -35
- data/lib/rails/generators/active_record/migration/templates/{create_table_migration.rb → create_table_migration.rb.tt} +3 -1
- data/lib/rails/generators/active_record/migration/templates/{migration.rb → migration.rb.tt} +7 -5
- data/lib/rails/generators/active_record/model/model_generator.rb +41 -25
- 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 → model.rb.tt} +10 -1
- data/lib/rails/generators/active_record/model/templates/{module.rb → module.rb.tt} +0 -0
- metadata +141 -57
- data/lib/active_record/associations/preloader/belongs_to.rb +0 -17
- data/lib/active_record/associations/preloader/collection_association.rb +0 -17
- 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 -15
- data/lib/active_record/associations/preloader/has_one_through.rb +0 -9
- data/lib/active_record/associations/preloader/singular_association.rb +0 -20
- data/lib/active_record/attribute.rb +0 -213
- data/lib/active_record/attribute/user_provided_default.rb +0 -28
- data/lib/active_record/attribute_decorators.rb +0 -67
- data/lib/active_record/attribute_mutation_tracker.rb +0 -70
- data/lib/active_record/attribute_set.rb +0 -110
- data/lib/active_record/attribute_set/builder.rb +0 -132
- data/lib/active_record/collection_cache_key.rb +0 -50
- data/lib/active_record/connection_adapters/connection_specification.rb +0 -263
- data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +0 -22
- data/lib/active_record/connection_adapters/postgresql/oid/rails_5_1_point.rb +0 -50
- data/lib/active_record/railties/jdbcmysql_error.rb +0 -16
- data/lib/active_record/relation/predicate_builder/association_query_handler.rb +0 -88
- data/lib/active_record/relation/predicate_builder/base_handler.rb +0 -17
- data/lib/active_record/relation/predicate_builder/class_handler.rb +0 -27
- data/lib/active_record/relation/predicate_builder/polymorphic_array_handler.rb +0 -57
- data/lib/active_record/relation/where_clause_factory.rb +0 -38
- data/lib/active_record/type/internal/abstract_json.rb +0 -33
@@ -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
|
@@ -6,12 +8,15 @@ module ActiveRecord
|
|
6
8
|
#
|
7
9
|
# * add_column
|
8
10
|
# * add_foreign_key
|
11
|
+
# * add_check_constraint
|
9
12
|
# * add_index
|
10
13
|
# * add_reference
|
11
14
|
# * add_timestamps
|
12
15
|
# * change_column
|
13
16
|
# * change_column_default (must supply a :from and :to option)
|
14
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)
|
15
20
|
# * create_join_table
|
16
21
|
# * create_table
|
17
22
|
# * disable_extension
|
@@ -21,6 +26,7 @@ module ActiveRecord
|
|
21
26
|
# * remove_column (must supply a type)
|
22
27
|
# * remove_columns (must specify at least one column name or more)
|
23
28
|
# * remove_foreign_key (must supply a second table)
|
29
|
+
# * remove_check_constraint
|
24
30
|
# * remove_index
|
25
31
|
# * remove_reference
|
26
32
|
# * remove_timestamps
|
@@ -28,12 +34,15 @@ module ActiveRecord
|
|
28
34
|
# * rename_index
|
29
35
|
# * rename_table
|
30
36
|
class CommandRecorder
|
31
|
-
ReversibleAndIrreversibleMethods = [
|
37
|
+
ReversibleAndIrreversibleMethods = [
|
38
|
+
:create_table, :create_join_table, :rename_table, :add_column, :remove_column,
|
32
39
|
:rename_index, :rename_column, :add_index, :remove_index, :add_timestamps, :remove_timestamps,
|
33
40
|
:change_column_default, :add_reference, :remove_reference, :transaction,
|
34
41
|
:drop_join_table, :drop_table, :execute_block, :enable_extension, :disable_extension,
|
35
42
|
:change_column, :execute, :remove_columns, :change_column_null,
|
36
|
-
:add_foreign_key, :remove_foreign_key
|
43
|
+
:add_foreign_key, :remove_foreign_key,
|
44
|
+
:change_column_comment, :change_table_comment,
|
45
|
+
:add_check_constraint, :remove_check_constraint
|
37
46
|
]
|
38
47
|
include JoinTable
|
39
48
|
|
@@ -79,11 +88,16 @@ module ActiveRecord
|
|
79
88
|
# recorder.inverse_of(:rename_table, [:old, :new])
|
80
89
|
# # => [:rename_table, [:new, :old]]
|
81
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
|
+
#
|
82
96
|
# This method will raise an +IrreversibleMigration+ exception if it cannot
|
83
97
|
# invert the +command+.
|
84
98
|
def inverse_of(command, args, &block)
|
85
99
|
method = :"invert_#{command}"
|
86
|
-
raise IrreversibleMigration,
|
100
|
+
raise IrreversibleMigration, <<~MSG unless respond_to?(method, true)
|
87
101
|
This migration uses #{command}, which is not automatically reversible.
|
88
102
|
To make the migration reversible you can either:
|
89
103
|
1. Define #up and #down methods in place of the #change method.
|
@@ -92,147 +106,187 @@ module ActiveRecord
|
|
92
106
|
send(method, args, &block)
|
93
107
|
end
|
94
108
|
|
95
|
-
def respond_to?(*args) # :nodoc:
|
96
|
-
super || delegate.respond_to?(*args)
|
97
|
-
end
|
98
|
-
|
99
109
|
ReversibleAndIrreversibleMethods.each do |method|
|
100
110
|
class_eval <<-EOV, __FILE__, __LINE__ + 1
|
101
111
|
def #{method}(*args, &block) # def create_table(*args, &block)
|
102
112
|
record(:"#{method}", args, &block) # record(:create_table, args, &block)
|
103
113
|
end # end
|
104
114
|
EOV
|
115
|
+
ruby2_keywords(method) if respond_to?(:ruby2_keywords, true)
|
105
116
|
end
|
106
117
|
alias :add_belongs_to :add_reference
|
107
118
|
alias :remove_belongs_to :remove_reference
|
108
119
|
|
109
|
-
def change_table(table_name, options
|
120
|
+
def change_table(table_name, **options) # :nodoc:
|
110
121
|
yield delegate.update_table_definition(table_name, self)
|
111
122
|
end
|
112
123
|
|
124
|
+
def replay(migration)
|
125
|
+
commands.each do |cmd, args, block|
|
126
|
+
migration.send(cmd, *args, &block)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
113
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
|
114
154
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
[[inv, cmd], [cmd, inv]].uniq.each do |method, inverse|
|
127
|
-
class_eval <<-EOV, __FILE__, __LINE__ + 1
|
128
|
-
def invert_#{method}(args, &block) # def invert_create_table(args, &block)
|
129
|
-
[:#{inverse}, args, block] # [:drop_table, args, block]
|
130
|
-
end # end
|
131
|
-
EOV
|
132
|
-
end
|
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]
|
133
166
|
end
|
134
|
-
end
|
135
167
|
|
136
|
-
|
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)."
|
171
|
+
end
|
172
|
+
super
|
173
|
+
end
|
137
174
|
|
138
|
-
|
139
|
-
|
140
|
-
raise ActiveRecord::IrreversibleMigration, "To avoid mistakes, drop_table is only reversible if given options or a block (can be empty)."
|
175
|
+
def invert_rename_table(args)
|
176
|
+
[:rename_table, args.reverse]
|
141
177
|
end
|
142
|
-
super
|
143
|
-
end
|
144
178
|
|
145
|
-
|
146
|
-
|
147
|
-
|
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
|
182
|
+
end
|
148
183
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
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
|
153
188
|
|
154
|
-
|
155
|
-
|
156
|
-
end
|
189
|
+
[:add_columns, args]
|
190
|
+
end
|
157
191
|
|
158
|
-
|
159
|
-
|
160
|
-
|
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
|
161
196
|
|
162
|
-
|
163
|
-
|
164
|
-
|
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
|
165
201
|
|
166
|
-
|
167
|
-
|
202
|
+
def invert_remove_index(args)
|
203
|
+
options = args.extract_options!
|
204
|
+
table, columns = args
|
168
205
|
|
169
|
-
|
170
|
-
end
|
206
|
+
columns ||= options.delete(:column)
|
171
207
|
|
172
|
-
|
173
|
-
table, options_or_column = *args
|
174
|
-
if (options = options_or_column).is_a?(Hash)
|
175
|
-
unless options[:column]
|
208
|
+
unless columns
|
176
209
|
raise ActiveRecord::IrreversibleMigration, "remove_index is only reversible if given a :column option."
|
177
210
|
end
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
211
|
+
|
212
|
+
options.delete(:if_exists)
|
213
|
+
|
214
|
+
args = [table, columns]
|
215
|
+
args << options unless options.empty?
|
216
|
+
|
217
|
+
[:add_index, args]
|
182
218
|
end
|
183
|
-
end
|
184
219
|
|
185
|
-
|
186
|
-
|
220
|
+
alias :invert_add_belongs_to :invert_add_reference
|
221
|
+
alias :invert_remove_belongs_to :invert_remove_reference
|
222
|
+
|
223
|
+
def invert_change_column_default(args)
|
224
|
+
table, column, options = args
|
225
|
+
|
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
|
187
229
|
|
188
|
-
|
189
|
-
|
230
|
+
[:change_column_default, [table, column, from: options[:to], to: options[:from]]]
|
231
|
+
end
|
190
232
|
|
191
|
-
|
192
|
-
|
233
|
+
def invert_change_column_null(args)
|
234
|
+
args[2] = !args[2]
|
235
|
+
[:change_column_null, args]
|
193
236
|
end
|
194
237
|
|
195
|
-
|
196
|
-
|
238
|
+
def invert_remove_foreign_key(args)
|
239
|
+
options = args.extract_options!
|
240
|
+
from_table, to_table = args
|
197
241
|
|
198
|
-
|
199
|
-
args[2] = !args[2]
|
200
|
-
[:change_column_null, args]
|
201
|
-
end
|
242
|
+
to_table ||= options.delete(:to_table)
|
202
243
|
|
203
|
-
|
204
|
-
from_table, to_table, add_options = args
|
205
|
-
add_options ||= {}
|
244
|
+
raise ActiveRecord::IrreversibleMigration, "remove_foreign_key is only reversible if given a second table" if to_table.nil?
|
206
245
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
else
|
212
|
-
options = to_table
|
246
|
+
reversed_args = [from_table, to_table]
|
247
|
+
reversed_args << options unless options.empty?
|
248
|
+
|
249
|
+
[:add_foreign_key, reversed_args]
|
213
250
|
end
|
214
251
|
|
215
|
-
|
216
|
-
|
252
|
+
def invert_change_column_comment(args)
|
253
|
+
table, column, options = args
|
217
254
|
|
218
|
-
|
219
|
-
|
220
|
-
|
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
|
221
258
|
|
222
|
-
|
223
|
-
|
259
|
+
[:change_column_comment, [table, column, from: options[:to], to: options[:from]]]
|
260
|
+
end
|
224
261
|
|
225
|
-
|
226
|
-
|
262
|
+
def invert_change_table_comment(args)
|
263
|
+
table, options = args
|
227
264
|
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
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
|
233
274
|
super
|
234
275
|
end
|
235
|
-
|
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)
|
236
290
|
end
|
237
291
|
end
|
238
292
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
class Migration
|
3
5
|
module Compatibility # :nodoc: all
|
@@ -5,121 +7,288 @@ module ActiveRecord
|
|
5
7
|
version = version.to_s
|
6
8
|
name = "V#{version.tr('.', '_')}"
|
7
9
|
unless const_defined?(name)
|
8
|
-
versions = constants.grep(/\AV[0-9_]+\z/).map { |s| s.to_s.delete(
|
10
|
+
versions = constants.grep(/\AV[0-9_]+\z/).map { |s| s.to_s.delete("V").tr("_", ".").inspect }
|
9
11
|
raise ArgumentError, "Unknown migration version #{version.inspect}; expected one of #{versions.sort.join(', ')}"
|
10
12
|
end
|
11
13
|
const_get(name)
|
12
14
|
end
|
13
15
|
|
14
|
-
|
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
|
15
24
|
|
16
|
-
module FourTwoShared
|
17
25
|
module TableDefinition
|
18
|
-
def references(
|
19
|
-
|
20
|
-
|
26
|
+
def references(*args, **options)
|
27
|
+
args.each do |ref_name|
|
28
|
+
ReferenceDefinition.new(ref_name, **options).add_to(self)
|
29
|
+
end
|
21
30
|
end
|
22
31
|
alias :belongs_to :references
|
32
|
+
end
|
23
33
|
|
24
|
-
|
25
|
-
|
34
|
+
def create_table(table_name, **options)
|
35
|
+
if block_given?
|
36
|
+
super { |t| yield compatible_table_definition(t) }
|
37
|
+
else
|
26
38
|
super
|
27
39
|
end
|
28
40
|
end
|
29
41
|
|
30
|
-
def
|
42
|
+
def change_table(table_name, **options)
|
31
43
|
if block_given?
|
32
|
-
super
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
37
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) }
|
38
98
|
else
|
39
99
|
super
|
40
100
|
end
|
41
101
|
end
|
42
102
|
|
43
|
-
def change_table(table_name, options
|
103
|
+
def change_table(table_name, **options)
|
44
104
|
if block_given?
|
45
|
-
super
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
50
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)
|
51
156
|
else
|
52
157
|
super
|
53
158
|
end
|
54
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
|
55
238
|
|
56
|
-
def add_reference(
|
239
|
+
def add_reference(table_name, ref_name, **options)
|
57
240
|
options[:index] ||= false
|
58
241
|
super
|
59
242
|
end
|
60
243
|
alias :add_belongs_to :add_reference
|
61
244
|
|
62
|
-
def add_timestamps(
|
245
|
+
def add_timestamps(table_name, **options)
|
63
246
|
options[:null] = true if options[:null].nil?
|
64
247
|
super
|
65
248
|
end
|
66
249
|
|
67
|
-
def index_exists?(table_name, column_name, options
|
250
|
+
def index_exists?(table_name, column_name, **options)
|
68
251
|
column_names = Array(column_name).map(&:to_s)
|
69
252
|
options[:name] =
|
70
253
|
if options[:name].present?
|
71
254
|
options[:name].to_s
|
72
255
|
else
|
73
|
-
index_name(table_name, column: column_names)
|
256
|
+
connection.index_name(table_name, column: column_names)
|
74
257
|
end
|
75
258
|
super
|
76
259
|
end
|
77
260
|
|
78
|
-
def remove_index(table_name,
|
79
|
-
options =
|
80
|
-
|
81
|
-
super(table_name, options)
|
261
|
+
def remove_index(table_name, column_name = nil, **options)
|
262
|
+
options[:name] = index_name_for_remove(table_name, column_name, options)
|
263
|
+
super
|
82
264
|
end
|
83
265
|
|
84
266
|
private
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
unless index_name_exists?(table_name, index_name, true)
|
90
|
-
if options.is_a?(Hash) && options.has_key?(:name)
|
91
|
-
options_without_column = options.dup
|
92
|
-
options_without_column.delete :column
|
93
|
-
index_name_without_column = index_name(table_name, options_without_column)
|
94
|
-
|
95
|
-
return index_name_without_column if index_name_exists?(table_name, index_name_without_column, false)
|
267
|
+
def compatible_table_definition(t)
|
268
|
+
class << t
|
269
|
+
prepend TableDefinition
|
96
270
|
end
|
97
|
-
|
98
|
-
raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' does not exist"
|
271
|
+
super
|
99
272
|
end
|
100
273
|
|
101
|
-
|
102
|
-
|
103
|
-
end
|
274
|
+
def index_name_for_remove(table_name, column_name, options)
|
275
|
+
index_name = connection.index_name(table_name, column_name || options)
|
104
276
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
include FourTwoShared
|
110
|
-
end
|
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)
|
111
281
|
|
112
|
-
|
113
|
-
|
282
|
+
if connection.index_name_exists?(table_name, index_name_without_column)
|
283
|
+
return index_name_without_column
|
284
|
+
end
|
285
|
+
end
|
114
286
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
" class #{self.class.name} < ActiveRecord::Migration[4.2]"
|
121
|
-
super
|
122
|
-
end
|
287
|
+
raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' does not exist"
|
288
|
+
end
|
289
|
+
|
290
|
+
index_name
|
291
|
+
end
|
123
292
|
end
|
124
293
|
end
|
125
294
|
end
|