Skip to content

Instantly share code, notes, and snippets.

@marocchino
Created August 28, 2012 08:24
Show Gist options
  • Save marocchino/3496134 to your computer and use it in GitHub Desktop.
Save marocchino/3496134 to your computer and use it in GitHub Desktop.
rake db:schema:dump_all
namespace :db do
namespace :schema do
# desc 'Dump all database schema'
task :dump_all => [:environment, :load_config] do
ActiveRecord::Base.configurations.keys.grep(/_development$/).map{|o|o.sub "_development", ""}.each do |name|
begin
filename = "#{Rails.root}/db/#{name}_schema.rb"
File.open(filename, 'w:utf-8') do |file|
ActiveRecord::Base.establish_connection("#{name}_#{Rails.env}")
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
end
rescue
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment