Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make the sqlite adapter preserve not-null constraints and index names…

… when altering tables

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2318 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 1f4dc25250d828dd7f4c2c1c8e1d23c24c3e8d0b 1 parent 11411ef
Jamis Buck jamis authored
15 activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
View
@@ -261,7 +261,8 @@ def copy_table(from, to, options = {}) #:nodoc:
options[:rename][column.name] if options[:rename]
@definition.column(column_name || column.name, column.type,
- :limit => column.limit, :default => column.default)
+ :limit => column.limit, :default => column.default,
+ :null => column.null)
end
@definition.primary_key(primary_key(from))
yield @definition if block_given?
@@ -275,8 +276,16 @@ def copy_table(from, to, options = {}) #:nodoc:
def copy_table_indexes(from, to) #:nodoc:
indexes(from).each do |index|
- type = index[:unique] ? 'UNIQUE' : ''
- add_index(to, index[:columns], type)
+ name = index.name
+ if to == "altered_#{from}"
+ name = "temp_#{name}"
+ elsif from == "altered_#{to}"
+ name = name[5..-1]
+ end
+
+ opts = { :name => name }
+ opts[:unique] = true if index.unique
+ add_index(to, index.columns, opts)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.