diff options
author | Stefan Kanev <stefan.kanev@gmail.com> | 2014-08-01 16:13:38 +0200 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2015-01-19 13:40:13 +0900 |
commit | 48e99a45310f5fec515305e90ff8ee2a6a61bada (patch) | |
tree | fe3354e0de2cf67944349db3b94ac7a4136ae8ec /activerecord/test/cases | |
parent | 53919bbfd2b3232ec66e0cdea7b387725653ab43 (diff) | |
download | rails-48e99a45310f5fec515305e90ff8ee2a6a61bada.tar.gz rails-48e99a45310f5fec515305e90ff8ee2a6a61bada.tar.bz2 rails-48e99a45310f5fec515305e90ff8ee2a6a61bada.zip |
Add an `:if_exists` option to `drop_table`
If set to `if_exists: true`, it generates a statement like:
DROP TABLE IF EXISTS posts
This syntax is supported in the popular SQL servers, that is (at least)
SQLite, PostgreSQL, MySQL, Oracle and MS SQL Sever.
Closes #16366.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/migration/change_schema_test.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/activerecord/test/cases/migration/change_schema_test.rb b/activerecord/test/cases/migration/change_schema_test.rb index b3129a8984..c84e65effc 100644 --- a/activerecord/test/cases/migration/change_schema_test.rb +++ b/activerecord/test/cases/migration/change_schema_test.rb @@ -403,6 +403,17 @@ module ActiveRecord end end + def test_drop_table_if_exists + connection.create_table(:testings) + assert connection.table_exists?(:testings) + connection.drop_table(:testings, if_exists: true) + assert_not connection.table_exists?(:testings) + end + + def test_drop_table_if_exists_nothing_raised + assert_nothing_raised { connection.drop_table(:nonexistent, if_exists: true) } + end + private def testing_table_with_only_foo_attribute connection.create_table :testings, :id => false do |t| |