aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-08-29 12:43:17 +0100
committerJon Leighton <j@jonathanleighton.com>2011-08-29 12:43:39 +0100
commitfd22d040fef48778a519825dd2f0cf2fd73a8965 (patch)
tree06a05d8cdddf9ba193103da91b5a5f1afa68009e
parent4fcd847c8d9fb2b22e1c2e3c840c8d1c590b56b4 (diff)
downloadrails-fd22d040fef48778a519825dd2f0cf2fd73a8965.tar.gz
rails-fd22d040fef48778a519825dd2f0cf2fd73a8965.tar.bz2
rails-fd22d040fef48778a519825dd2f0cf2fd73a8965.zip
Move the bulk alter table code into the abstract mysql adapter, hence it is supported for mysql2 as well now.
-rw-r--r--activerecord/CHANGELOG2
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb42
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql_adapter.rb47
3 files changed, 44 insertions, 47 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index e8d4b9c04e..700e11ff94 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*Rails 3.2.0 (unreleased)*
+* Support bulk change_table in mysql2 adapter, as well as the mysql one. [Jon Leighton]
+
* If multiple parameters are sent representing a date, and some are blank, the
resulting object is nil. In previous releases those values defaulted to 1. This
only affects existing but blank parameters, missing ones still raise an error.
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 548ca83353..4b7c74e0b8 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -140,6 +140,10 @@ module ActiveRecord
true
end
+ def supports_bulk_alter? #:nodoc:
+ true
+ end
+
def native_database_types
NATIVE_DATABASE_TYPES
end
@@ -401,6 +405,21 @@ module ActiveRecord
super(table_name, options.reverse_merge(:options => "ENGINE=InnoDB"))
end
+ def bulk_change_table(table_name, operations) #:nodoc:
+ sqls = operations.map do |command, args|
+ table, arguments = args.shift, args
+ method = :"#{command}_sql"
+
+ if respond_to?(method)
+ send(method, table, *arguments)
+ else
+ raise "Unknown method called : #{method}(#{arguments.inspect})"
+ end
+ end.flatten.join(", ")
+
+ execute("ALTER TABLE #{quote_table_name(table_name)} #{sqls}")
+ end
+
# Renames a table.
#
# Example:
@@ -552,6 +571,29 @@ module ActiveRecord
rename_column_sql
end
+ def remove_column_sql(table_name, *column_names)
+ columns_for_remove(table_name, *column_names).map {|column_name| "DROP #{column_name}" }
+ end
+ alias :remove_columns_sql :remove_column
+
+ def add_index_sql(table_name, column_name, options = {})
+ index_name, index_type, index_columns = add_index_options(table_name, column_name, options)
+ "ADD #{index_type} INDEX #{index_name} (#{index_columns})"
+ end
+
+ def remove_index_sql(table_name, options = {})
+ index_name = index_name_for_remove(table_name, options)
+ "DROP INDEX #{index_name}"
+ end
+
+ def add_timestamps_sql(table_name)
+ [add_column_sql(table_name, :created_at, :datetime), add_column_sql(table_name, :updated_at, :datetime)]
+ end
+
+ def remove_timestamps_sql(table_name)
+ [remove_column_sql(table_name, :updated_at), remove_column_sql(table_name, :created_at)]
+ end
+
private
def supports_views?
diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
index 182db65165..e9bdcc2104 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -97,11 +97,6 @@ module ActiveRecord
connect
end
- # FIXME: Move to abstract adapter
- def supports_bulk_alter? #:nodoc:
- true
- end
-
# Returns true, since this connection adapter supports prepared statement
# caching.
def supports_statement_cache?
@@ -312,48 +307,6 @@ module ActiveRecord
# Transactions aren't supported
end
- # SCHEMA STATEMENTS ========================================
-
- def bulk_change_table(table_name, operations) #:nodoc:
- sqls = operations.map do |command, args|
- table, arguments = args.shift, args
- method = :"#{command}_sql"
-
- if respond_to?(method)
- send(method, table, *arguments)
- else
- raise "Unknown method called : #{method}(#{arguments.inspect})"
- end
- end.flatten.join(", ")
-
- execute("ALTER TABLE #{quote_table_name(table_name)} #{sqls}")
- end
-
- protected
-
- def remove_column_sql(table_name, *column_names)
- columns_for_remove(table_name, *column_names).map {|column_name| "DROP #{column_name}" }
- end
- alias :remove_columns_sql :remove_column
-
- def add_index_sql(table_name, column_name, options = {})
- index_name, index_type, index_columns = add_index_options(table_name, column_name, options)
- "ADD #{index_type} INDEX #{index_name} (#{index_columns})"
- end
-
- def remove_index_sql(table_name, options = {})
- index_name = index_name_for_remove(table_name, options)
- "DROP INDEX #{index_name}"
- end
-
- def add_timestamps_sql(table_name)
- [add_column_sql(table_name, :created_at, :datetime), add_column_sql(table_name, :updated_at, :datetime)]
- end
-
- def remove_timestamps_sql(table_name)
- [remove_column_sql(table_name, :updated_at), remove_column_sql(table_name, :created_at)]
- end
-
private
def exec_stmt(sql, name, binds)