1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/test
Jess Bees d536ffd591 Raise an exception when using unrecognized options in change_table block
In a database migration, the expressions `add_column`, `remove_index`,
etc. accept as keyword options `if_exists: true`/`if_not_exists: true`
which will skip that table alteration if the column or index does or
does not already exist.

This might lead some to think that within a change_table block,
```
change_table(:table) do |t|
	t.column :new_column, if_not_exists: true
	t.remove_index :old_column, if_exists: true
end
```
also works, but it doesn't. Or rather, it is silently ignored when
change_table is called with `bulk: true`, and it works accidentally
otherwise.

This commit raises an exception when these options are used in a
change_table block, which suggests the similar syntax:
`t.column :new_column unless t.column_exists?(:new_column)`. This
suggestion is already made in the documentation to
`ActiveRecord::ConnectionAdapters::Table`.
https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/Table.html#method-i-column_exists-3F

Do not raise these new exceptions on migrations before 7.0
2021-12-16 11:41:52 -05:00
..
active_record/connection_adapters
activejob Revert "Run ActiveRecord -> ActiveJob integration tests in CI" 2021-06-15 11:19:04 -04:00
assets
cases Raise an exception when using unrecognized options in change_table block 2021-12-16 11:41:52 -05:00
fixtures Use to_formatted_s(:db) instead of to_s(:db) internally 2021-12-06 19:22:04 +00:00
migrations Sort migration ID as int in db:migrate:status for consistency. 2021-07-16 13:10:31 -05:00
models Add authenticate_by when using has_secure_password 2021-12-03 10:06:43 -06:00
schema Add authenticate_by when using has_secure_password 2021-12-03 10:06:43 -06:00
support Rename adapter_short to adapter_name 2021-09-21 08:26:04 +09:00
config.example.yml Allow using a different socket to test mysql 2021-08-05 14:27:30 -04:00
config.rb Delete AS::Dependencies.safe_constantize 2021-08-20 17:51:05 +02:00