#!/usr/bin/env ruby require './boot' # TODO: Alert that DB will be dropped def drop_database(config) case config['adapter'] when /mysql/ ActiveRecord::Base.establish_connection(config) ActiveRecord::Base.connection.drop_database config['database'] when /sqlite/ require 'pathname' path = Pathname.new(config['database']) file = path.absolute? ? path.to_s : File.join(Rails.root, path) FileUtils.rm(file) when /postgresql/ ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public')) ActiveRecord::Base.connection.drop_database config['database'] end end ActiveRecord::Base.configurations.each_value do |config| # Skip entries that don't have a database key next unless config['database'] begin drop_database(config) rescue Exception => e $stderr.puts "Couldn't drop #{config['database']} : #{e.inspect}" end end ActiveRecord::Schema.define do create_table "accounts" do |t| t.string "name" end end