From 5e4c22dfbb6dad676f74ded50b8c2536834a46a7 Mon Sep 17 00:00:00 2001 From: Mehmet Emin INAC Date: Sat, 22 Sep 2018 16:47:57 +0200 Subject: Index option added for change_table migrations In case if we want to add a column into the existing table with index on it, we have to add column and index in two seperate lines. With this feature we don't need to write an extra line to add index for column. We can just use `index` option. Old behaviour in action: ``` change_table(:languages) do |t| t.string :country_code t.index: :country_code end ``` New behaviour in action: ``` change_table(:languages) do |t| t.string :country_code, index: true end ``` Exactly same behaviour is already exist for `create_table` migrations. --- .../active_record/connection_adapters/abstract/schema_definitions.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activerecord/lib/active_record/connection_adapters/abstract') diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb index 582ac516c7..015204c056 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb @@ -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. -- cgit v1.2.3