aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb9
-rwxr-xr-xactiverecord/lib/active_record/connection_adapters/mysql_adapter.rb4
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb4
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb4
4 files changed, 20 insertions, 1 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 861480d980..366192909e 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -90,6 +90,13 @@ module ActiveRecord
create_sql << ") #{options[:options]}"
execute create_sql
end
+
+ # Renames a table.
+ # ===== Example
+ # rename_table('octopuses', 'octopi')
+ def rename_table(name, new_name)
+ raise NotImplementedError, "rename_table is not implemented"
+ end
# Drops a table from the database.
def drop_table(name)
@@ -109,7 +116,7 @@ module ActiveRecord
# remove_column(:suppliers, :qualification)
def remove_column(table_name, column_name)
execute "ALTER TABLE #{table_name} DROP #{column_name}"
- end
+ end
# Changes the column's definition according to the new options.
# See TableDefinition#column for details of the options you can use.
diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
index 9f38dabdcc..d56e1f90da 100755
--- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -258,6 +258,10 @@ module ActiveRecord
def create_table(name, options = {}) #:nodoc:
super(name, {:options => "ENGINE=InnoDB"}.merge(options))
end
+
+ def rename_table(name, new_name)
+ execute "RENAME TABLE #{name} TO #{new_name}"
+ end
def change_column_default(table_name, column_name, default) #:nodoc:
current_type = select_one("SHOW COLUMNS FROM #{table_name} LIKE '#{column_name}'")["Type"]
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 320ef2752b..b908c10049 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -198,6 +198,10 @@ module ActiveRecord
def schema_search_path #:nodoc:
@schema_search_path ||= query('SHOW search_path')[0][0]
end
+
+ def rename_table(name, new_name)
+ execute "ALTER TABLE #{name} RENAME TO #{new_name}"
+ end
def add_column(table_name, column_name, type, options = {})
native_type = native_database_types[type]
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
index 5c7a93e9d0..8f2b6cda03 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
@@ -214,6 +214,10 @@ module ActiveRecord
execute "DROP INDEX #{index_name}"
end
+
+ def rename_table(name, new_name)
+ move_table(name, new_name)
+ end
def add_column(table_name, column_name, type, options = {}) #:nodoc:
alter_table(table_name) do |definition|