mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #23593 from meinac/add_index_option_for_change_table
index option added for change_table migrations
This commit is contained in:
commit
322c5704e5
3 changed files with 22 additions and 0 deletions
|
@ -1,3 +1,15 @@
|
|||
* Added `index` option for `change_table` migration helpers.
|
||||
With this change you can create indexes while adding new
|
||||
columns into the existing tables.
|
||||
|
||||
Example:
|
||||
|
||||
change_table(:languages) do |t|
|
||||
t.string :country_code, index: true
|
||||
end
|
||||
|
||||
*Mehmet Emin İNAÇ*
|
||||
|
||||
* Fix `transaction` reverting for migrations.
|
||||
|
||||
Before: Commands inside a `transaction` in a reverted migration ran uninverted.
|
||||
|
|
|
@ -527,7 +527,9 @@ module ActiveRecord
|
|||
#
|
||||
# See TableDefinition#column for details of the options you can use.
|
||||
def column(column_name, type, options = {})
|
||||
index_options = options.delete(:index)
|
||||
@base.add_column(name, column_name, type, options)
|
||||
index(column_name, index_options.is_a?(Hash) ? index_options : {}) if index_options
|
||||
end
|
||||
|
||||
# Checks to see if a column exists.
|
||||
|
|
|
@ -164,6 +164,14 @@ module ActiveRecord
|
|||
end
|
||||
end
|
||||
|
||||
def test_column_creates_column_with_index
|
||||
with_change_table do |t|
|
||||
@connection.expect :add_column, nil, [:delete_me, :bar, :integer, {}]
|
||||
@connection.expect :add_index, nil, [:delete_me, :bar, {}]
|
||||
t.column :bar, :integer, index: true
|
||||
end
|
||||
end
|
||||
|
||||
def test_index_creates_index
|
||||
with_change_table do |t|
|
||||
@connection.expect :add_index, nil, [:delete_me, :bar, {}]
|
||||
|
|
Loading…
Reference in a new issue