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/sqlite_adapter.rb24
1 files changed, 18 insertions, 6 deletions
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: