activerecord 6.0.0.rc1 → 6.0.3.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of activerecord might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +251 -3
- data/README.rdoc +1 -1
- data/lib/active_record.rb +1 -0
- data/lib/active_record/advisory_lock_base.rb +18 -0
- data/lib/active_record/aggregations.rb +0 -1
- data/lib/active_record/association_relation.rb +10 -8
- data/lib/active_record/associations.rb +2 -2
- data/lib/active_record/associations/alias_tracker.rb +0 -1
- data/lib/active_record/associations/association.rb +5 -1
- data/lib/active_record/associations/builder/collection_association.rb +2 -2
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +1 -3
- data/lib/active_record/associations/collection_association.rb +6 -2
- data/lib/active_record/associations/collection_proxy.rb +2 -3
- data/lib/active_record/associations/has_many_association.rb +0 -1
- data/lib/active_record/associations/join_dependency.rb +23 -9
- data/lib/active_record/associations/join_dependency/join_association.rb +12 -3
- data/lib/active_record/associations/preloader.rb +2 -3
- data/lib/active_record/associations/preloader/association.rb +3 -1
- data/lib/active_record/attribute_assignment.rb +0 -1
- data/lib/active_record/attribute_decorators.rb +0 -2
- data/lib/active_record/attribute_methods.rb +0 -51
- data/lib/active_record/attribute_methods/before_type_cast.rb +0 -1
- data/lib/active_record/attribute_methods/dirty.rb +8 -3
- data/lib/active_record/attribute_methods/primary_key.rb +0 -2
- data/lib/active_record/attribute_methods/read.rb +0 -1
- data/lib/active_record/attribute_methods/serialization.rb +0 -1
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +0 -2
- data/lib/active_record/attribute_methods/write.rb +0 -1
- data/lib/active_record/attributes.rb +0 -1
- data/lib/active_record/autosave_association.rb +11 -7
- data/lib/active_record/callbacks.rb +1 -2
- data/lib/active_record/coders/yaml_column.rb +0 -1
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +107 -13
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +21 -15
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +5 -5
- data/lib/active_record/connection_adapters/abstract/quoting.rb +53 -0
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +1 -2
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +27 -27
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +55 -37
- data/lib/active_record/connection_adapters/abstract/transaction.rb +14 -7
- data/lib/active_record/connection_adapters/abstract_adapter.rb +62 -25
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +25 -32
- data/lib/active_record/connection_adapters/connection_specification.rb +3 -4
- data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +2 -2
- data/lib/active_record/connection_adapters/mysql/column.rb +1 -1
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +8 -12
- data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +0 -1
- data/lib/active_record/connection_adapters/mysql/quoting.rb +44 -7
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +1 -2
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +3 -1
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +8 -8
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +12 -4
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +9 -3
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/oid/money.rb +2 -2
- data/lib/active_record/connection_adapters/postgresql/oid/oid.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +39 -2
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +2 -2
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +15 -29
- data/lib/active_record/connection_adapters/postgresql/utils.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +17 -3
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +8 -7
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +38 -3
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +3 -3
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +23 -8
- data/lib/active_record/connection_adapters/statement_pool.rb +0 -1
- data/lib/active_record/connection_handling.rb +17 -22
- data/lib/active_record/core.rb +8 -6
- data/lib/active_record/counter_cache.rb +4 -1
- data/lib/active_record/database_configurations.rb +60 -31
- data/lib/active_record/database_configurations/url_config.rb +0 -1
- data/lib/active_record/dynamic_matchers.rb +2 -3
- data/lib/active_record/enum.rb +9 -0
- data/lib/active_record/explain.rb +0 -1
- data/lib/active_record/fixture_set/table_row.rb +0 -1
- data/lib/active_record/fixture_set/table_rows.rb +0 -1
- data/lib/active_record/fixtures.rb +11 -9
- data/lib/active_record/gem_version.rb +1 -1
- data/lib/active_record/inheritance.rb +0 -3
- data/lib/active_record/insert_all.rb +5 -6
- data/lib/active_record/internal_metadata.rb +1 -1
- data/lib/active_record/locking/optimistic.rb +0 -1
- data/lib/active_record/log_subscriber.rb +1 -1
- data/lib/active_record/middleware/database_selector.rb +3 -4
- data/lib/active_record/middleware/database_selector/resolver.rb +5 -8
- data/lib/active_record/migration.rb +43 -32
- data/lib/active_record/migration/command_recorder.rb +6 -18
- data/lib/active_record/migration/compatibility.rb +3 -3
- data/lib/active_record/migration/join_table.rb +0 -1
- data/lib/active_record/model_schema.rb +3 -2
- data/lib/active_record/nested_attributes.rb +0 -2
- data/lib/active_record/no_touching.rb +2 -2
- data/lib/active_record/null_relation.rb +0 -1
- data/lib/active_record/persistence.rb +4 -5
- data/lib/active_record/querying.rb +1 -1
- data/lib/active_record/railtie.rb +1 -2
- data/lib/active_record/railties/collection_cache_association_loading.rb +1 -1
- data/lib/active_record/railties/databases.rake +63 -23
- data/lib/active_record/reflection.rb +9 -9
- data/lib/active_record/relation.rb +13 -1
- data/lib/active_record/relation/batches.rb +0 -1
- data/lib/active_record/relation/calculations.rb +3 -5
- data/lib/active_record/relation/delegation.rb +7 -6
- data/lib/active_record/relation/finder_methods.rb +14 -4
- data/lib/active_record/relation/from_clause.rb +4 -0
- data/lib/active_record/relation/merger.rb +6 -3
- data/lib/active_record/relation/predicate_builder.rb +1 -5
- data/lib/active_record/relation/query_methods.rb +94 -55
- data/lib/active_record/relation/spawn_methods.rb +0 -1
- data/lib/active_record/relation/where_clause.rb +0 -1
- data/lib/active_record/result.rb +0 -1
- data/lib/active_record/sanitization.rb +30 -2
- data/lib/active_record/schema.rb +1 -1
- data/lib/active_record/schema_dumper.rb +5 -1
- data/lib/active_record/schema_migration.rb +1 -1
- data/lib/active_record/scoping.rb +0 -1
- data/lib/active_record/scoping/default.rb +0 -1
- data/lib/active_record/scoping/named.rb +3 -3
- data/lib/active_record/store.rb +1 -1
- data/lib/active_record/suppressor.rb +2 -2
- data/lib/active_record/table_metadata.rb +21 -10
- data/lib/active_record/tasks/database_tasks.rb +76 -8
- data/lib/active_record/tasks/mysql_database_tasks.rb +3 -2
- data/lib/active_record/tasks/postgresql_database_tasks.rb +0 -1
- data/lib/active_record/tasks/sqlite_database_tasks.rb +0 -1
- data/lib/active_record/test_databases.rb +1 -16
- data/lib/active_record/test_fixtures.rb +2 -1
- data/lib/active_record/timestamp.rb +26 -17
- data/lib/active_record/touch_later.rb +3 -2
- data/lib/active_record/transactions.rb +18 -19
- data/lib/active_record/type.rb +0 -1
- data/lib/active_record/type/adapter_specific_registry.rb +2 -5
- data/lib/active_record/type/hash_lookup_type_map.rb +0 -1
- data/lib/active_record/type/serialized.rb +0 -1
- data/lib/active_record/type/type_map.rb +0 -1
- data/lib/active_record/type/unsigned_integer.rb +0 -1
- data/lib/active_record/type_caster/connection.rb +16 -10
- data/lib/active_record/validations.rb +3 -3
- data/lib/active_record/validations/associated.rb +1 -2
- data/lib/arel.rb +17 -6
- data/lib/arel/predications.rb +5 -6
- data/lib/arel/visitors/depth_first.rb +1 -2
- data/lib/arel/visitors/dot.rb +0 -1
- data/lib/arel/visitors/mssql.rb +0 -1
- data/lib/arel/visitors/oracle.rb +1 -2
- data/lib/arel/visitors/oracle12.rb +0 -1
- data/lib/arel/visitors/postgresql.rb +0 -1
- data/lib/arel/visitors/sqlite.rb +0 -1
- data/lib/arel/visitors/to_sql.rb +23 -27
- data/lib/arel/visitors/visitor.rb +9 -6
- data/lib/arel/visitors/where_sql.rb +0 -1
- data/lib/rails/generators/active_record/application_record/application_record_generator.rb +0 -1
- data/lib/rails/generators/active_record/migration.rb +0 -1
- data/lib/rails/generators/active_record/migration/templates/migration.rb.tt +1 -1
- data/lib/rails/generators/active_record/model/model_generator.rb +0 -1
- metadata +13 -9
@@ -35,10 +35,10 @@ module ActiveRecord
|
|
35
35
|
# config.active_record.database_resolver = MyResolver
|
36
36
|
# config.active_record.database_resolver_context = MyResolver::MySession
|
37
37
|
class DatabaseSelector
|
38
|
-
def initialize(app, resolver_klass =
|
38
|
+
def initialize(app, resolver_klass = nil, context_klass = nil, options = {})
|
39
39
|
@app = app
|
40
|
-
@resolver_klass = resolver_klass
|
41
|
-
@context_klass = context_klass
|
40
|
+
@resolver_klass = resolver_klass || Resolver
|
41
|
+
@context_klass = context_klass || Resolver::Session
|
42
42
|
@options = options
|
43
43
|
end
|
44
44
|
|
@@ -55,7 +55,6 @@ module ActiveRecord
|
|
55
55
|
end
|
56
56
|
|
57
57
|
private
|
58
|
-
|
59
58
|
def select_database(request, &blk)
|
60
59
|
context = context_klass.call(request)
|
61
60
|
resolver = resolver_klass.call(context, options)
|
@@ -44,19 +44,16 @@ module ActiveRecord
|
|
44
44
|
end
|
45
45
|
|
46
46
|
private
|
47
|
-
|
48
47
|
def read_from_primary(&blk)
|
49
|
-
ActiveRecord::Base.
|
50
|
-
|
51
|
-
|
52
|
-
yield
|
53
|
-
end
|
48
|
+
ActiveRecord::Base.connected_to(role: ActiveRecord::Base.writing_role, prevent_writes: true) do
|
49
|
+
instrumenter.instrument("database_selector.active_record.read_from_primary") do
|
50
|
+
yield
|
54
51
|
end
|
55
52
|
end
|
56
53
|
end
|
57
54
|
|
58
55
|
def read_from_replica(&blk)
|
59
|
-
ActiveRecord::Base.connected_to(role: ActiveRecord::Base.reading_role) do
|
56
|
+
ActiveRecord::Base.connected_to(role: ActiveRecord::Base.reading_role, prevent_writes: true) do
|
60
57
|
instrumenter.instrument("database_selector.active_record.read_from_replica") do
|
61
58
|
yield
|
62
59
|
end
|
@@ -64,7 +61,7 @@ module ActiveRecord
|
|
64
61
|
end
|
65
62
|
|
66
63
|
def write_to_primary(&blk)
|
67
|
-
ActiveRecord::Base.connected_to(role: ActiveRecord::Base.writing_role) do
|
64
|
+
ActiveRecord::Base.connected_to(role: ActiveRecord::Base.writing_role, prevent_writes: false) do
|
68
65
|
instrumenter.instrument("database_selector.active_record.wrote_to_primary") do
|
69
66
|
yield
|
70
67
|
ensure
|
@@ -494,9 +494,9 @@ module ActiveRecord
|
|
494
494
|
# This migration will create the horses table for you on the way up, and
|
495
495
|
# automatically figure out how to drop the table on the way down.
|
496
496
|
#
|
497
|
-
# Some commands
|
498
|
-
#
|
499
|
-
#
|
497
|
+
# Some commands cannot be reversed. If you care to define how to move up
|
498
|
+
# and down in these cases, you should define the +up+ and +down+ methods
|
499
|
+
# as before.
|
500
500
|
#
|
501
501
|
# If a command cannot be reversed, an
|
502
502
|
# <tt>ActiveRecord::IrreversibleMigration</tt> exception will be raised when
|
@@ -568,7 +568,6 @@ module ActiveRecord
|
|
568
568
|
end
|
569
569
|
|
570
570
|
private
|
571
|
-
|
572
571
|
def connection
|
573
572
|
ActiveRecord::Base.connection
|
574
573
|
end
|
@@ -588,18 +587,26 @@ module ActiveRecord
|
|
588
587
|
end
|
589
588
|
|
590
589
|
def load_schema_if_pending!
|
591
|
-
|
590
|
+
current_config = Base.connection_config
|
591
|
+
all_configs = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env)
|
592
|
+
|
593
|
+
needs_update = !all_configs.all? do |db_config|
|
594
|
+
Tasks::DatabaseTasks.schema_up_to_date?(db_config.config, ActiveRecord::Base.schema_format, nil, Rails.env, db_config.spec_name)
|
595
|
+
end
|
596
|
+
|
597
|
+
if needs_update
|
592
598
|
# Roundtrip to Rake to allow plugins to hook into database initialization.
|
593
599
|
root = defined?(ENGINE_ROOT) ? ENGINE_ROOT : Rails.root
|
594
600
|
FileUtils.cd(root) do
|
595
|
-
current_config = Base.connection_config
|
596
601
|
Base.clear_all_connections!
|
597
602
|
system("bin/rails db:test:prepare")
|
598
|
-
# Establish a new connection, the old database may be gone (db:test:prepare uses purge)
|
599
|
-
Base.establish_connection(current_config)
|
600
603
|
end
|
601
|
-
check_pending!
|
602
604
|
end
|
605
|
+
|
606
|
+
# Establish a new connection, the old database may be gone (db:test:prepare uses purge)
|
607
|
+
Base.establish_connection(current_config)
|
608
|
+
|
609
|
+
check_pending!
|
603
610
|
end
|
604
611
|
|
605
612
|
def maintain_test_schema! #:nodoc:
|
@@ -611,6 +618,7 @@ module ActiveRecord
|
|
611
618
|
def method_missing(name, *args, &block) #:nodoc:
|
612
619
|
nearest_delegate.send(name, *args, &block)
|
613
620
|
end
|
621
|
+
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
|
614
622
|
|
615
623
|
def migrate(direction)
|
616
624
|
new.migrate direction
|
@@ -882,16 +890,18 @@ module ActiveRecord
|
|
882
890
|
connection.send(method, *arguments, &block)
|
883
891
|
end
|
884
892
|
end
|
893
|
+
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
|
885
894
|
|
886
895
|
def copy(destination, sources, options = {})
|
887
896
|
copied = []
|
897
|
+
schema_migration = options[:schema_migration] || ActiveRecord::SchemaMigration
|
888
898
|
|
889
899
|
FileUtils.mkdir_p(destination) unless File.exist?(destination)
|
890
900
|
|
891
|
-
destination_migrations = ActiveRecord::MigrationContext.new(destination).migrations
|
901
|
+
destination_migrations = ActiveRecord::MigrationContext.new(destination, schema_migration).migrations
|
892
902
|
last = destination_migrations.last
|
893
903
|
sources.each do |scope, path|
|
894
|
-
source_migrations = ActiveRecord::MigrationContext.new(path).migrations
|
904
|
+
source_migrations = ActiveRecord::MigrationContext.new(path, schema_migration).migrations
|
895
905
|
|
896
906
|
source_migrations.each do |migration|
|
897
907
|
source = File.binread(migration.filename)
|
@@ -992,7 +1002,6 @@ module ActiveRecord
|
|
992
1002
|
delegate :migrate, :announce, :write, :disable_ddl_transaction, to: :migration
|
993
1003
|
|
994
1004
|
private
|
995
|
-
|
996
1005
|
def migration
|
997
1006
|
@migration ||= load_migration
|
998
1007
|
end
|
@@ -1014,10 +1023,11 @@ module ActiveRecord
|
|
1014
1023
|
end
|
1015
1024
|
|
1016
1025
|
class MigrationContext #:nodoc:
|
1017
|
-
attr_reader :migrations_paths
|
1026
|
+
attr_reader :migrations_paths, :schema_migration
|
1018
1027
|
|
1019
|
-
def initialize(migrations_paths)
|
1028
|
+
def initialize(migrations_paths, schema_migration)
|
1020
1029
|
@migrations_paths = migrations_paths
|
1030
|
+
@schema_migration = schema_migration
|
1021
1031
|
end
|
1022
1032
|
|
1023
1033
|
def migrate(target_version = nil, &block)
|
@@ -1048,7 +1058,7 @@ module ActiveRecord
|
|
1048
1058
|
migrations
|
1049
1059
|
end
|
1050
1060
|
|
1051
|
-
Migrator.new(:up, selected_migrations, target_version).migrate
|
1061
|
+
Migrator.new(:up, selected_migrations, schema_migration, target_version).migrate
|
1052
1062
|
end
|
1053
1063
|
|
1054
1064
|
def down(target_version = nil)
|
@@ -1058,20 +1068,20 @@ module ActiveRecord
|
|
1058
1068
|
migrations
|
1059
1069
|
end
|
1060
1070
|
|
1061
|
-
Migrator.new(:down, selected_migrations, target_version).migrate
|
1071
|
+
Migrator.new(:down, selected_migrations, schema_migration, target_version).migrate
|
1062
1072
|
end
|
1063
1073
|
|
1064
1074
|
def run(direction, target_version)
|
1065
|
-
Migrator.new(direction, migrations, target_version).run
|
1075
|
+
Migrator.new(direction, migrations, schema_migration, target_version).run
|
1066
1076
|
end
|
1067
1077
|
|
1068
1078
|
def open
|
1069
|
-
Migrator.new(:up, migrations,
|
1079
|
+
Migrator.new(:up, migrations, schema_migration)
|
1070
1080
|
end
|
1071
1081
|
|
1072
1082
|
def get_all_versions
|
1073
|
-
if
|
1074
|
-
|
1083
|
+
if schema_migration.table_exists?
|
1084
|
+
schema_migration.all_versions.map(&:to_i)
|
1075
1085
|
else
|
1076
1086
|
[]
|
1077
1087
|
end
|
@@ -1108,12 +1118,12 @@ module ActiveRecord
|
|
1108
1118
|
end
|
1109
1119
|
|
1110
1120
|
def migrations_status
|
1111
|
-
db_list =
|
1121
|
+
db_list = schema_migration.normalized_versions
|
1112
1122
|
|
1113
1123
|
file_list = migration_files.map do |file|
|
1114
1124
|
version, name, scope = parse_migration_filename(file)
|
1115
1125
|
raise IllegalMigrationNameError.new(file) unless version
|
1116
|
-
version =
|
1126
|
+
version = schema_migration.normalize_migration_number(version)
|
1117
1127
|
status = db_list.delete(version) ? "up" : "down"
|
1118
1128
|
[status, version, (name + scope).humanize]
|
1119
1129
|
end.compact
|
@@ -1153,7 +1163,7 @@ module ActiveRecord
|
|
1153
1163
|
end
|
1154
1164
|
|
1155
1165
|
def move(direction, steps)
|
1156
|
-
migrator = Migrator.new(direction, migrations)
|
1166
|
+
migrator = Migrator.new(direction, migrations, schema_migration)
|
1157
1167
|
|
1158
1168
|
if current_version != 0 && !migrator.current_migration
|
1159
1169
|
raise UnknownMigrationVersionError.new(current_version)
|
@@ -1172,27 +1182,28 @@ module ActiveRecord
|
|
1172
1182
|
end
|
1173
1183
|
end
|
1174
1184
|
|
1175
|
-
class Migrator
|
1185
|
+
class Migrator # :nodoc:
|
1176
1186
|
class << self
|
1177
1187
|
attr_accessor :migrations_paths
|
1178
1188
|
|
1179
1189
|
# For cases where a table doesn't exist like loading from schema cache
|
1180
1190
|
def current_version
|
1181
|
-
MigrationContext.new(migrations_paths).current_version
|
1191
|
+
MigrationContext.new(migrations_paths, SchemaMigration).current_version
|
1182
1192
|
end
|
1183
1193
|
end
|
1184
1194
|
|
1185
1195
|
self.migrations_paths = ["db/migrate"]
|
1186
1196
|
|
1187
|
-
def initialize(direction, migrations, target_version = nil)
|
1197
|
+
def initialize(direction, migrations, schema_migration, target_version = nil)
|
1188
1198
|
@direction = direction
|
1189
1199
|
@target_version = target_version
|
1190
1200
|
@migrated_versions = nil
|
1191
1201
|
@migrations = migrations
|
1202
|
+
@schema_migration = schema_migration
|
1192
1203
|
|
1193
1204
|
validate(@migrations)
|
1194
1205
|
|
1195
|
-
|
1206
|
+
@schema_migration.create_table
|
1196
1207
|
ActiveRecord::InternalMetadata.create_table
|
1197
1208
|
end
|
1198
1209
|
|
@@ -1246,11 +1257,10 @@ module ActiveRecord
|
|
1246
1257
|
end
|
1247
1258
|
|
1248
1259
|
def load_migrated
|
1249
|
-
@migrated_versions = Set.new(
|
1260
|
+
@migrated_versions = Set.new(@schema_migration.all_versions.map(&:to_i))
|
1250
1261
|
end
|
1251
1262
|
|
1252
1263
|
private
|
1253
|
-
|
1254
1264
|
# Used for running a specific migration.
|
1255
1265
|
def run_without_lock
|
1256
1266
|
migration = migrations.detect { |m| m.version == @target_version }
|
@@ -1330,10 +1340,10 @@ module ActiveRecord
|
|
1330
1340
|
def record_version_state_after_migrating(version)
|
1331
1341
|
if down?
|
1332
1342
|
migrated.delete(version)
|
1333
|
-
|
1343
|
+
@schema_migration.delete_by(version: version.to_s)
|
1334
1344
|
else
|
1335
1345
|
migrated << version
|
1336
|
-
|
1346
|
+
@schema_migration.create!(version: version.to_s)
|
1337
1347
|
end
|
1338
1348
|
end
|
1339
1349
|
|
@@ -1364,7 +1374,8 @@ module ActiveRecord
|
|
1364
1374
|
|
1365
1375
|
def with_advisory_lock
|
1366
1376
|
lock_id = generate_migrator_advisory_lock_id
|
1367
|
-
|
1377
|
+
AdvisoryLockBase.establish_connection(ActiveRecord::Base.connection_config) unless AdvisoryLockBase.connected?
|
1378
|
+
connection = AdvisoryLockBase.connection
|
1368
1379
|
got_lock = connection.get_advisory_lock(lock_id)
|
1369
1380
|
raise ConcurrentMigrationError unless got_lock
|
1370
1381
|
load_migrated # reload schema_migrations to be sure it wasn't changed by another process before we got the lock
|
@@ -32,7 +32,8 @@ module ActiveRecord
|
|
32
32
|
# * rename_index
|
33
33
|
# * rename_table
|
34
34
|
class CommandRecorder
|
35
|
-
ReversibleAndIrreversibleMethods = [
|
35
|
+
ReversibleAndIrreversibleMethods = [
|
36
|
+
:create_table, :create_join_table, :rename_table, :add_column, :remove_column,
|
36
37
|
:rename_index, :rename_column, :add_index, :remove_index, :add_timestamps, :remove_timestamps,
|
37
38
|
:change_column_default, :add_reference, :remove_reference, :transaction,
|
38
39
|
:drop_join_table, :drop_table, :execute_block, :enable_extension, :disable_extension,
|
@@ -103,11 +104,12 @@ module ActiveRecord
|
|
103
104
|
record(:"#{method}", args, &block) # record(:create_table, args, &block)
|
104
105
|
end # end
|
105
106
|
EOV
|
107
|
+
ruby2_keywords(method) if respond_to?(:ruby2_keywords, true)
|
106
108
|
end
|
107
109
|
alias :add_belongs_to :add_reference
|
108
110
|
alias :remove_belongs_to :remove_reference
|
109
111
|
|
110
|
-
def change_table(table_name, options
|
112
|
+
def change_table(table_name, **options) # :nodoc:
|
111
113
|
yield delegate.update_table_definition(table_name, self)
|
112
114
|
end
|
113
115
|
|
@@ -118,7 +120,6 @@ module ActiveRecord
|
|
118
120
|
end
|
119
121
|
|
120
122
|
private
|
121
|
-
|
122
123
|
module StraightReversions # :nodoc:
|
123
124
|
private
|
124
125
|
{
|
@@ -128,6 +129,7 @@ module ActiveRecord
|
|
128
129
|
add_column: :remove_column,
|
129
130
|
add_timestamps: :remove_timestamps,
|
130
131
|
add_reference: :remove_reference,
|
132
|
+
add_foreign_key: :remove_foreign_key,
|
131
133
|
enable_extension: :disable_extension
|
132
134
|
}.each do |cmd, inv|
|
133
135
|
[[inv, cmd], [cmd, inv]].uniq.each do |method, inverse|
|
@@ -218,21 +220,6 @@ module ActiveRecord
|
|
218
220
|
[:change_column_null, args]
|
219
221
|
end
|
220
222
|
|
221
|
-
def invert_add_foreign_key(args)
|
222
|
-
from_table, to_table, add_options = args
|
223
|
-
add_options ||= {}
|
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]]
|
234
|
-
end
|
235
|
-
|
236
223
|
def invert_remove_foreign_key(args)
|
237
224
|
options = args.extract_options!
|
238
225
|
from_table, to_table = args
|
@@ -279,6 +266,7 @@ module ActiveRecord
|
|
279
266
|
super
|
280
267
|
end
|
281
268
|
end
|
269
|
+
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
|
282
270
|
end
|
283
271
|
end
|
284
272
|
end
|
@@ -97,7 +97,7 @@ module ActiveRecord
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
-
def create_table(table_name, options
|
100
|
+
def create_table(table_name, **options)
|
101
101
|
if connection.adapter_name == "Mysql2"
|
102
102
|
super(table_name, options: "ENGINE=InnoDB", **options)
|
103
103
|
else
|
@@ -119,7 +119,7 @@ module ActiveRecord
|
|
119
119
|
alias :belongs_to :references
|
120
120
|
end
|
121
121
|
|
122
|
-
def create_table(table_name, options
|
122
|
+
def create_table(table_name, **options)
|
123
123
|
if connection.adapter_name == "PostgreSQL"
|
124
124
|
if options[:id] == :uuid && !options.key?(:default)
|
125
125
|
options[:default] = "uuid_generate_v4()"
|
@@ -147,7 +147,7 @@ module ActiveRecord
|
|
147
147
|
super
|
148
148
|
end
|
149
149
|
|
150
|
-
def add_column(table_name, column_name, type, options
|
150
|
+
def add_column(table_name, column_name, type, **options)
|
151
151
|
if type == :primary_key
|
152
152
|
type = :integer
|
153
153
|
options[:primary_key] = true
|
@@ -456,13 +456,11 @@ module ActiveRecord
|
|
456
456
|
end
|
457
457
|
|
458
458
|
protected
|
459
|
-
|
460
459
|
def initialize_load_schema_monitor
|
461
460
|
@load_schema_monitor = Monitor.new
|
462
461
|
end
|
463
462
|
|
464
463
|
private
|
465
|
-
|
466
464
|
def inherited(child_class)
|
467
465
|
super
|
468
466
|
child_class.initialize_load_schema_monitor
|
@@ -480,6 +478,9 @@ module ActiveRecord
|
|
480
478
|
load_schema!
|
481
479
|
|
482
480
|
@schema_loaded = true
|
481
|
+
rescue
|
482
|
+
reload_schema_from_cache # If the schema loading failed half way through, we must reset the state.
|
483
|
+
raise
|
483
484
|
end
|
484
485
|
end
|
485
486
|
|
@@ -354,7 +354,6 @@ module ActiveRecord
|
|
354
354
|
end
|
355
355
|
|
356
356
|
private
|
357
|
-
|
358
357
|
# Generates a writer method for this association. Serves as a point for
|
359
358
|
# accessing the objects in the association. For example, this method
|
360
359
|
# could generate the following:
|
@@ -386,7 +385,6 @@ module ActiveRecord
|
|
386
385
|
end
|
387
386
|
|
388
387
|
private
|
389
|
-
|
390
388
|
# Attribute hash keys that should not be assigned as normal attributes.
|
391
389
|
# These hash keys are nested attributes implementation details.
|
392
390
|
UNASSIGNABLE_KEYS = %w( id _destroy )
|
@@ -54,11 +54,11 @@ module ActiveRecord
|
|
54
54
|
NoTouching.applied_to?(self.class)
|
55
55
|
end
|
56
56
|
|
57
|
-
def touch_later(
|
57
|
+
def touch_later(*, **) # :nodoc:
|
58
58
|
super unless no_touching?
|
59
59
|
end
|
60
60
|
|
61
|
-
def touch(
|
61
|
+
def touch(*, **) # :nodoc:
|
62
62
|
super unless no_touching?
|
63
63
|
end
|
64
64
|
end
|
@@ -466,8 +466,8 @@ module ActiveRecord
|
|
466
466
|
#
|
467
467
|
# Attributes marked as readonly are silently ignored if the record is
|
468
468
|
# being updated.
|
469
|
-
def save(*args, &block)
|
470
|
-
create_or_update(*args, &block)
|
469
|
+
def save(*args, **options, &block)
|
470
|
+
create_or_update(*args, **options, &block)
|
471
471
|
rescue ActiveRecord::RecordInvalid
|
472
472
|
false
|
473
473
|
end
|
@@ -499,8 +499,8 @@ module ActiveRecord
|
|
499
499
|
# being updated.
|
500
500
|
#
|
501
501
|
# Unless an error is raised, returns true.
|
502
|
-
def save!(*args, &block)
|
503
|
-
create_or_update(*args, &block) || raise(RecordNotSaved.new("Failed to save the record", self))
|
502
|
+
def save!(*args, **options, &block)
|
503
|
+
create_or_update(*args, **options, &block) || raise(RecordNotSaved.new("Failed to save the record", self))
|
504
504
|
end
|
505
505
|
|
506
506
|
# Deletes the record in the database and freezes this instance to
|
@@ -870,7 +870,6 @@ module ActiveRecord
|
|
870
870
|
end
|
871
871
|
|
872
872
|
private
|
873
|
-
|
874
873
|
# A hook to be overridden by association modules.
|
875
874
|
def destroy_associations
|
876
875
|
end
|