From 475dd378acd98b65c5a22f0b19078ea3bede3a3b Mon Sep 17 00:00:00 2001 From: Carl Allen Date: Wed, 1 Dec 2010 16:26:15 -0800 Subject: [PATCH 1/2] DROP DATABASE should use IF EXISTS to prevent exceptions if the database does not exist --- .../abstract/schema_statements.rb | 2 +- .../cases/adapters/mysql/active_schema_test.rb | 4 ++-- .../cases/adapters/mysql2/active_schema_test.rb | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index de7d358..5d86b19 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -237,7 +237,7 @@ module ActiveRecord # Drops a table from the database. def drop_table(table_name, options = {}) - execute "DROP TABLE #{quote_table_name(table_name)}" + execute "DROP TABLE IF EXISTS #{quote_table_name(table_name)}" end # Adds a new column to the named table. diff --git a/activerecord/test/cases/adapters/mysql/active_schema_test.rb b/activerecord/test/cases/adapters/mysql/active_schema_test.rb index 509baac..b3216c6 100644 --- a/activerecord/test/cases/adapters/mysql/active_schema_test.rb +++ b/activerecord/test/cases/adapters/mysql/active_schema_test.rb @@ -39,7 +39,7 @@ class ActiveSchemaTest < ActiveRecord::TestCase end def test_drop_table - assert_equal "DROP TABLE `people`", drop_table(:people) + assert_equal "DROP TABLE IF EXISTS `people`", drop_table(:people) end if current_adapter?(:MysqlAdapter) or current_adapter?(:Mysql2Adapter) @@ -64,7 +64,7 @@ class ActiveSchemaTest < ActiveRecord::TestCase end def test_drop_table_with_specific_database - assert_equal "DROP TABLE `otherdb`.`people`", drop_table('otherdb.people') + assert_equal "DROP TABLE IF EXISTS `otherdb`.`people`", drop_table('otherdb.people') end def test_add_timestamps diff --git a/activerecord/test/cases/adapters/mysql2/active_schema_test.rb b/activerecord/test/cases/adapters/mysql2/active_schema_test.rb index a83399d..c7088e5 100644 --- a/activerecord/test/cases/adapters/mysql2/active_schema_test.rb +++ b/activerecord/test/cases/adapters/mysql2/active_schema_test.rb @@ -39,7 +39,7 @@ class ActiveSchemaTest < ActiveRecord::TestCase end def test_drop_table - assert_equal "DROP TABLE `people`", drop_table(:people) + assert_equal "DROP TABLE IF EXISTS `people`", drop_table(:people) end if current_adapter?(:Mysql2Adapter) @@ -64,7 +64,7 @@ class ActiveSchemaTest < ActiveRecord::TestCase end def test_drop_table_with_specific_database - assert_equal "DROP TABLE `otherdb`.`people`", drop_table('otherdb.people') + assert_equal "DROP TABLE IF EXISTS `otherdb`.`people`", drop_table('otherdb.people') end def test_add_timestamps -- 1.7.3.2