3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ActiveRecordを使って DB Drop / Create

Posted at

##drop -> create -> 接続まで

require "active_record"

config = {
  :adapter   => "mysql2",
  :encoding  => "utf8",
  :reconnect => true,
  :pool      => 5,
  :database  => "__test__"
}

ActiveRecord::Base.establish_connection(config.merge(:database => "mysql"))
ActiveRecord::Base.connection.drop_database config[:database] rescue nil
ActiveRecord::Base.connection.create_database config[:database]
ActiveRecord::Base.establish_connection(config)
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?