Skip to content
This repository
Browse code

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 authored September 24, 2005
15  activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
@@ -261,7 +261,8 @@ def copy_table(from, to, options = {}) #:nodoc:
261 261
                 options[:rename][column.name] if options[:rename]
262 262
               
263 263
               @definition.column(column_name || column.name, column.type, 
264  
-                :limit => column.limit, :default => column.default)
  264
+                :limit => column.limit, :default => column.default,
  265
+                :null => column.null)
265 266
             end
266 267
             @definition.primary_key(primary_key(from))
267 268
             yield @definition if block_given?
@@ -275,8 +276,16 @@ def copy_table(from, to, options = {}) #:nodoc:
275 276
         
276 277
         def copy_table_indexes(from, to) #:nodoc:
277 278
           indexes(from).each do |index|
278  
-            type = index[:unique] ? 'UNIQUE' : ''
279  
-            add_index(to, index[:columns], type)
  279
+            name = index.name
  280
+            if to == "altered_#{from}"
  281
+              name = "temp_#{name}"
  282
+            elsif from == "altered_#{to}"
  283
+              name = name[5..-1]
  284
+            end
  285
+
  286
+            opts = { :name => name }
  287
+            opts[:unique] = true if index.unique
  288
+            add_index(to, index.columns, opts)
280 289
           end
281 290
         end
282 291
         

0 notes on commit 1f4dc25

Please sign in to comment.
Something went wrong with that request. Please try again.