File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
lib/active_record/connection_adapters Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -584,9 +584,20 @@ def add_lock!(sql, options)
584584 sql
585585 end
586586
587- def recreate_database ( name )
587+ def recreate_database ( name )
588+ # Switch to another database or we'll receive a "Database in use" error message.
589+ existing_database = current_database . to_s
590+ if name . to_s == existing_database
591+ # The master database should be available on all SQL Server instances, use that
592+ execute 'USE master'
593+ end
594+
595+ # Recreate the database
588596 drop_database ( name )
589597 create_database ( name )
598+
599+ # Switch back to the database if we switched away from it above
600+ execute "USE #{ existing_database } " if name . to_s == existing_database
590601 end
591602
592603 def drop_database ( name )
You can’t perform that action at this time.
0 commit comments