rails_db_dump 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +7 -1
- data/lib/rails_db_dump/tasks.rb +17 -1
- data/lib/rails_db_dump/version.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -6,7 +6,13 @@ An install-and-forget KISSy wrapper around your database dumper.
|
|
6
6
|
|
7
7
|
rake db:dump
|
8
8
|
|
9
|
-
|
9
|
+
Without parameters the task dumps the current database to standard output.
|
10
|
+
|
11
|
+
Pass a `TABLE_NAME` environment variable to dump a single table:
|
12
|
+
|
13
|
+
rake db:dump TABLE_NAME=locations
|
14
|
+
|
15
|
+
There is also a symmetrical task, `rake db:restore`, which restores the database from standard input.
|
10
16
|
|
11
17
|
## Installation
|
12
18
|
|
data/lib/rails_db_dump/tasks.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
namespace :db do
|
2
|
+
desc "Dump the database to standard output. Pass a TABLE_NAME environment variable to dump a single table"
|
2
3
|
task :dump do
|
3
4
|
require 'yaml'
|
4
5
|
config = YAML.load_file(File.join(Rails.root,'config','database.yml'))[Rails.env]
|
6
|
+
table_name = ENV['TABLE_NAME']
|
7
|
+
|
5
8
|
case config["adapter"]
|
6
9
|
when /^mysql/
|
7
10
|
args = {
|
@@ -13,6 +16,7 @@ namespace :db do
|
|
13
16
|
'password' => '--password'
|
14
17
|
}.map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }.compact
|
15
18
|
args << config['database']
|
19
|
+
args << table_name unless table_name.blank?
|
16
20
|
|
17
21
|
exec('mysqldump', *args)
|
18
22
|
|
@@ -21,16 +25,28 @@ namespace :db do
|
|
21
25
|
ENV['PGHOST'] = config["host"] if config["host"]
|
22
26
|
ENV['PGPORT'] = config["port"].to_s if config["port"]
|
23
27
|
ENV['PGPASSWORD'] = config["password"].to_s if config["password"]
|
24
|
-
|
28
|
+
if table_name.blank?
|
29
|
+
exec('pg_dump', config["database"])
|
30
|
+
else
|
31
|
+
exec('pg_dump', '-t', table_name, config["database"])
|
32
|
+
end
|
25
33
|
|
26
34
|
when "sqlite"
|
35
|
+
raise 'Table dumping not supported with sqlite... yet' unless table_name.blank?
|
27
36
|
exec('sqlite', config["database"], '.dump')
|
28
37
|
|
29
38
|
when "sqlite3"
|
39
|
+
raise 'Table dumping not supported with sqlite... yet' unless table_name.blank?
|
30
40
|
exec('sqlite3', config['database'], '.dump')
|
31
41
|
|
32
42
|
else
|
33
43
|
abort "Don't know how to dump #{config['database']}."
|
34
44
|
end
|
35
45
|
end
|
46
|
+
|
47
|
+
desc "Restore the database from standard input."
|
48
|
+
task :restore do
|
49
|
+
# Doesn't get any simpler than that!
|
50
|
+
exec File.join(Rails.root, 'script', 'dbconsole'), '--include-password'
|
51
|
+
end
|
36
52
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_db_dump
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 0
|
9
8
|
- 1
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Leonid Shevtsov
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-12-
|
18
|
+
date: 2010-12-09 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|