aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
diff options
context:
space:
mode:
authorKen Mazaika <kenmazaika@gmail.com>2013-03-27 00:30:11 -0400
committerKen Mazaika <kenmazaika@gmail.com>2013-03-27 23:35:54 -0400
commit9600e0b02973ce5dd36642511d542a6b62983a5e (patch)
tree9f8317610a85ef1e74b49ac08cbc329a03be6908 /activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
parent0739d146bcd31247391d64b852885634d78e576d (diff)
downloadrails-9600e0b02973ce5dd36642511d542a6b62983a5e.tar.gz
rails-9600e0b02973ce5dd36642511d542a6b62983a5e.tar.bz2
rails-9600e0b02973ce5dd36642511d542a6b62983a5e.zip
Add support for FULLTEXT and SPATIAL indexes using the :type flag for MySQL.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb15
1 files changed, 14 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
index e95e97e4a8..aebcc2d874 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -498,13 +498,25 @@ module ActiveRecord
# CREATE UNIQUE INDEX index_accounts_on_branch_id_and_party_id ON accounts(branch_id, party_id) WHERE active
#
# ====== Creating an index with a specific method
+ #
# add_index(:developers, :name, :using => 'btree')
+ #
# generates
+ #
# CREATE INDEX index_developers_on_name ON developers USING btree (name) -- PostgreSQL
# CREATE INDEX index_developers_on_name USING btree ON developers (name) -- MySQL
#
# Note: only supported by PostgreSQL and MySQL
#
+ # ====== Creating an index with a specific type
+ #
+ # add_index(:developers, :name, :type => :fulltext)
+ #
+ # generates
+ #
+ # CREATE FULLTEXT INDEX index_developers_on_name ON developers (name) -- MySQL
+ #
+ # Note: only supported by MySQL. Supported: <tt>:fulltext</tt> and <tt>:spatial</tt> on MyISAM tables.
def add_index(table_name, column_name, options = {})
index_name, index_type, index_columns, index_options = add_index_options(table_name, column_name, options)
execute "CREATE #{index_type} INDEX #{quote_column_name(index_name)} ON #{quote_table_name(table_name)} (#{index_columns})#{index_options}"
@@ -755,9 +767,10 @@ module ActiveRecord
index_name = index_name(table_name, column: column_names)
if Hash === options # legacy support, since this param was a string
- options.assert_valid_keys(:unique, :order, :name, :where, :length, :internal, :using, :algorithm)
+ options.assert_valid_keys(:unique, :order, :name, :where, :length, :internal, :using, :algorithm, :type)
index_type = options[:unique] ? "UNIQUE" : ""
+ index_type = options[:type].to_s if options.key?(:type)
index_name = options[:name].to_s if options.key?(:name)
max_index_length = options.fetch(:internal, false) ? index_name_length : allowed_index_name_length