Skip to content
This repository
Browse code

Fixed that altering join tables in migrations would fail w/ sqlite3 #…

…7453 [TimoMihaljov/brandon]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7484 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 79202b37dc7566e8b8392a44c461a64469f79a77 1 parent 2fba012
David Heinemeier Hansson authored September 15, 2007
2  activerecord/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *SVN*
2 2
 
  3
+* Fixed that altering join tables in migrations would fail w/ sqlite3 #7453 [TimoMihaljov/brandon]
  4
+
3 5
 * Fix association writer with :dependent => :nullify.  #7314 [Jonathan Viney]
4 6
 
5 7
 * OpenBase: update for new lib and latest Rails. Support migrations.  #8748 [dcsesq]
3  activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
@@ -285,6 +285,7 @@ def move_table(from, to, options = {}, &block) #:nodoc:
285 285
         end
286 286
 
287 287
         def copy_table(from, to, options = {}) #:nodoc:
  288
+          options = options.merge(:id => !columns(from).detect{|c| c.name == 'id'}.nil?)
288 289
           create_table(to, options) do |@definition|
289 290
             columns(from).each do |column|
290 291
               column_name = options[:rename] ?
@@ -296,7 +297,7 @@ def copy_table(from, to, options = {}) #:nodoc:
296 297
                 :limit => column.limit, :default => column.default,
297 298
                 :null => column.null)
298 299
             end
299  
-            @definition.primary_key(primary_key(from))
  300
+            @definition.primary_key(primary_key(from)) if primary_key(from)
300 301
             yield @definition if block_given?
301 302
           end
302 303
 
4  activerecord/test/copy_table_test_sqlite.rb
@@ -42,6 +42,10 @@ def test_copy_table_with_index
42 42
     end
43 43
   end
44 44
   
  45
+  def test_copy_table_without_primary_key
  46
+    test_copy_table('developers_projects', 'programmers_projects')
  47
+  end
  48
+  
45 49
 protected
46 50
   def copy_table(from, to, options = {})
47 51
     @connection.copy_table(from, to, {:temporary => true}.merge(options))

0 notes on commit 79202b3

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