Method: Framework::Application#drop_database!

Defined in:
lib/framework/application.rb

#drop_database!(name = nil) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/framework/application.rb', line 71

def drop_database!(name = nil)
  name ||= 'default'
  cfg = database_config[name][env]

  case cfg['adapter']
  when 'postgresql'
    establish_postgres_connection(name)
    ActiveRecord::Base.connection.drop_database(cfg['database'])
  when 'sqlite3'
    require 'pathname'
    path = Pathname.new(cfg['database']).to_s
    FileUtils.rm(path) if File.exist?(path)
  else
    raise "Unknown adapter '#{cfg['adapter']}'"
  end

  puts "The database #{database_config[name][env]['database']} has been successfully dropped"
end