From fe4d5ea786aa82426735b081b6f1581678222814 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 9 Oct 2006 02:14:36 +0000 Subject: Fixed rename_table on SQLite tables with indexes defined (closes #5942) [brandon@opensoul.org] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5260 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../connection_adapters/sqlite_adapter.rb | 24 ++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'activerecord/lib/active_record/connection_adapters') diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb index db9aa2e717..eb57df3d2f 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb @@ -227,13 +227,13 @@ module ActiveRecord end def rename_table(name, new_name) - move_table(name, new_name) + execute "ALTER TABLE #{name} RENAME TO #{new_name}" end def add_column(table_name, column_name, type, options = {}) #:nodoc: - alter_table(table_name) do |definition| - definition.column(column_name, type, options) - end + super(table_name, column_name, type, options = {}) + # See last paragraph on http://www.sqlite.org/lang_altertable.html + execute "VACUUM" end def remove_column(table_name, column_name) #:nodoc: @@ -316,8 +316,9 @@ module ActiveRecord elsif from == "altered_#{to}" name = name[5..-1] end - - opts = { :name => name } + + # index name can't be the same + opts = { :name => name.gsub(/_(#{from})_/, "_#{to}_") } opts[:unique] = true if index.unique add_index(to, index.columns, opts) end @@ -370,6 +371,17 @@ module ActiveRecord sql end 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| + definition.column(column_name, type, options) + end + end + end class DeprecatedSQLiteAdapter < SQLite2Adapter # :nodoc: -- cgit v1.2.3