public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
create_table :force => true no longer tries to drop a non-existing 
table

Signed-off-by: Michael Koziarski <michael@koziarski.com>
tarmo (author)
Tue May 06 16:08:57 -0700 2008
NZKoz (committer)
Tue May 06 18:01:46 -0700 2008
commit  0a21193dc660396fb993b06d1d3c168a9cd900a5
tree    2e1cff75eefe09a019bd25f3bbec9975ffb8c032
parent  8877ab5852d9a1133eb9a730ae47dde214bafe55
...
97
98
99
100
101
 
 
102
103
104
...
97
98
99
 
 
100
101
102
103
104
0
@@ -97,8 +97,8 @@ module ActiveRecord
0
 
0
         yield table_definition
0
 
0
- if options[:force]
0
- drop_table(table_name, options) rescue nil
0
+ if options[:force] && table_exists?(table_name)
0
+ drop_table(table_name, options)
0
         end
0
 
0
         create_sql = "CREATE#{' TEMPORARY' if options[:temporary]} TABLE "
...
209
210
211
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
213
214
...
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
0
@@ -209,6 +209,24 @@ if ActiveRecord::Base.connection.supports_migrations?
0
       ActiveRecord::Base.primary_key_prefix_type = nil
0
     end
0
 
0
+ uses_mocha('test_create_table_with_force_true_does_not_drop_nonexisting_table') do
0
+ def test_create_table_with_force_true_does_not_drop_nonexisting_table
0
+ if Person.connection.table_exists?(:testings2)
0
+ Person.connection.drop_table :testings2
0
+ end
0
+
0
+ # using a copy as we need the drop_table method to
0
+ # continue to work for the ensure block of the test
0
+ temp_conn = Person.connection.dup
0
+ temp_conn.expects(:drop_table).never
0
+ temp_conn.create_table :testings2, :force => true do |t|
0
+ t.column :foo, :string
0
+ end
0
+ ensure
0
+ Person.connection.drop_table :testings2 rescue nil
0
+ end
0
+ end
0
+
0
 
0
     # SQL Server, Sybase, and SQLite3 will not allow you to add a NOT NULL
0
     # column to a table without a default value.

Comments

    No one has commented yet.