diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-03-26 17:26:20 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-03-26 17:26:20 -0300 |
commit | fb522a27731e04d149abe68809fa030382931bc3 (patch) | |
tree | c3f70cd34da8df0a6a515e6ce4f189f16ec36828 /activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb | |
parent | 9ed0cf51b467907810ef3959c8e9cdf77370370e (diff) | |
parent | 63c94efccb20c0b398dd90c0d209d6894eb22d92 (diff) | |
download | rails-fb522a27731e04d149abe68809fa030382931bc3.tar.gz rails-fb522a27731e04d149abe68809fa030382931bc3.tar.bz2 rails-fb522a27731e04d149abe68809fa030382931bc3.zip |
Merge pull request #14480 from steverice/mysql-indexes-in-create-table
Create indexes inline in CREATE TABLE 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.rb | 23 |
1 files changed, 11 insertions, 12 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 7f530ec5e4..23404a5c48 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -186,24 +186,23 @@ module ActiveRecord def create_table(table_name, options = {}) td = create_table_definition table_name, options[:temporary], options[:options], options[:as] - if !options[:as] - unless options[:id] == false - pk = options.fetch(:primary_key) { - Base.get_primary_key table_name.to_s.singularize - } - - td.primary_key pk, options.fetch(:id, :primary_key), options - end + unless options[:id] == false || options[:as] + pk = options.fetch(:primary_key) { + Base.get_primary_key table_name.to_s.singularize + } - yield td if block_given? + td.primary_key pk, options.fetch(:id, :primary_key), options end + yield td if block_given? + if options[:force] && table_exists?(table_name) drop_table(table_name, options) end - execute schema_creation.accept td - td.indexes.each_pair { |c,o| add_index table_name, c, o } + result = execute schema_creation.accept td + td.indexes.each_pair { |c,o| add_index table_name, c, o } unless supports_indexes_in_create? + result end # Creates a new join table with the name created using the lexical order of the first two @@ -796,7 +795,7 @@ module ActiveRecord if index_name.length > max_index_length raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' is too long; the limit is #{max_index_length} characters" end - if index_name_exists?(table_name, index_name, false) + if table_exists?(table_name) && index_name_exists?(table_name, index_name, false) raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' already exists" end index_columns = quoted_columns_for_index(column_names, options).join(", ") |