activerecord 6.0.2.2 → 6.0.3.rc1
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 +66 -0
- 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 +4 -11
- data/lib/active_record/associations.rb +1 -1
- data/lib/active_record/associations/alias_tracker.rb +0 -1
- data/lib/active_record/associations/association.rb +5 -9
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +0 -2
- data/lib/active_record/associations/collection_proxy.rb +1 -2
- data/lib/active_record/associations/has_many_association.rb +0 -1
- data/lib/active_record/associations/join_dependency.rb +9 -0
- data/lib/active_record/associations/preloader.rb +0 -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/before_type_cast.rb +0 -1
- data/lib/active_record/attribute_methods/dirty.rb +2 -2
- 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 +3 -3
- 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 +0 -3
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +17 -15
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +0 -1
- 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_statements.rb +47 -30
- data/lib/active_record/connection_adapters/abstract/transaction.rb +4 -5
- data/lib/active_record/connection_adapters/abstract_adapter.rb +7 -3
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +12 -28
- data/lib/active_record/connection_adapters/connection_specification.rb +1 -2
- data/lib/active_record/connection_adapters/mysql/column.rb +1 -1
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +5 -11
- data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +0 -1
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +1 -2
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +8 -8
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +6 -2
- 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/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/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 +5 -2
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +5 -6
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +0 -1
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +3 -3
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +8 -7
- data/lib/active_record/connection_adapters/statement_pool.rb +0 -1
- data/lib/active_record/connection_handling.rb +10 -26
- data/lib/active_record/core.rb +0 -2
- data/lib/active_record/counter_cache.rb +4 -1
- data/lib/active_record/database_configurations/url_config.rb +0 -1
- data/lib/active_record/dynamic_matchers.rb +2 -3
- 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 +0 -3
- data/lib/active_record/gem_version.rb +2 -2
- data/lib/active_record/inheritance.rb +0 -3
- data/lib/active_record/insert_all.rb +3 -3
- 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 +0 -1
- data/lib/active_record/middleware/database_selector/resolver.rb +1 -2
- data/lib/active_record/migration.rb +4 -4
- 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 +0 -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 -1
- data/lib/active_record/railties/collection_cache_association_loading.rb +1 -1
- data/lib/active_record/reflection.rb +8 -8
- data/lib/active_record/relation.rb +12 -1
- data/lib/active_record/relation/batches.rb +0 -1
- data/lib/active_record/relation/calculations.rb +1 -1
- data/lib/active_record/relation/delegation.rb +7 -6
- data/lib/active_record/relation/finder_methods.rb +0 -1
- data/lib/active_record/relation/from_clause.rb +4 -0
- data/lib/active_record/relation/merger.rb +0 -1
- data/lib/active_record/relation/predicate_builder.rb +1 -5
- data/lib/active_record/relation/query_methods.rb +9 -7
- 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/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 -4
- data/lib/active_record/store.rb +1 -1
- data/lib/active_record/suppressor.rb +2 -2
- data/lib/active_record/table_metadata.rb +16 -1
- data/lib/active_record/tasks/mysql_database_tasks.rb +0 -1
- 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_fixtures.rb +1 -1
- data/lib/active_record/timestamp.rb +0 -1
- data/lib/active_record/touch_later.rb +1 -2
- data/lib/active_record/transactions.rb +8 -8
- 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/validations.rb +2 -3
- data/lib/active_record/validations/associated.rb +1 -2
- data/lib/arel.rb +5 -1
- data/lib/arel/predications.rb +5 -6
- data/lib/arel/visitors/depth_first.rb +0 -1
- 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 +0 -1
- data/lib/arel/visitors/visitor.rb +0 -1
- 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 +14 -13
@@ -167,7 +167,6 @@ module ActiveRecord
|
|
167
167
|
end
|
168
168
|
|
169
169
|
private
|
170
|
-
|
171
170
|
def internal_poll(timeout)
|
172
171
|
no_wait_poll || (timeout && wait_poll(timeout))
|
173
172
|
end
|
@@ -331,7 +330,6 @@ module ActiveRecord
|
|
331
330
|
end
|
332
331
|
|
333
332
|
private
|
334
|
-
|
335
333
|
def spawn_thread(frequency)
|
336
334
|
Thread.new(frequency) do |t|
|
337
335
|
running = true
|
@@ -1161,7 +1159,6 @@ module ActiveRecord
|
|
1161
1159
|
end
|
1162
1160
|
|
1163
1161
|
private
|
1164
|
-
|
1165
1162
|
def owner_to_pool
|
1166
1163
|
@owner_to_pool[Process.pid]
|
1167
1164
|
end
|
@@ -182,7 +182,7 @@ module ActiveRecord
|
|
182
182
|
|
183
183
|
# Executes the truncate statement.
|
184
184
|
def truncate(table_name, name = nil)
|
185
|
-
execute(
|
185
|
+
execute(build_truncate_statement(table_name), name)
|
186
186
|
end
|
187
187
|
|
188
188
|
def truncate_tables(*table_names) # :nodoc:
|
@@ -190,9 +190,8 @@ module ActiveRecord
|
|
190
190
|
|
191
191
|
with_multi_statements do
|
192
192
|
disable_referential_integrity do
|
193
|
-
|
194
|
-
|
195
|
-
end
|
193
|
+
statements = build_truncate_statements(table_names)
|
194
|
+
execute_batch(statements, "Truncate Tables")
|
196
195
|
end
|
197
196
|
end
|
198
197
|
end
|
@@ -363,14 +362,12 @@ module ActiveRecord
|
|
363
362
|
def insert_fixtures_set(fixture_set, tables_to_delete = [])
|
364
363
|
fixture_inserts = build_fixture_statements(fixture_set)
|
365
364
|
table_deletes = tables_to_delete.map { |table| "DELETE FROM #{quote_table_name(table)}" }
|
366
|
-
|
365
|
+
statements = table_deletes + fixture_inserts
|
367
366
|
|
368
367
|
with_multi_statements do
|
369
368
|
disable_referential_integrity do
|
370
369
|
transaction(requires_new: true) do
|
371
|
-
|
372
|
-
execute_batch(sql, "Fixtures Load")
|
373
|
-
end
|
370
|
+
execute_batch(statements, "Fixtures Load")
|
374
371
|
end
|
375
372
|
end
|
376
373
|
end
|
@@ -406,8 +403,10 @@ module ActiveRecord
|
|
406
403
|
end
|
407
404
|
|
408
405
|
private
|
409
|
-
def execute_batch(
|
410
|
-
|
406
|
+
def execute_batch(statements, name = nil)
|
407
|
+
statements.each do |statement|
|
408
|
+
execute(statement, name)
|
409
|
+
end
|
411
410
|
end
|
412
411
|
|
413
412
|
DEFAULT_INSERT_VALUE = Arel.sql("DEFAULT").freeze
|
@@ -457,7 +456,7 @@ module ActiveRecord
|
|
457
456
|
end
|
458
457
|
|
459
458
|
manager.values = manager.create_values_list(values_list)
|
460
|
-
manager.
|
459
|
+
visitor.compile(manager.ast)
|
461
460
|
end
|
462
461
|
|
463
462
|
def build_fixture_statements(fixture_set)
|
@@ -467,11 +466,14 @@ module ActiveRecord
|
|
467
466
|
end.compact
|
468
467
|
end
|
469
468
|
|
470
|
-
def
|
471
|
-
|
472
|
-
|
469
|
+
def build_truncate_statement(table_name)
|
470
|
+
"TRUNCATE TABLE #{quote_table_name(table_name)}"
|
471
|
+
end
|
472
|
+
|
473
|
+
def build_truncate_statements(table_names)
|
474
|
+
table_names.map do |table_name|
|
475
|
+
build_truncate_statement(table_name)
|
473
476
|
end
|
474
|
-
combine_multi_statements(truncate_tables)
|
475
477
|
end
|
476
478
|
|
477
479
|
def with_multi_statements
|
@@ -19,7 +19,6 @@ module ActiveRecord
|
|
19
19
|
to: :@conn, private: true
|
20
20
|
|
21
21
|
private
|
22
|
-
|
23
22
|
def visit_AlterTable(o)
|
24
23
|
sql = +"ALTER TABLE #{quote_table_name(o.name)} "
|
25
24
|
sql << o.adds.map { |col| accept col }.join(" ")
|
@@ -28,7 +27,7 @@ module ActiveRecord
|
|
28
27
|
end
|
29
28
|
|
30
29
|
def visit_ColumnDefinition(o)
|
31
|
-
o.sql_type = type_to_sql(o.type, o.options)
|
30
|
+
o.sql_type = type_to_sql(o.type, **o.options)
|
32
31
|
column_sql = +"#{quote_column_name(o.name)} #{o.sql_type}"
|
33
32
|
add_column_options!(column_sql, column_options(o)) unless o.type == :primary_key
|
34
33
|
column_sql
|
@@ -139,7 +139,8 @@ module ActiveRecord
|
|
139
139
|
|
140
140
|
def add_to(table)
|
141
141
|
columns.each do |column_options|
|
142
|
-
|
142
|
+
kwargs = column_options.extract_options!
|
143
|
+
table.column(*column_options, **kwargs)
|
143
144
|
end
|
144
145
|
|
145
146
|
if index
|
@@ -147,7 +148,7 @@ module ActiveRecord
|
|
147
148
|
end
|
148
149
|
|
149
150
|
if foreign_key
|
150
|
-
table.foreign_key(foreign_table_name, foreign_key_options)
|
151
|
+
table.foreign_key(foreign_table_name, **foreign_key_options)
|
151
152
|
end
|
152
153
|
end
|
153
154
|
|
@@ -199,7 +200,7 @@ module ActiveRecord
|
|
199
200
|
# Appends a primary key definition to the table definition.
|
200
201
|
# Can be called multiple times, but this is probably not a good idea.
|
201
202
|
def primary_key(name, type = :primary_key, **options)
|
202
|
-
column(name, type, options.merge(primary_key: true))
|
203
|
+
column(name, type, **options.merge(primary_key: true))
|
203
204
|
end
|
204
205
|
|
205
206
|
##
|
@@ -226,7 +227,7 @@ module ActiveRecord
|
|
226
227
|
module_eval <<-RUBY, __FILE__, __LINE__ + 1
|
227
228
|
def #{column_type}(*names, **options)
|
228
229
|
raise ArgumentError, "Missing column name(s) for #{column_type}" if names.empty?
|
229
|
-
names.each { |name| column(name, :#{column_type}, options) }
|
230
|
+
names.each { |name| column(name, :#{column_type}, **options) }
|
230
231
|
end
|
231
232
|
RUBY
|
232
233
|
end
|
@@ -363,7 +364,6 @@ module ActiveRecord
|
|
363
364
|
def column(name, type, **options)
|
364
365
|
name = name.to_s
|
365
366
|
type = type.to_sym if type
|
366
|
-
options = options.dup
|
367
367
|
|
368
368
|
if @columns_hash[name]
|
369
369
|
if @columns_hash[name].primary_key?
|
@@ -375,7 +375,7 @@ module ActiveRecord
|
|
375
375
|
|
376
376
|
index_options = options.delete(:index)
|
377
377
|
index(name, index_options.is_a?(Hash) ? index_options : {}) if index_options
|
378
|
-
@columns_hash[name] = new_column_definition(name, type, options)
|
378
|
+
@columns_hash[name] = new_column_definition(name, type, **options)
|
379
379
|
self
|
380
380
|
end
|
381
381
|
|
@@ -393,7 +393,7 @@ module ActiveRecord
|
|
393
393
|
indexes << [column_name, options]
|
394
394
|
end
|
395
395
|
|
396
|
-
def foreign_key(table_name, options
|
396
|
+
def foreign_key(table_name, **options) # :nodoc:
|
397
397
|
foreign_keys << [table_name, options]
|
398
398
|
end
|
399
399
|
|
@@ -408,8 +408,8 @@ module ActiveRecord
|
|
408
408
|
options[:precision] = 6
|
409
409
|
end
|
410
410
|
|
411
|
-
column(:created_at, :datetime, options)
|
412
|
-
column(:updated_at, :datetime, options)
|
411
|
+
column(:created_at, :datetime, **options)
|
412
|
+
column(:updated_at, :datetime, **options)
|
413
413
|
end
|
414
414
|
|
415
415
|
# Adds a reference.
|
@@ -421,7 +421,7 @@ module ActiveRecord
|
|
421
421
|
# See {connection.add_reference}[rdoc-ref:SchemaStatements#add_reference] for details of the options you can use.
|
422
422
|
def references(*args, **options)
|
423
423
|
args.each do |ref_name|
|
424
|
-
ReferenceDefinition.new(ref_name, options).add_to(self)
|
424
|
+
ReferenceDefinition.new(ref_name, **options).add_to(self)
|
425
425
|
end
|
426
426
|
end
|
427
427
|
alias :belongs_to :references
|
@@ -476,10 +476,10 @@ module ActiveRecord
|
|
476
476
|
@foreign_key_drops << name
|
477
477
|
end
|
478
478
|
|
479
|
-
def add_column(name, type, options)
|
479
|
+
def add_column(name, type, **options)
|
480
480
|
name = name.to_s
|
481
481
|
type = type.to_sym
|
482
|
-
@adds << AddColumnDefinition.new(@td.new_column_definition(name, type, options))
|
482
|
+
@adds << AddColumnDefinition.new(@td.new_column_definition(name, type, **options))
|
483
483
|
end
|
484
484
|
end
|
485
485
|
|
@@ -540,7 +540,7 @@ module ActiveRecord
|
|
540
540
|
# See TableDefinition#column for details of the options you can use.
|
541
541
|
def column(column_name, type, **options)
|
542
542
|
index_options = options.delete(:index)
|
543
|
-
@base.add_column(name, column_name, type, options)
|
543
|
+
@base.add_column(name, column_name, type, **options)
|
544
544
|
index(column_name, index_options.is_a?(Hash) ? index_options : {}) if index_options
|
545
545
|
end
|
546
546
|
|
@@ -549,8 +549,8 @@ module ActiveRecord
|
|
549
549
|
# t.string(:name) unless t.column_exists?(:name, :string)
|
550
550
|
#
|
551
551
|
# See {connection.column_exists?}[rdoc-ref:SchemaStatements#column_exists?]
|
552
|
-
def column_exists?(column_name, type = nil, options
|
553
|
-
@base.column_exists?(name, column_name, type, options)
|
552
|
+
def column_exists?(column_name, type = nil, **options)
|
553
|
+
@base.column_exists?(name, column_name, type, **options)
|
554
554
|
end
|
555
555
|
|
556
556
|
# Adds a new index to the table. +column_name+ can be a single Symbol, or
|
@@ -590,8 +590,8 @@ module ActiveRecord
|
|
590
590
|
# t.timestamps(null: false)
|
591
591
|
#
|
592
592
|
# See {connection.add_timestamps}[rdoc-ref:SchemaStatements#add_timestamps]
|
593
|
-
def timestamps(options
|
594
|
-
@base.add_timestamps(name, options)
|
593
|
+
def timestamps(**options)
|
594
|
+
@base.add_timestamps(name, **options)
|
595
595
|
end
|
596
596
|
|
597
597
|
# Changes the column's definition according to the new options.
|
@@ -641,8 +641,8 @@ module ActiveRecord
|
|
641
641
|
# t.remove_timestamps
|
642
642
|
#
|
643
643
|
# See {connection.remove_timestamps}[rdoc-ref:SchemaStatements#remove_timestamps]
|
644
|
-
def remove_timestamps(options
|
645
|
-
@base.remove_timestamps(name, options)
|
644
|
+
def remove_timestamps(**options)
|
645
|
+
@base.remove_timestamps(name, **options)
|
646
646
|
end
|
647
647
|
|
648
648
|
# Renames a column.
|
@@ -662,7 +662,7 @@ module ActiveRecord
|
|
662
662
|
# See {connection.add_reference}[rdoc-ref:SchemaStatements#add_reference] for details of the options you can use.
|
663
663
|
def references(*args, **options)
|
664
664
|
args.each do |ref_name|
|
665
|
-
@base.add_reference(name, ref_name, options)
|
665
|
+
@base.add_reference(name, ref_name, **options)
|
666
666
|
end
|
667
667
|
end
|
668
668
|
alias :belongs_to :references
|
@@ -675,7 +675,7 @@ module ActiveRecord
|
|
675
675
|
# See {connection.remove_reference}[rdoc-ref:SchemaStatements#remove_reference]
|
676
676
|
def remove_references(*args, **options)
|
677
677
|
args.each do |ref_name|
|
678
|
-
@base.remove_reference(name, ref_name, options)
|
678
|
+
@base.remove_reference(name, ref_name, **options)
|
679
679
|
end
|
680
680
|
end
|
681
681
|
alias :remove_belongs_to :remove_references
|
@@ -686,8 +686,8 @@ module ActiveRecord
|
|
686
686
|
# t.foreign_key(:authors, column: :author_id, primary_key: "id")
|
687
687
|
#
|
688
688
|
# See {connection.add_foreign_key}[rdoc-ref:SchemaStatements#add_foreign_key]
|
689
|
-
def foreign_key(*args)
|
690
|
-
@base.add_foreign_key(name, *args)
|
689
|
+
def foreign_key(*args, **options)
|
690
|
+
@base.add_foreign_key(name, *args, **options)
|
691
691
|
end
|
692
692
|
|
693
693
|
# Removes the given foreign key from the table.
|
@@ -696,8 +696,8 @@ module ActiveRecord
|
|
696
696
|
# t.remove_foreign_key(column: :author_id)
|
697
697
|
#
|
698
698
|
# See {connection.remove_foreign_key}[rdoc-ref:SchemaStatements#remove_foreign_key]
|
699
|
-
def remove_foreign_key(*args)
|
700
|
-
@base.remove_foreign_key(name, *args)
|
699
|
+
def remove_foreign_key(*args, **options)
|
700
|
+
@base.remove_foreign_key(name, *args, **options)
|
701
701
|
end
|
702
702
|
|
703
703
|
# Checks to see if a foreign key exists.
|
@@ -705,8 +705,8 @@ module ActiveRecord
|
|
705
705
|
# t.foreign_key(:authors) unless t.foreign_key_exists?(:authors)
|
706
706
|
#
|
707
707
|
# See {connection.foreign_key_exists?}[rdoc-ref:SchemaStatements#foreign_key_exists?]
|
708
|
-
def foreign_key_exists?(*args)
|
709
|
-
@base.foreign_key_exists?(name, *args)
|
708
|
+
def foreign_key_exists?(*args, **options)
|
709
|
+
@base.foreign_key_exists?(name, *args, **options)
|
710
710
|
end
|
711
711
|
end
|
712
712
|
end
|
@@ -292,7 +292,7 @@ module ActiveRecord
|
|
292
292
|
#
|
293
293
|
# See also TableDefinition#column for details on how to create columns.
|
294
294
|
def create_table(table_name, **options)
|
295
|
-
td = create_table_definition(table_name, options)
|
295
|
+
td = create_table_definition(table_name, **options)
|
296
296
|
|
297
297
|
if options[:id] != false && !options[:as]
|
298
298
|
pk = options.fetch(:primary_key) do
|
@@ -302,14 +302,14 @@ module ActiveRecord
|
|
302
302
|
if pk.is_a?(Array)
|
303
303
|
td.primary_keys pk
|
304
304
|
else
|
305
|
-
td.primary_key pk, options.fetch(:id, :primary_key), options.except(:comment)
|
305
|
+
td.primary_key pk, options.fetch(:id, :primary_key), **options.except(:comment)
|
306
306
|
end
|
307
307
|
end
|
308
308
|
|
309
309
|
yield td if block_given?
|
310
310
|
|
311
311
|
if options[:force]
|
312
|
-
drop_table(table_name, options
|
312
|
+
drop_table(table_name, **options, if_exists: true)
|
313
313
|
end
|
314
314
|
|
315
315
|
result = execute schema_creation.accept td
|
@@ -378,9 +378,9 @@ module ActiveRecord
|
|
378
378
|
|
379
379
|
t1_ref, t2_ref = [table_1, table_2].map { |t| t.to_s.singularize }
|
380
380
|
|
381
|
-
create_table(join_table_name, options.merge!(id: false)) do |td|
|
382
|
-
td.references t1_ref, column_options
|
383
|
-
td.references t2_ref, column_options
|
381
|
+
create_table(join_table_name, **options.merge!(id: false)) do |td|
|
382
|
+
td.references t1_ref, **column_options
|
383
|
+
td.references t2_ref, **column_options
|
384
384
|
yield td if block_given?
|
385
385
|
end
|
386
386
|
end
|
@@ -391,7 +391,7 @@ module ActiveRecord
|
|
391
391
|
# Although this command ignores the block if one is given, it can be helpful
|
392
392
|
# to provide one in a migration's +change+ method so it can be reverted.
|
393
393
|
# In that case, the block will be used by #create_join_table.
|
394
|
-
def drop_join_table(table_1, table_2, options
|
394
|
+
def drop_join_table(table_1, table_2, **options)
|
395
395
|
join_table_name = find_join_table_name(table_1, table_2, options)
|
396
396
|
drop_table(join_table_name)
|
397
397
|
end
|
@@ -468,7 +468,7 @@ module ActiveRecord
|
|
468
468
|
# end
|
469
469
|
#
|
470
470
|
# See also Table for details on all of the various column transformations.
|
471
|
-
def change_table(table_name, options
|
471
|
+
def change_table(table_name, **options)
|
472
472
|
if supports_bulk_alter? && options[:bulk]
|
473
473
|
recorder = ActiveRecord::Migration::CommandRecorder.new(self)
|
474
474
|
yield update_table_definition(table_name, recorder)
|
@@ -498,7 +498,7 @@ module ActiveRecord
|
|
498
498
|
# Although this command ignores most +options+ and the block if one is given,
|
499
499
|
# it can be helpful to provide these in a migration's +change+ method so it can be reverted.
|
500
500
|
# In that case, +options+ and the block will be used by #create_table.
|
501
|
-
def drop_table(table_name, options
|
501
|
+
def drop_table(table_name, **options)
|
502
502
|
execute "DROP TABLE#{' IF EXISTS' if options[:if_exists]} #{quote_table_name(table_name)}"
|
503
503
|
end
|
504
504
|
|
@@ -587,7 +587,7 @@ module ActiveRecord
|
|
587
587
|
# # ALTER TABLE "shapes" ADD "triangle" polygon
|
588
588
|
def add_column(table_name, column_name, type, **options)
|
589
589
|
at = create_alter_table table_name
|
590
|
-
at.add_column(column_name, type, options)
|
590
|
+
at.add_column(column_name, type, **options)
|
591
591
|
execute schema_creation.accept at
|
592
592
|
end
|
593
593
|
|
@@ -610,8 +610,8 @@ module ActiveRecord
|
|
610
610
|
# to provide these in a migration's +change+ method so it can be reverted.
|
611
611
|
# In that case, +type+ and +options+ will be used by #add_column.
|
612
612
|
# Indexes on the column are automatically removed.
|
613
|
-
def remove_column(table_name, column_name, type = nil, options
|
614
|
-
execute "ALTER TABLE #{quote_table_name(table_name)} #{remove_column_for_alter(table_name, column_name, type, options)}"
|
613
|
+
def remove_column(table_name, column_name, type = nil, **options)
|
614
|
+
execute "ALTER TABLE #{quote_table_name(table_name)} #{remove_column_for_alter(table_name, column_name, type, **options)}"
|
615
615
|
end
|
616
616
|
|
617
617
|
# Changes the column's definition according to the new options.
|
@@ -783,7 +783,7 @@ module ActiveRecord
|
|
783
783
|
#
|
784
784
|
# For more information see the {"Transactional Migrations" section}[rdoc-ref:Migration].
|
785
785
|
def add_index(table_name, column_name, options = {})
|
786
|
-
index_name, index_type, index_columns, index_options = add_index_options(table_name, column_name, options)
|
786
|
+
index_name, index_type, index_columns, index_options = add_index_options(table_name, column_name, **options)
|
787
787
|
execute "CREATE #{index_type} INDEX #{quote_column_name(index_name)} ON #{quote_table_name(table_name)} (#{index_columns})#{index_options}"
|
788
788
|
end
|
789
789
|
|
@@ -902,7 +902,7 @@ module ActiveRecord
|
|
902
902
|
# add_reference(:products, :supplier, foreign_key: {to_table: :firms})
|
903
903
|
#
|
904
904
|
def add_reference(table_name, ref_name, **options)
|
905
|
-
ReferenceDefinition.new(ref_name, options).add_to(update_table_definition(table_name, self))
|
905
|
+
ReferenceDefinition.new(ref_name, **options).add_to(update_table_definition(table_name, self))
|
906
906
|
end
|
907
907
|
alias :add_belongs_to :add_reference
|
908
908
|
|
@@ -930,7 +930,7 @@ module ActiveRecord
|
|
930
930
|
foreign_key_options = { to_table: reference_name }
|
931
931
|
end
|
932
932
|
foreign_key_options[:column] ||= "#{ref_name}_id"
|
933
|
-
remove_foreign_key(table_name, foreign_key_options)
|
933
|
+
remove_foreign_key(table_name, **foreign_key_options)
|
934
934
|
end
|
935
935
|
|
936
936
|
remove_column(table_name, "#{ref_name}_id")
|
@@ -988,7 +988,7 @@ module ActiveRecord
|
|
988
988
|
# Action that happens <tt>ON UPDATE</tt>. Valid values are +:nullify+, +:cascade+ and +:restrict+
|
989
989
|
# [<tt>:validate</tt>]
|
990
990
|
# (PostgreSQL only) Specify whether or not the constraint should be validated. Defaults to +true+.
|
991
|
-
def add_foreign_key(from_table, to_table, options
|
991
|
+
def add_foreign_key(from_table, to_table, **options)
|
992
992
|
return unless supports_foreign_keys?
|
993
993
|
|
994
994
|
options = foreign_key_options(from_table, to_table, options)
|
@@ -1145,22 +1145,22 @@ module ActiveRecord
|
|
1145
1145
|
#
|
1146
1146
|
# add_timestamps(:suppliers, null: true)
|
1147
1147
|
#
|
1148
|
-
def add_timestamps(table_name, options
|
1148
|
+
def add_timestamps(table_name, **options)
|
1149
1149
|
options[:null] = false if options[:null].nil?
|
1150
1150
|
|
1151
1151
|
if !options.key?(:precision) && supports_datetime_with_precision?
|
1152
1152
|
options[:precision] = 6
|
1153
1153
|
end
|
1154
1154
|
|
1155
|
-
add_column table_name, :created_at, :datetime, options
|
1156
|
-
add_column table_name, :updated_at, :datetime, options
|
1155
|
+
add_column table_name, :created_at, :datetime, **options
|
1156
|
+
add_column table_name, :updated_at, :datetime, **options
|
1157
1157
|
end
|
1158
1158
|
|
1159
1159
|
# Removes the timestamp columns (+created_at+ and +updated_at+) from the table definition.
|
1160
1160
|
#
|
1161
1161
|
# remove_timestamps(:suppliers)
|
1162
1162
|
#
|
1163
|
-
def remove_timestamps(table_name, options
|
1163
|
+
def remove_timestamps(table_name, **options)
|
1164
1164
|
remove_column table_name, :updated_at
|
1165
1165
|
remove_column table_name, :created_at
|
1166
1166
|
end
|
@@ -1196,7 +1196,7 @@ module ActiveRecord
|
|
1196
1196
|
if data_source_exists?(table_name) && index_name_exists?(table_name, index_name)
|
1197
1197
|
raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' already exists"
|
1198
1198
|
end
|
1199
|
-
index_columns = quoted_columns_for_index(column_names, options).join(", ")
|
1199
|
+
index_columns = quoted_columns_for_index(column_names, **options).join(", ")
|
1200
1200
|
|
1201
1201
|
[index_name, index_type, index_columns, index_options, algorithm, using, comment]
|
1202
1202
|
end
|
@@ -1253,7 +1253,7 @@ module ActiveRecord
|
|
1253
1253
|
# the PostgreSQL adapter for supporting operator classes.
|
1254
1254
|
def add_options_for_index_columns(quoted_columns, **options)
|
1255
1255
|
if supports_index_sort_order?
|
1256
|
-
quoted_columns = add_index_sort_order(quoted_columns, options)
|
1256
|
+
quoted_columns = add_index_sort_order(quoted_columns, **options)
|
1257
1257
|
end
|
1258
1258
|
|
1259
1259
|
quoted_columns
|
@@ -1263,7 +1263,7 @@ module ActiveRecord
|
|
1263
1263
|
return [column_names] if column_names.is_a?(String)
|
1264
1264
|
|
1265
1265
|
quoted_columns = Hash[column_names.map { |name| [name.to_sym, quote_column_name(name).dup] }]
|
1266
|
-
add_options_for_index_columns(quoted_columns, options).values
|
1266
|
+
add_options_for_index_columns(quoted_columns, **options).values
|
1267
1267
|
end
|
1268
1268
|
|
1269
1269
|
def index_name_for_remove(table_name, options = {})
|
@@ -1322,8 +1322,8 @@ module ActiveRecord
|
|
1322
1322
|
SchemaCreation.new(self)
|
1323
1323
|
end
|
1324
1324
|
|
1325
|
-
def create_table_definition(*args)
|
1326
|
-
TableDefinition.new(self, *args)
|
1325
|
+
def create_table_definition(*args, **options)
|
1326
|
+
TableDefinition.new(self, *args, **options)
|
1327
1327
|
end
|
1328
1328
|
|
1329
1329
|
def create_alter_table(name)
|
@@ -1374,7 +1374,7 @@ module ActiveRecord
|
|
1374
1374
|
|
1375
1375
|
def foreign_key_for(from_table, **options)
|
1376
1376
|
return unless supports_foreign_keys?
|
1377
|
-
foreign_keys(from_table).detect { |fk| fk.defined_for?(options) }
|
1377
|
+
foreign_keys(from_table).detect { |fk| fk.defined_for?(**options) }
|
1378
1378
|
end
|
1379
1379
|
|
1380
1380
|
def foreign_key_for!(from_table, to_table: nil, **options)
|
@@ -1436,20 +1436,37 @@ module ActiveRecord
|
|
1436
1436
|
non_combinable_operations.each(&:call)
|
1437
1437
|
end
|
1438
1438
|
|
1439
|
-
def add_column_for_alter(table_name, column_name, type, options
|
1439
|
+
def add_column_for_alter(table_name, column_name, type, **options)
|
1440
1440
|
td = create_table_definition(table_name)
|
1441
|
-
cd = td.new_column_definition(column_name, type, options)
|
1441
|
+
cd = td.new_column_definition(column_name, type, **options)
|
1442
1442
|
schema_creation.accept(AddColumnDefinition.new(cd))
|
1443
1443
|
end
|
1444
1444
|
|
1445
|
-
def remove_column_for_alter(table_name, column_name, type = nil, options
|
1445
|
+
def remove_column_for_alter(table_name, column_name, type = nil, **options)
|
1446
1446
|
"DROP COLUMN #{quote_column_name(column_name)}"
|
1447
1447
|
end
|
1448
1448
|
|
1449
|
-
def remove_columns_for_alter(table_name, *column_names)
|
1449
|
+
def remove_columns_for_alter(table_name, *column_names, **options)
|
1450
1450
|
column_names.map { |column_name| remove_column_for_alter(table_name, column_name) }
|
1451
1451
|
end
|
1452
1452
|
|
1453
|
+
def add_timestamps_for_alter(table_name, **options)
|
1454
|
+
options[:null] = false if options[:null].nil?
|
1455
|
+
|
1456
|
+
if !options.key?(:precision) && supports_datetime_with_precision?
|
1457
|
+
options[:precision] = 6
|
1458
|
+
end
|
1459
|
+
|
1460
|
+
[
|
1461
|
+
add_column_for_alter(table_name, :created_at, :datetime, **options),
|
1462
|
+
add_column_for_alter(table_name, :updated_at, :datetime, **options)
|
1463
|
+
]
|
1464
|
+
end
|
1465
|
+
|
1466
|
+
def remove_timestamps_for_alter(table_name, **options)
|
1467
|
+
remove_columns_for_alter(table_name, :updated_at, :created_at)
|
1468
|
+
end
|
1469
|
+
|
1453
1470
|
def insert_versions_sql(versions)
|
1454
1471
|
sm_table = quote_table_name(schema_migration.table_name)
|
1455
1472
|
|