dbdump_command 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README +25 -0
- data/Rakefile +4 -0
- data/bin/dbdump +5 -0
- data/dbdump_command.gemspec +35 -0
- data/install.rb +5 -0
- data/lib/commands/dbdump.rb +104 -0
- data/lib/dbdump_command/version.rb +3 -0
- data/uninstall.rb +2 -0
- metadata +114 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Will Bryant, Sekuda Ltd
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
DbdumpCommand
|
2
|
+
=============
|
3
|
+
|
4
|
+
This plugin adds a script/dbdump command which dumps your Rails database out.
|
5
|
+
|
6
|
+
This master branch supports Rails 3.0. For Rails 2.3, use the rails_2_3 branch.
|
7
|
+
|
8
|
+
Like script/dbconsole, it takes your database connection details from
|
9
|
+
config/database.yml, and supports mysql, postgresql, and sqlite.
|
10
|
+
|
11
|
+
It takes the same options as script/dbconsole, ie. -p to supply the password
|
12
|
+
to your dump program for mysql and postgresql. (Note that for mysql, this
|
13
|
+
means that the password is visible when other users on the system run 'ps'.
|
14
|
+
Postgresql does not have this problem as it uses an environment variable set
|
15
|
+
in ENV before execing and so not visible in ps.)
|
16
|
+
|
17
|
+
|
18
|
+
Example
|
19
|
+
=======
|
20
|
+
|
21
|
+
RAILS_ENV=production script/dbdump -p >mysite_production_`date +%Y-%m-%d`
|
22
|
+
- dumps your production database to a file named like mysite_production_2009-01-27.
|
23
|
+
|
24
|
+
|
25
|
+
Copyright (c) 2009-2011 Will Bryant, Sekuda Ltd, released under the MIT license
|
data/Rakefile
ADDED
data/bin/dbdump
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/dbdump_command/version', __FILE__)
|
3
|
+
|
4
|
+
spec = Gem::Specification.new do |gem|
|
5
|
+
gem.name = 'dbdump_command'
|
6
|
+
gem.version = DbdumpCommand::VERSION
|
7
|
+
gem.summary = "Adds support for displaying your ActiveRecord tables, named scopes, collections, or plain arrays in a table view when working in script/console, shell, or email template."
|
8
|
+
gem.description = <<-EOF
|
9
|
+
This plugin adds a dbdump command which dumps your Rails database out.
|
10
|
+
|
11
|
+
This master branch supports Rails 3.0 and above, as a gem command.
|
12
|
+
For Rails 2.3, use the rails_2_3 branch from github and install as a plugin.
|
13
|
+
|
14
|
+
Like rails dbconsole, it takes your database connection details from
|
15
|
+
config/database.yml, and supports mysql, mysql2, postgresql, and sqlite.
|
16
|
+
|
17
|
+
It takes the same options as rails dbconsole, ie. -p to supply the password
|
18
|
+
to your dump program for mysql and postgresql. (Note that for mysql, this
|
19
|
+
means that the password is visible when other users on the system run 'ps'.
|
20
|
+
Postgresql does not have this problem as it uses an environment variable set
|
21
|
+
in ENV before execing and so not visible in ps.)
|
22
|
+
EOF
|
23
|
+
gem.has_rdoc = false
|
24
|
+
gem.author = "Will Bryant"
|
25
|
+
gem.email = "will.bryant@gmail.com"
|
26
|
+
gem.homepage = "http://github.com/willbryant/dbdump_command"
|
27
|
+
|
28
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
29
|
+
gem.files = `git ls-files`.split("\n")
|
30
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
31
|
+
gem.require_path = "lib"
|
32
|
+
|
33
|
+
gem.add_dependency 'activerecord'
|
34
|
+
gem.add_development_dependency "rake"
|
35
|
+
end
|
data/install.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'yaml'
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
module Rails
|
6
|
+
class DBDump
|
7
|
+
def self.start(app)
|
8
|
+
new(app).start
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(app)
|
12
|
+
@app = app
|
13
|
+
end
|
14
|
+
|
15
|
+
def start
|
16
|
+
include_password = false
|
17
|
+
options = {}
|
18
|
+
OptionParser.new do |opt|
|
19
|
+
opt.banner = "Usage: dbdump [options] [environment]"
|
20
|
+
opt.on("-p", "--include-password", "Automatically provide the password from database.yml") do |v|
|
21
|
+
include_password = true
|
22
|
+
end
|
23
|
+
|
24
|
+
opt.parse!(ARGV)
|
25
|
+
abort opt.to_s unless (0..1).include?(ARGV.size)
|
26
|
+
end
|
27
|
+
|
28
|
+
unless config = YAML::load(ERB.new(IO.read("#{@app.root}/config/database.yml")).result)[Rails.env]
|
29
|
+
abort "No database is configured for the environment '#{Rails.env}'"
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def find_cmd(*commands)
|
34
|
+
dirs_on_path = ENV['PATH'].to_s.split(File::PATH_SEPARATOR)
|
35
|
+
commands += commands.map{|cmd| "#{cmd}.exe"} if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
|
36
|
+
|
37
|
+
full_path_command = nil
|
38
|
+
found = commands.detect do |cmd|
|
39
|
+
dir = dirs_on_path.detect do |path|
|
40
|
+
full_path_command = File.join(path, cmd)
|
41
|
+
File.executable? full_path_command
|
42
|
+
end
|
43
|
+
end
|
44
|
+
found ? full_path_command : abort("Couldn't find database client: #{commands.join(', ')}. Check your $PATH and try again.")
|
45
|
+
end
|
46
|
+
|
47
|
+
case config["adapter"]
|
48
|
+
when /^mysql/
|
49
|
+
args = {
|
50
|
+
'host' => '--host',
|
51
|
+
'port' => '--port',
|
52
|
+
'socket' => '--socket',
|
53
|
+
'username' => '--user',
|
54
|
+
'encoding' => '--default-character-set'
|
55
|
+
}.map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }.compact
|
56
|
+
|
57
|
+
if config['password'] && include_password
|
58
|
+
args << "--password=#{config['password']}"
|
59
|
+
elsif config['password'] && !config['password'].to_s.empty?
|
60
|
+
args << "-p"
|
61
|
+
end
|
62
|
+
|
63
|
+
args << config['database']
|
64
|
+
|
65
|
+
exec(find_cmd('mysqldump', 'mysql5dump'), "--single-transaction", *args)
|
66
|
+
|
67
|
+
when "postgresql"
|
68
|
+
ENV['PGUSER'] = config["username"] if config["username"]
|
69
|
+
ENV['PGHOST'] = config["host"] if config["host"]
|
70
|
+
ENV['PGPORT'] = config["port"].to_s if config["port"]
|
71
|
+
ENV['PGPASSWORD'] = config["password"].to_s if config["password"] && include_password
|
72
|
+
|
73
|
+
args = {
|
74
|
+
'encoding' => '--encoding'
|
75
|
+
}.map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }.compact
|
76
|
+
|
77
|
+
args << config["database"]
|
78
|
+
|
79
|
+
exec(find_cmd('pg_dump'), *args)
|
80
|
+
|
81
|
+
when "sqlite"
|
82
|
+
exec(find_cmd('sqlite'), config["database"], ".dump")
|
83
|
+
|
84
|
+
when "sqlite3"
|
85
|
+
args = []
|
86
|
+
|
87
|
+
args << "-#{options['mode']}" if options['mode']
|
88
|
+
args << "-header" if options['header']
|
89
|
+
args << config['database']
|
90
|
+
args << ".dump"
|
91
|
+
|
92
|
+
exec(find_cmd('sqlite3'), *args)
|
93
|
+
|
94
|
+
else
|
95
|
+
abort "Unknown command-line dump client for #{config['database']}. Submit a dbdump patch to add support!"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# Has to set the RAILS_ENV before config/application is required
|
102
|
+
if ARGV.first && !ARGV.first.index("-") && env = ARGV.first
|
103
|
+
ENV['RAILS_ENV'] = %w(production development test).find { |e| e.index(env) } || env
|
104
|
+
end
|
data/uninstall.rb
ADDED
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dbdump_command
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Will Bryant
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-08-18 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: activerecord
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rake
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
description: |
|
49
|
+
This plugin adds a dbdump command which dumps your Rails database out.
|
50
|
+
|
51
|
+
This master branch supports Rails 3.0 and above, as a gem command.
|
52
|
+
For Rails 2.3, use the rails_2_3 branch from github and install as a plugin.
|
53
|
+
|
54
|
+
Like rails dbconsole, it takes your database connection details from
|
55
|
+
config/database.yml, and supports mysql, mysql2, postgresql, and sqlite.
|
56
|
+
|
57
|
+
It takes the same options as rails dbconsole, ie. -p to supply the password
|
58
|
+
to your dump program for mysql and postgresql. (Note that for mysql, this
|
59
|
+
means that the password is visible when other users on the system run 'ps'.
|
60
|
+
Postgresql does not have this problem as it uses an environment variable set
|
61
|
+
in ENV before execing and so not visible in ps.)
|
62
|
+
|
63
|
+
email: will.bryant@gmail.com
|
64
|
+
executables:
|
65
|
+
- dbdump
|
66
|
+
extensions: []
|
67
|
+
|
68
|
+
extra_rdoc_files: []
|
69
|
+
|
70
|
+
files:
|
71
|
+
- MIT-LICENSE
|
72
|
+
- README
|
73
|
+
- Rakefile
|
74
|
+
- bin/dbdump
|
75
|
+
- dbdump_command.gemspec
|
76
|
+
- install.rb
|
77
|
+
- lib/commands/dbdump.rb
|
78
|
+
- lib/dbdump_command/version.rb
|
79
|
+
- uninstall.rb
|
80
|
+
homepage: http://github.com/willbryant/dbdump_command
|
81
|
+
licenses: []
|
82
|
+
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 3
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
version: "0"
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
hash: 3
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
version: "0"
|
106
|
+
requirements: []
|
107
|
+
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 1.8.15
|
110
|
+
signing_key:
|
111
|
+
specification_version: 3
|
112
|
+
summary: Adds support for displaying your ActiveRecord tables, named scopes, collections, or plain arrays in a table view when working in script/console, shell, or email template.
|
113
|
+
test_files: []
|
114
|
+
|