Sha256: 6a41563d9a91f157473a6af45f559cee671a9b622a4bcba15e03f98f21f3a908

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

#!/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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tiny-rails-0.0.1 templates/migrate