Skip to content

Commit

Permalink
create_table :force => true no longer tries to drop a non-existing table
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Koziarski <michael@koziarski.com>
  • Loading branch information
tarmo authored and NZKoz committed May 7, 2008
1 parent 8877ab5 commit 0a21193
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Expand Up @@ -97,8 +97,8 @@ def create_table(table_name, options = {})

yield table_definition

if options[:force]
drop_table(table_name, options) rescue nil
if options[:force] && table_exists?(table_name)
drop_table(table_name, options)
end

create_sql = "CREATE#{' TEMPORARY' if options[:temporary]} TABLE "
Expand Down
18 changes: 18 additions & 0 deletions activerecord/test/cases/migration_test.rb
Expand Up @@ -209,6 +209,24 @@ def test_create_table_with_primary_key_prefix_as_table_name
ActiveRecord::Base.primary_key_prefix_type = nil
end

uses_mocha('test_create_table_with_force_true_does_not_drop_nonexisting_table') do
def test_create_table_with_force_true_does_not_drop_nonexisting_table
if Person.connection.table_exists?(:testings2)
Person.connection.drop_table :testings2
end

# using a copy as we need the drop_table method to
# continue to work for the ensure block of the test
temp_conn = Person.connection.dup
temp_conn.expects(:drop_table).never
temp_conn.create_table :testings2, :force => true do |t|
t.column :foo, :string
end
ensure
Person.connection.drop_table :testings2 rescue nil
end
end


# SQL Server, Sybase, and SQLite3 will not allow you to add a NOT NULL
# column to a table without a default value.
Expand Down

0 comments on commit 0a21193

Please sign in to comment.