Raise when both :force
and :if_not_exists
provided to create_table
Co-authored-by: Allison Phillips <aly@thanx.com>
This commit is contained in:
parent
bad7ff1664
commit
e8bf57894e
@ -293,6 +293,11 @@ def primary_key(table_name)
|
||||
def create_table(table_name, id: :primary_key, primary_key: nil, force: nil, **options, &block)
|
||||
validate_create_table_options!(options)
|
||||
validate_table_length!(table_name) unless options[:_uses_legacy_table_name]
|
||||
|
||||
if force && options.key?(:if_not_exists)
|
||||
raise ArgumentError, "Options `:force` and `:if_not_exists` cannot be used simultaneously."
|
||||
end
|
||||
|
||||
td = build_create_table_definition(table_name, id: id, primary_key: primary_key, force: force, **options, &block)
|
||||
|
||||
if force
|
||||
|
@ -199,6 +199,13 @@ def test_create_table_raises_for_long_table_names
|
||||
connection.drop_table short_name, if_exists: true
|
||||
end
|
||||
|
||||
def test_create_table_with_force_and_if_not_exists
|
||||
connection = Person.lease_connection
|
||||
assert_raises(ArgumentError, match: /Options `:force` and `:if_not_exists` cannot be used simultaneously/) do
|
||||
connection.create_table(:testings, force: true, if_not_exists: true)
|
||||
end
|
||||
end
|
||||
|
||||
def test_create_table_with_indexes_and_if_not_exists_true
|
||||
connection = Person.lease_connection
|
||||
connection.create_table :testings, force: true do |t|
|
||||
|
Loading…
Reference in New Issue
Block a user