aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorSteve Rice <steve@steverice.org>2014-03-25 21:13:29 -0700
committerSteve Rice <steve@pagerduty.com>2014-03-25 22:10:43 -0700
commit63c94efccb20c0b398dd90c0d209d6894eb22d92 (patch)
tree2717390d594069f6c82e8c9eb7f98eecebe7c07f /activerecord/lib
parentafa148a4f0ac5e2a446b5fe87881a130e8a24f3d (diff)
downloadrails-63c94efccb20c0b398dd90c0d209d6894eb22d92.tar.gz
rails-63c94efccb20c0b398dd90c0d209d6894eb22d92.tar.bz2
rails-63c94efccb20c0b398dd90c0d209d6894eb22d92.zip
Fixes bugs for using indexes in CREATE TABLE by adding checks for table existence
Also: - updates tests by stubbing table_exists? method - adds entry for creating indexes in CREATE TABLE to changelog
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb2
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb2
2 files changed, 2 insertions, 2 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 59210c345f..23404a5c48 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -795,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(", ")
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
index 96c7d5d7eb..a1748c9261 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -12,7 +12,7 @@ module ActiveRecord
statements = []
statements.concat(o.columns.map { |c| accept c })
statements.concat(o.indexes.map { |(column_name, options)| index_in_create(o.name, column_name, options) })
- create_sql << "(#{statements.join(', ')}) "
+ create_sql << "(#{statements.join(', ')}) " if statements.present?
create_sql << "#{o.options}"
create_sql << " AS #{@conn.to_sql(o.as)}" if o.as
create_sql