From afa148a4f0ac5e2a446b5fe87881a130e8a24f3d Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Tue, 21 Jan 2014 16:56:53 -0700 Subject: 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 --- activerecord/test/cases/adapters/mysql/active_schema_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'activerecord/test/cases/adapters/mysql') diff --git a/activerecord/test/cases/adapters/mysql/active_schema_test.rb b/activerecord/test/cases/adapters/mysql/active_schema_test.rb index e77138eb1d..072aa65000 100644 --- a/activerecord/test/cases/adapters/mysql/active_schema_test.rb +++ b/activerecord/test/cases/adapters/mysql/active_schema_test.rb @@ -116,6 +116,17 @@ class ActiveSchemaTest < ActiveRecord::TestCase end end + def test_indexes_in_create + begin + ActiveRecord::Base.connection.stubs(:index_name_exists?).returns(false) + expected = "CREATE TEMPORARY TABLE `temp` (INDEX `index_temp_on_zip` (`zip`)) ENGINE=InnoDB AS SELECT id, name, zip FROM a_really_complicated_query" + actual = ActiveRecord::Base.connection.create_table(:temp, temporary: true, as: "SELECT id, name, zip FROM a_really_complicated_query") do |t| + t.index :zip + end + assert_equal expected, actual + end + end + private def with_real_execute ActiveRecord::Base.connection.singleton_class.class_eval do -- cgit v1.2.3