Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4e953af
Showing
7 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pkg/* | ||
*.gem | ||
.bundle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source "http://rubygems.org" | ||
|
||
# Specify your gem's dependencies in rails_db_dump.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'bundler' | ||
Bundler::GemHelper.install_tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module RailsDbDump | ||
# Your code goes here... | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module RailsDbDump | ||
VERSION = "0.0.1" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |