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
@@ -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
|
@@ -15,7 +15,7 @@ module ActiveRecord
|
|
15
15
|
def column_spec_for_primary_key(column)
|
16
16
|
return {} if default_primary_key?(column)
|
17
17
|
spec = { id: schema_type(column).inspect }
|
18
|
-
spec.merge!(prepare_column_options(column).except!(:null))
|
18
|
+
spec.merge!(prepare_column_options(column).except!(:null, :comment))
|
19
19
|
spec[:default] ||= "nil" if explicit_primary_key_default?(column)
|
20
20
|
spec
|
21
21
|
end
|
@@ -101,7 +101,7 @@ module ActiveRecord
|
|
101
101
|
def index_exists?(table_name, column_name, options = {})
|
102
102
|
column_names = Array(column_name).map(&:to_s)
|
103
103
|
checks = []
|
104
|
-
checks << lambda { |i| i.columns == column_names }
|
104
|
+
checks << lambda { |i| Array(i.columns) == column_names }
|
105
105
|
checks << lambda { |i| i.unique } if options[:unique]
|
106
106
|
checks << lambda { |i| i.name == options[:name].to_s } if options[:name]
|
107
107
|
|
@@ -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
|
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
|
|
@@ -518,14 +518,15 @@ module ActiveRecord
|
|
518
518
|
# Available options are (none of these exists by default):
|
519
519
|
# * <tt>:limit</tt> -
|
520
520
|
# Requests a maximum column length. This is the number of characters for a <tt>:string</tt> column
|
521
|
-
# and number of bytes for <tt>:text</tt>, <tt>:binary</tt
|
521
|
+
# and number of bytes for <tt>:text</tt>, <tt>:binary</tt>, and <tt>:integer</tt> columns.
|
522
522
|
# This option is ignored by some backends.
|
523
523
|
# * <tt>:default</tt> -
|
524
524
|
# The column's default value. Use +nil+ for +NULL+.
|
525
525
|
# * <tt>:null</tt> -
|
526
526
|
# Allows or disallows +NULL+ values in the column.
|
527
527
|
# * <tt>:precision</tt> -
|
528
|
-
# Specifies the precision for the <tt>:decimal</tt
|
528
|
+
# Specifies the precision for the <tt>:decimal</tt>, <tt>:numeric</tt>,
|
529
|
+
# <tt>:datetime</tt>, and <tt>:time</tt> columns.
|
529
530
|
# * <tt>:scale</tt> -
|
530
531
|
# Specifies the scale for the <tt>:decimal</tt> and <tt>:numeric</tt> columns.
|
531
532
|
# * <tt>:collation</tt> -
|
@@ -586,7 +587,7 @@ module ActiveRecord
|
|
586
587
|
# # ALTER TABLE "shapes" ADD "triangle" polygon
|
587
588
|
def add_column(table_name, column_name, type, **options)
|
588
589
|
at = create_alter_table table_name
|
589
|
-
at.add_column(column_name, type, options)
|
590
|
+
at.add_column(column_name, type, **options)
|
590
591
|
execute schema_creation.accept at
|
591
592
|
end
|
592
593
|
|
@@ -609,8 +610,8 @@ module ActiveRecord
|
|
609
610
|
# to provide these in a migration's +change+ method so it can be reverted.
|
610
611
|
# In that case, +type+ and +options+ will be used by #add_column.
|
611
612
|
# Indexes on the column are automatically removed.
|
612
|
-
def remove_column(table_name, column_name, type = nil, options
|
613
|
-
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)}"
|
614
615
|
end
|
615
616
|
|
616
617
|
# Changes the column's definition according to the new options.
|
@@ -782,7 +783,7 @@ module ActiveRecord
|
|
782
783
|
#
|
783
784
|
# For more information see the {"Transactional Migrations" section}[rdoc-ref:Migration].
|
784
785
|
def add_index(table_name, column_name, options = {})
|
785
|
-
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)
|
786
787
|
execute "CREATE #{index_type} INDEX #{quote_column_name(index_name)} ON #{quote_table_name(table_name)} (#{index_columns})#{index_options}"
|
787
788
|
end
|
788
789
|
|
@@ -901,7 +902,7 @@ module ActiveRecord
|
|
901
902
|
# add_reference(:products, :supplier, foreign_key: {to_table: :firms})
|
902
903
|
#
|
903
904
|
def add_reference(table_name, ref_name, **options)
|
904
|
-
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))
|
905
906
|
end
|
906
907
|
alias :add_belongs_to :add_reference
|
907
908
|
|
@@ -929,7 +930,7 @@ module ActiveRecord
|
|
929
930
|
foreign_key_options = { to_table: reference_name }
|
930
931
|
end
|
931
932
|
foreign_key_options[:column] ||= "#{ref_name}_id"
|
932
|
-
remove_foreign_key(table_name, foreign_key_options)
|
933
|
+
remove_foreign_key(table_name, **foreign_key_options)
|
933
934
|
end
|
934
935
|
|
935
936
|
remove_column(table_name, "#{ref_name}_id")
|
@@ -987,7 +988,7 @@ module ActiveRecord
|
|
987
988
|
# Action that happens <tt>ON UPDATE</tt>. Valid values are +:nullify+, +:cascade+ and +:restrict+
|
988
989
|
# [<tt>:validate</tt>]
|
989
990
|
# (PostgreSQL only) Specify whether or not the constraint should be validated. Defaults to +true+.
|
990
|
-
def add_foreign_key(from_table, to_table, options
|
991
|
+
def add_foreign_key(from_table, to_table, **options)
|
991
992
|
return unless supports_foreign_keys?
|
992
993
|
|
993
994
|
options = foreign_key_options(from_table, to_table, options)
|
@@ -1060,8 +1061,8 @@ module ActiveRecord
|
|
1060
1061
|
options
|
1061
1062
|
end
|
1062
1063
|
|
1063
|
-
def dump_schema_information
|
1064
|
-
versions =
|
1064
|
+
def dump_schema_information # :nodoc:
|
1065
|
+
versions = schema_migration.all_versions
|
1065
1066
|
insert_versions_sql(versions) if versions.any?
|
1066
1067
|
end
|
1067
1068
|
|
@@ -1077,7 +1078,7 @@ module ActiveRecord
|
|
1077
1078
|
end
|
1078
1079
|
|
1079
1080
|
version = version.to_i
|
1080
|
-
sm_table = quote_table_name(
|
1081
|
+
sm_table = quote_table_name(schema_migration.table_name)
|
1081
1082
|
|
1082
1083
|
migrated = migration_context.get_all_versions
|
1083
1084
|
versions = migration_context.migrations.map(&:version)
|
@@ -1144,22 +1145,22 @@ module ActiveRecord
|
|
1144
1145
|
#
|
1145
1146
|
# add_timestamps(:suppliers, null: true)
|
1146
1147
|
#
|
1147
|
-
def add_timestamps(table_name, options
|
1148
|
+
def add_timestamps(table_name, **options)
|
1148
1149
|
options[:null] = false if options[:null].nil?
|
1149
1150
|
|
1150
1151
|
if !options.key?(:precision) && supports_datetime_with_precision?
|
1151
1152
|
options[:precision] = 6
|
1152
1153
|
end
|
1153
1154
|
|
1154
|
-
add_column table_name, :created_at, :datetime, options
|
1155
|
-
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
|
1156
1157
|
end
|
1157
1158
|
|
1158
1159
|
# Removes the timestamp columns (+created_at+ and +updated_at+) from the table definition.
|
1159
1160
|
#
|
1160
1161
|
# remove_timestamps(:suppliers)
|
1161
1162
|
#
|
1162
|
-
def remove_timestamps(table_name, options
|
1163
|
+
def remove_timestamps(table_name, **options)
|
1163
1164
|
remove_column table_name, :updated_at
|
1164
1165
|
remove_column table_name, :created_at
|
1165
1166
|
end
|
@@ -1195,7 +1196,7 @@ module ActiveRecord
|
|
1195
1196
|
if data_source_exists?(table_name) && index_name_exists?(table_name, index_name)
|
1196
1197
|
raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' already exists"
|
1197
1198
|
end
|
1198
|
-
index_columns = quoted_columns_for_index(column_names, options).join(", ")
|
1199
|
+
index_columns = quoted_columns_for_index(column_names, **options).join(", ")
|
1199
1200
|
|
1200
1201
|
[index_name, index_type, index_columns, index_options, algorithm, using, comment]
|
1201
1202
|
end
|
@@ -1252,7 +1253,7 @@ module ActiveRecord
|
|
1252
1253
|
# the PostgreSQL adapter for supporting operator classes.
|
1253
1254
|
def add_options_for_index_columns(quoted_columns, **options)
|
1254
1255
|
if supports_index_sort_order?
|
1255
|
-
quoted_columns = add_index_sort_order(quoted_columns, options)
|
1256
|
+
quoted_columns = add_index_sort_order(quoted_columns, **options)
|
1256
1257
|
end
|
1257
1258
|
|
1258
1259
|
quoted_columns
|
@@ -1262,7 +1263,7 @@ module ActiveRecord
|
|
1262
1263
|
return [column_names] if column_names.is_a?(String)
|
1263
1264
|
|
1264
1265
|
quoted_columns = Hash[column_names.map { |name| [name.to_sym, quote_column_name(name).dup] }]
|
1265
|
-
add_options_for_index_columns(quoted_columns, options).values
|
1266
|
+
add_options_for_index_columns(quoted_columns, **options).values
|
1266
1267
|
end
|
1267
1268
|
|
1268
1269
|
def index_name_for_remove(table_name, options = {})
|
@@ -1321,8 +1322,8 @@ module ActiveRecord
|
|
1321
1322
|
SchemaCreation.new(self)
|
1322
1323
|
end
|
1323
1324
|
|
1324
|
-
def create_table_definition(*args)
|
1325
|
-
TableDefinition.new(self, *args)
|
1325
|
+
def create_table_definition(*args, **options)
|
1326
|
+
TableDefinition.new(self, *args, **options)
|
1326
1327
|
end
|
1327
1328
|
|
1328
1329
|
def create_alter_table(name)
|
@@ -1373,7 +1374,7 @@ module ActiveRecord
|
|
1373
1374
|
|
1374
1375
|
def foreign_key_for(from_table, **options)
|
1375
1376
|
return unless supports_foreign_keys?
|
1376
|
-
foreign_keys(from_table).detect { |fk| fk.defined_for?(options) }
|
1377
|
+
foreign_keys(from_table).detect { |fk| fk.defined_for?(**options) }
|
1377
1378
|
end
|
1378
1379
|
|
1379
1380
|
def foreign_key_for!(from_table, to_table: nil, **options)
|
@@ -1435,22 +1436,39 @@ module ActiveRecord
|
|
1435
1436
|
non_combinable_operations.each(&:call)
|
1436
1437
|
end
|
1437
1438
|
|
1438
|
-
def add_column_for_alter(table_name, column_name, type, options
|
1439
|
+
def add_column_for_alter(table_name, column_name, type, **options)
|
1439
1440
|
td = create_table_definition(table_name)
|
1440
|
-
cd = td.new_column_definition(column_name, type, options)
|
1441
|
+
cd = td.new_column_definition(column_name, type, **options)
|
1441
1442
|
schema_creation.accept(AddColumnDefinition.new(cd))
|
1442
1443
|
end
|
1443
1444
|
|
1444
|
-
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)
|
1445
1446
|
"DROP COLUMN #{quote_column_name(column_name)}"
|
1446
1447
|
end
|
1447
1448
|
|
1448
|
-
def remove_columns_for_alter(table_name, *column_names)
|
1449
|
+
def remove_columns_for_alter(table_name, *column_names, **options)
|
1449
1450
|
column_names.map { |column_name| remove_column_for_alter(table_name, column_name) }
|
1450
1451
|
end
|
1451
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
|
+
|
1452
1470
|
def insert_versions_sql(versions)
|
1453
|
-
sm_table = quote_table_name(
|
1471
|
+
sm_table = quote_table_name(schema_migration.table_name)
|
1454
1472
|
|
1455
1473
|
if versions.is_a?(Array)
|
1456
1474
|
sql = +"INSERT INTO #{sm_table} (version) VALUES\n"
|