dumper 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,9 +10,10 @@ module Dumper
10
10
  autoload :VERSION, 'dumper/version'
11
11
 
12
12
  module Database
13
- autoload :Base, 'dumper/database/base'
14
- autoload :MySQL, 'dumper/database/mysql'
15
- autoload :MongoDB, 'dumper/database/mongodb'
16
- autoload :Redis, 'dumper/database/redis'
13
+ autoload :Base, 'dumper/database/base'
14
+ autoload :MySQL, 'dumper/database/mysql'
15
+ autoload :PostgreSQL, 'dumper/database/postgresql'
16
+ autoload :MongoDB, 'dumper/database/mongodb'
17
+ autoload :Redis, 'dumper/database/redis'
17
18
  end
18
19
  end
@@ -22,7 +22,7 @@ module Dumper
22
22
  def initialize(options = {})
23
23
  log 'app_key is missing' if options[:app_key].blank?
24
24
 
25
- @stack = Dumper::Stack.new
25
+ @stack = Dumper::Stack.new(options)
26
26
  @api_base = options[:api_base] || 'http://dumper.io'
27
27
  @app_key = options[:app_key]
28
28
  @app_env = @stack.rails_env
@@ -3,7 +3,7 @@ module Dumper
3
3
  class Base
4
4
  include Dumper::Utility::ObjectFinder
5
5
 
6
- attr_accessor :tmpdir, :filename
6
+ attr_accessor :tmpdir, :filename, :config
7
7
 
8
8
  def initialize(stack = nil)
9
9
  @stack = stack
@@ -10,8 +10,8 @@ module Dumper
10
10
 
11
11
  def connection_options
12
12
  [ :database, :host, :port, :username, :password ].map do |option|
13
- next if @stack.configs[:mongodb][option].blank?
14
- "--#{option}='#{@stack.configs[:mongodb][option]}'".gsub('--database', '--db')
13
+ next if @config.send(option).blank?
14
+ "--#{option}='#{@config.send(option)}'".gsub('--database', '--db')
15
15
  end.compact.join(' ')
16
16
  end
17
17
 
@@ -5,13 +5,13 @@ module Dumper
5
5
  FILE_EXT = 'sql.gz'
6
6
 
7
7
  def command
8
- "cd #{tmpdir} && #{dump_tool_path} #{connection_options} #{additional_options} #{@stack.configs[:mysql][:database]} | gzip > #{filename}"
8
+ "cd #{tmpdir} && #{dump_tool_path} #{connection_options} #{additional_options} #{@config.database} | gzip > #{filename}"
9
9
  end
10
10
 
11
11
  def connection_options
12
12
  [ :host, :port, :username, :password ].map do |option|
13
- next if @stack.configs[:mysql][option].blank?
14
- "--#{option}='#{@stack.configs[:mysql][option]}'".gsub('--username', '--user')
13
+ next if @config.send(option).blank?
14
+ "--#{option}='#{@config.send(option)}'".gsub('--username', '--user')
15
15
  end.compact.join(' ')
16
16
  end
17
17
 
@@ -0,0 +1,39 @@
1
+ module Dumper
2
+ module Database
3
+ class PostgreSQL < Base
4
+ DUMP_TOOL = 'pg_dump'
5
+ FILE_EXT = 'sql.gz'
6
+
7
+ def command
8
+ "cd #{tmpdir} && #{password_variable} #{dump_tool_path} #{connection_options} #{@config.database} | gzip > #{filename}"
9
+ end
10
+
11
+ def connection_options
12
+ [ :host, :port, :socket ].map do |option|
13
+ next if @config.send(option).blank?
14
+ "--#{option}='#{@config.send(option)}'".gsub('--socket', '--host')
15
+ end.compact.join(' ')
16
+ end
17
+
18
+ def password_variable
19
+ @config.password.blank? ? '' : "PGPASSWORD='#{@config.password}'"
20
+ end
21
+
22
+ def config_for(rails_env=nil)
23
+ return unless defined?(ActiveRecord::Base) &&
24
+ ActiveRecord::Base.configurations &&
25
+ (config = ActiveRecord::Base.configurations[rails_env]) &&
26
+ (config['adapter'] == 'postgresql')
27
+
28
+ {
29
+ :host => config['host'],
30
+ :port => config['port'],
31
+ :username => config['username'],
32
+ :password => config['password'],
33
+ :database => config['database'],
34
+ :dump_tool => dump_tool_path
35
+ }
36
+ end
37
+ end
38
+ end
39
+ end
@@ -6,7 +6,7 @@ module Dumper
6
6
 
