Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
leonid-shevtsov committed Dec 1, 2010
0 parents commit 4e953af
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
pkg/*
*.gem
.bundle
4 changes: 4 additions & 0 deletions Gemfile
@@ -0,0 +1,4 @@
source "http://rubygems.org"

# Specify your gem's dependencies in rails_db_dump.gemspec
gemspec
2 changes: 2 additions & 0 deletions Rakefile
@@ -0,0 +1,2 @@
require 'bundler'
Bundler::GemHelper.install_tasks
3 changes: 3 additions & 0 deletions lib/rails_db_dump.rb
@@ -0,0 +1,3 @@
module RailsDbDump
# Your code goes here...
end
3 changes: 3 additions & 0 deletions lib/rails_db_dump/version.rb
@@ -0,0 +1,3 @@
module RailsDbDump
VERSION = "0.0.1"
end
19 changes: 19 additions & 0 deletions rails_db_dump.gemspec
@@ -0,0 +1,19 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "rails_db_dump/version"

Gem::Specification.new do |s|
s.name = "rails_db_dump"
s.version = RailsDbDump::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["Leonid Shevtsov"]
s.email = ["leonid@shevtsov.me"]
s.homepage = "https://github.com/leonid-shevtsov/rails_db_dump"
s.summary = %q{dump your Rails database with a simple rake task}
s.description = %q{rails_db_dump is a wrapper for the native dumper of whatever database engine you're using, taking access parameters from database.yml. Supports mysql, postgresql and sqlite at the moment.}

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
end
36 changes: 36 additions & 0 deletions tasks/rails_db_dump.rake
@@ -0,0 +1,36 @@
namespace :db do
task :dump do
require 'yaml'
config = YAML.load_file(File.join(Rails.root,'config','database.yml'))[Rails.env]
case config["adapter"]
when /^mysql/
args = {
'host' => '--host',
'port' => '--port',
'socket' => '--socket',
'username' => '--user',
'encoding' => '--default-character-set',
'password' => '--password'
}.map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }.compact
args << config['database']

exec('mysqldump', *args)

when "postgresql"
ENV['PGUSER'] = config["username"] if config["username"]
ENV['PGHOST'] = config["host"] if config["host"]
ENV['PGPORT'] = config["port"].to_s if config["port"]
ENV['PGPASSWORD'] = config["password"].to_s if config["password"]
exec('pg_dump', config["database"])

when "sqlite"
exec('sqlite', config["database"], '.dump')

when "sqlite3"
exec('sqlite3', config['database'], '.dump')

else
abort "Don't know how to dump #{config['database']}."
end
end
end

0 comments on commit 4e953af

Please sign in to comment.