aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
diff options
context:
space:
mode:
authorCody Cutrer <cody@cutrer.us>2014-01-21 16:56:53 -0700
committerSteve Rice <steve@pagerduty.com>2014-03-25 21:29:14 -0700
commitafa148a4f0ac5e2a446b5fe87881a130e8a24f3d (patch)
treef7c274ecbc55c280e48d1355fe217e0f6a9e1585 /activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
parent470108b6e95a32e017ba3790d5701d8c8e91bf29 (diff)
downloadrails-afa148a4f0ac5e2a446b5fe87881a130e8a24f3d.tar.gz
rails-afa148a4f0ac5e2a446b5fe87881a130e8a24f3d.tar.bz2
rails-afa148a4f0ac5e2a446b5fe87881a130e8a24f3d.zip
create indexes inline in CREATE TABLE for MySQL
This is important, because adding an index on a temporary table after it has been created would commit the transaction Conflicts: activerecord/CHANGELOG.md
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.rb21
1 files changed, 10 insertions, 11 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..59210c345f 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