7
7
  def command
8
8
  uncompressed = filename.sub('.gz','')
9
- "cd #{tmpdir} && cp #{@stack.configs[:redis][:dbpath]} #{uncompressed} && gzip #{uncompressed}"
9
+ "cd #{tmpdir} && cp #{@config.dbpath} #{uncompressed} && gzip #{uncompressed}"
10
10
  end
11
11
 
12
12
  def config_for(rails_env=nil)
@@ -1,3 +1,4 @@
1
+ require 'ostruct'
1
2
  require 'posix/spawn'
2
3
 
3
4
  module Dumper
@@ -25,15 +26,12 @@ module Dumper
25
26
 
26
27
  def perform(server)
27
28
  # Initialize database
28
- case server[:type]
29
- when 'mysql'
30
- @database = Dumper::Database::MySQL.new(@stack)
31
- when 'mongodb'
32
- @database = Dumper::Database::MongoDB.new(@stack)
33
- when 'redis'
34
- @database = Dumper::Database::Redis.new(@stack)
29
+ server_type = server[:type].to_sym
30
+ if Dumper::Stack::DATABASES.keys.include?(server_type)
31
+ @database = Dumper::Stack::DATABASES[server_type].new(@stack)
32
+ @database.config = OpenStruct.new(@stack.configs[Dumper::Stack::DATABASES.key(@database.class)])
35
33
  else
36
- abort_with "invalid server type: #{server[:type]}"
34
+ abort_with "invalid server type: #{server_type}"
37
35
  end
38
36
 
39
37
  # Prepare
@@ -3,14 +3,15 @@ module Dumper
3
3
  include Dumper::Utility::ObjectFinder
4
4
 
5
5
  DATABASES = {
6
- :mysql => Dumper::Database::MySQL,
7
- :mongodb => Dumper::Database::MongoDB,
8
- :redis => Dumper::Database::Redis,
6
+ :mysql => Dumper::Database::MySQL,
7
+ :postgresql => Dumper::Database::PostgreSQL,
8
+ :mongodb => Dumper::Database::MongoDB,
9
+ :redis => Dumper::Database::Redis,
9
10
  }
10
11
 
11
12
  attr_accessor :rails_env, :dispatcher, :framework, :rackup, :configs
12
13
 
13
- def initialize
14
+ def initialize(options = {})
14
15
  @configs = {}
15
16
 
16
17
  # Rackup?
@@ -23,7 +24,8 @@ module Dumper
23
24
  @rails_version = Rails::VERSION::STRING
24
25
  @is_supported_rails_version = (::Rails::VERSION::MAJOR >= 3)
25
26
  DATABASES.each do |key, klass|
26
- next unless config = klass.new.config_for(@rails_env)
27
+ database = klass.new
28
+ next unless config = database.config_for(@rails_env) || database.config_for(options[:additional_env])
27
29
  @configs[key] = config
28
30
  end
29
31
 
@@ -1,3 +1,3 @@
1
1
  module Dumper
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dumper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-03 00:00:00.000000000 Z
12
+ date: 2012-06-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json
@@ -114,6 +114,7 @@ files:
114
114
  - lib/dumper/database/base.rb
115
115
  - lib/dumper/database/mongodb.rb
116
116
  - lib/dumper/database/mysql.rb
117
+ - lib/dumper/database/postgresql.rb
117
118
  - lib/dumper/database/redis.rb
118
119
  - lib/dumper/dependency.rb
119
120
  - lib/dumper/job.rb