mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
d536ffd591
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 |
||
---|---|---|
.. | ||
active_record/connection_adapters | ||
activejob | ||
assets | ||
cases | ||
fixtures | ||
migrations | ||
models | ||
schema | ||
support | ||
config.example.yml | ||
config.rb |