dumpman 1.2.7

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9da2c005f92e87d46996616037b4b570b40c0c76145e24a13f9e0273044d7a6b
4
+ data.tar.gz: be18187a5fb78467bb939f5718f848988472a8d24b00ebba7baa4951d3ef71c5
5
+ SHA512:
6
+ metadata.gz: 9ab3c888440f173b054630eaaa5017a072dc0fd684e546e7c4c34d8274c43de5df4c5c4f58ffc623f43c02daa36280616a871e38a8fdd3191f966acbd4b47c7b
7
+ data.tar.gz: 5b1fce2f208578bd9ae6acc0c1b4609316d5331c8623c170e5e46bda0df6e495294b2883a6f42b95bb387fb9d1f0f1c219824ebea73019eb4430357cea559c75
@@ -0,0 +1,15 @@
1
+ plugins:
2
+ brakeman:
3
+ enabled: true
4
+ config:
5
+ app_path: spec/dummy
6
+ flog:
7
+ enabled: true
8
+ config:
9
+ score_threshold: 20.0
10
+ reek:
11
+ enabled: true
12
+ rubocop:
13
+ enabled: true
14
+ rubymotion:
15
+ enabled: true
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /spec/dummy/config/database.yml
10
+ /spec/dummy/log/
11
+ /spec/dummy/dumpman.sql
12
+ /spec/dummy/dumpman.sql.zip
13
+ /tmp/
14
+
15
+ # rspec failure tracking
16
+ .rspec_status
@@ -0,0 +1,31 @@
1
+ disallow_single_word:
2
+ enabled: true
3
+
4
+ character_limit:
5
+ enabled: true
6
+ number: 72
7
+
8
+ summary_character_limit:
9
+ enabled: true
10
+ number: 50
11
+
12
+ disallow_generic:
13
+ enabled: true
14
+ words:
15
+ - fix
16
+ - fixed
17
+ - fixes
18
+ - oops
19
+ - todo
20
+ - fixme
21
+ - commit
22
+ - changes
23
+ - hm
24
+ - hmm
25
+ - hmmm
26
+ - test
27
+ - tests
28
+ - quickfix
29
+
30
+ enforce_capitalized:
31
+ enabled: true
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,44 @@
1
+ sudo: false
2
+
3
+ env:
4
+ matrix:
5
+ - DB=pg
6
+ - DB=mysql
7
+
8
+ language: ruby
9
+
10
+ rvm:
11
+ - 2.2.10
12
+ - 2.3.7
13
+ - 2.4.4
14
+ - 2.5.1
15
+
16
+ before_install:
17
+ - gem install bundler -v 1.15.3
18
+
19
+ before_script:
20
+ # coverage
21
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
22
+ - chmod +x ./cc-test-reporter
23
+ - ./cc-test-reporter before-build
24
+
25
+ # pg db setup
26
+ - sh -c "if [ '$DB' = 'pg' ]; then psql -c 'DROP DATABASE IF EXISTS dumpman_test;' -U postgres; fi"
27
+ - sh -c "if [ '$DB' = 'pg' ]; then psql -c 'CREATE DATABASE dumpman_test;' -U postgres; fi"
28
+ - sh -c "if [ '$DB' = 'pg' ]; then cp spec/dummy/config/pg.database.yml.travis spec/dummy/config/database.yml; fi"
29
+
30
+ # mysql db setup
31
+ - sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'CREATE DATABASE IF NOT EXISTS dumpman_test;'; fi"
32
+ - sh -c "if [ '$DB' = 'mysql' ]; then cp spec/dummy/config/mysql.database.yml.travis spec/dummy/config/database.yml; fi"
33
+
34
+ script:
35
+ - bundle exec rspec
36
+ - bundle exec danger
37
+
38
+ after_script:
39
+ # coverage
40
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
41
+
42
+ services:
43
+ - postgresql
44
+ - mysql
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at skcc321@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
@@ -0,0 +1,16 @@
1
+ # Sometimes it's a README fix, or something like that - which isn't relevant for
2
+ # including in a project's CHANGELOG for example
3
+ declared_trivial = github.pr_title.include? "#trivial"
4
+
5
+ # Make it more obvious that a PR is a work in progress and shouldn't be merged yet
6
+ warn("PR is classed as Work in Progress") if github.pr_title.include? "[WIP]"
7
+
8
+ # Warn when there is a big PR
9
+ warn("Big PR") if git.lines_of_code > 500
10
+
11
+ # Don't let testing shortcuts get into master by accident
12
+ fail("fdescribe left in tests") if `grep -r fdescribe spec/ `.length > 1
13
+ fail("fit left in tests") if `grep -r fit spec/ `.length > 1
14
+
15
+ # run pronto linters
16
+ pronto.lint
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 rafael
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,71 @@
1
+ [![Build Status](https://travis-ci.org/skcc321/dumpman.svg?branch=master)](https://travis-ci.org/skcc321/dumpman)
2
+ [![Maintainability](https://api.codeclimate.com/v1/badges/3f69b1bb862be2a7e6ce/maintainability)](https://codeclimate.com/github/skcc321/dumpman/maintainability)
3
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/3f69b1bb862be2a7e6ce/test_coverage)](https://codeclimate.com/github/skcc321/dumpman/test_coverage)
4
+
5
+ # Dumpman
6
+ Dumpman gem is what you need if you have application somewhere and need to dump your DB download it and up that dump localy!
7
+
8
+ ![alt text](https://farm8.staticflickr.com/7347/10602023975_fd3e5b61b7_b.jpg)
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'dumpman', git: 'git@github.com:skcc321/dumpman.git'
16
+ ```
17
+
18
+ Then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install dumpman
25
+
26
+ Generate default config:
27
+
28
+ $ rails g dumpman
29
+
30
+ it will create file app/config/initializers/dumpman.rb
31
+ ```ruby
32
+ Dumpman.setup do
33
+ # dump file name
34
+ dump_file_name "dumpman.sql"
35
+
36
+ # :prod is uniq connection name
37
+ define_source :prod do
38
+ # application environment (RAILS_ENV)
39
+ app_env 'production'
40
+
41
+ # ssh command for connection to the remote server
42
+ ssh_cmd 'root@192.168.1.1'
43
+
44
+ # ssh options for connection to the remote server
45
+ # example:
46
+ # ssh_opts '-i ~/.ssh/sertificate.pem'
47
+
48
+ # app path on the remote server
49
+ app_path '~/application/current'
50
+ end
51
+ end
52
+ ```
53
+
54
+ Update app/config/initializers/dumpman.rb with propper settings.
55
+
56
+ ## Usage
57
+
58
+ Now you are able to use awesome commands:
59
+
60
+ $ rake db:prod:up
61
+ $ rake db:stage:up
62
+ $ rake db:qa:up
63
+ ...
64
+
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome!
68
+
69
+ ## License
70
+
71
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "rake"
4
+ require "zip"
5
+
6
+ Dir[File.join(File.dirname(__FILE__),'lib/tasks/*.rake')].each { |f| load f }
7
+
8
+ RSpec::Core::RakeTask.new(:spec)
9
+
10
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dumpman"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,55 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dumpman/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'dumpman'
8
+ spec.version = Dumpman::VERSION
9
+ spec.authors = ['rafael']
10
+ spec.email = ['skcc321@gmail.com']
11
+
12
+ spec.summary = %q{gem for playing with dumps}
13
+ spec.description = %q{it dumps}
14
+ spec.homepage = 'https://github.com/skcc321/dumpman'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = 'https://github.com/skcc321/dumpman'
21
+ else
22
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+
32
+ spec.add_dependency 'rails', '>= 4.2.8'
33
+ spec.add_dependency 'rake', '>= 12.1.0'
34
+ spec.add_dependency 'rubyzip', '>= 1.2.1'
35
+
36
+ spec.add_development_dependency 'bundler', '>= 1.15'
37
+ spec.add_development_dependency 'mysql2'
38
+ spec.add_development_dependency 'pg', '>= 0.18.4'
39
+ spec.add_development_dependency 'pry-byebug'
40
+ spec.add_development_dependency 'rspec', '>= 3.5.0'
41
+ spec.add_development_dependency 'simplecov'
42
+
43
+ # danger
44
+ spec.add_development_dependency 'danger'
45
+ spec.add_development_dependency 'danger-pronto'
46
+ spec.add_development_dependency 'pronto'
47
+ spec.add_development_dependency 'pronto-brakeman'
48
+ spec.add_development_dependency 'pronto-fasterer'
49
+ spec.add_development_dependency 'pronto-flay'
50
+ spec.add_development_dependency 'pronto-poper'
51
+ spec.add_development_dependency 'pronto-rails_best_practices'
52
+ spec.add_development_dependency 'pronto-rails_schema'
53
+ spec.add_development_dependency 'pronto-reek'
54
+ spec.add_development_dependency 'pronto-rubocop'
55
+ end
@@ -0,0 +1,56 @@
1
+ require 'dumpman/connection'
2
+ require 'dumpman/database'
3
+ require 'dumpman/adapters/base'
4
+ require 'dumpman/adapters/pg'
5
+ require 'dumpman/adapters/mysql'
6
+ require 'dumpman/comandor'
7
+ require 'dumpman/executor'
8
+ require 'dumpman/fetcher'
9
+ require 'dumpman/railtie'
10
+ require 'dumpman/version'
11
+
12
+ module Dumpman
13
+ mattr_accessor :connections
14
+
15
+ @@dump_folder = '.'
16
+ @@dump_file_name = 'dumpman.sql'
17
+ @@connections = []
18
+
19
+ class << self
20
+ def setup(&block)
21
+ self.instance_eval(&block)
22
+ end
23
+
24
+ def dump_file_name(val = nil)
25
+ return @@dump_file_name unless val.present?
26
+ @@dump_file_name = val
27
+ end
28
+
29
+ def dump_folder(val = nil)
30
+ return @@dump_folder unless val.present?
31
+ @@dump_folder = val
32
+ end
33
+
34
+ def connection_names
35
+ connections.map(&:name)
36
+ end
37
+
38
+ def define_source(name, &block)
39
+ connection = Dumpman::Connection.new(name)
40
+ connection.instance_eval(&block)
41
+ connections << connection
42
+ end
43
+
44
+ def dump_file
45
+ File.join(dump_folder, dump_file_name)
46
+ end
47
+
48
+ def dump_zip_name
49
+ "#{dump_file_name}.zip"
50
+ end
51
+
52
+ def dump_zip
53
+ File.join(dump_folder, dump_zip_name)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,61 @@
1
+ module Dumpman
2
+ module Adapters
3
+ class Base
4
+ include Singleton
5
+
6
+ def self.dump_cmd
7
+ instance.dump_cmd
8
+ end
9
+
10
+ def self.restore_cmd
11
+ instance.restore_cmd
12
+ end
13
+
14
+ def self.drop_cmd
15
+ instance.drop_cmd
16
+ end
17
+
18
+ def self.create_cmd
19
+ instance.create_cmd
20
+ end
21
+
22
+ def dump_cmd
23
+ raise(NotImplementedError)
24
+ end
25
+
26
+ def restore_cmd
27
+ raise(NotImplementedError)
28
+ end
29
+
30
+ def drop_cmd
31
+ raise(NotImplementedError)
32
+ end
33
+
34
+ def create_cmd
35
+ raise(NotImplementedError)
36
+ end
37
+
38
+ private
39
+
40
+ def db_config
41
+ @db_config ||= ActiveRecord::Base.connection_config
42
+ end
43
+
44
+ def database
45
+ @database ||= db_config.fetch(:database)
46
+ end
47
+
48
+ def username
49
+ @username ||= db_config.fetch(:username)
50
+ end
51
+
52
+ def password
53
+ @password ||= db_config.fetch(:password)
54
+ end
55
+
56
+ def host
57
+ @host ||= db_config.fetch(:host)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,21 @@
1
+ module Dumpman
2
+ module Adapters
3
+ class Mysql < Base
4
+ def dump_cmd
5
+ "MYSQL_PWD='#{password}' mysqldump -u #{username} -h #{host} #{database} > #{Dumpman.dump_file}"
6
+ end
7
+
8
+ def restore_cmd
9
+ "MYSQL_PWD='#{password}' mysql -u #{username} -h #{host} #{database} < #{Dumpman.dump_file}"
10
+ end
11
+
12
+ def drop_cmd
13
+ "MYSQL_PWD='#{password}' mysql -u #{username} -h #{host} -e 'drop database #{database}'"
14
+ end
15
+
16
+ def create_cmd
17
+ "MYSQL_PWD='#{password}' mysql -u #{username} -h #{host} -e 'create database #{database}'"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module Dumpman
2
+ module Adapters
3
+ class Pg < Base
4
+ def dump_cmd
5
+ "PGPASSWORD='#{password}' pg_dump -h #{host} --username '#{username}' --verbose --clean --no-owner --no-acl --format=c #{database} > '#{Dumpman.dump_file}'"
6
+ end
7
+
8
+ def restore_cmd
9
+ "PGPASSWORD='#{password}' pg_restore -h #{host} --username '#{username}' --verbose --clean --no-owner --no-acl -d #{database} '#{Dumpman.dump_file}'"
10
+ end
11
+
12
+ def drop_cmd
13
+ "PGPASSWORD='#{password}' dropdb -h #{host} --username '#{username}' #{database}"
14
+ end
15
+
16
+ def create_cmd
17
+ "PGPASSWORD='#{password}' createdb -h #{host} --username '#{username}' #{database}"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,46 @@
1
+ require "zip"
2
+
3
+ module Dumpman
4
+ module Commandor
5
+ extend self
6
+
7
+ def zip
8
+ # clean up from old dump
9
+ File.delete(Dumpman.dump_zip) if File.exists?(Dumpman.dump_zip)
10
+
11
+ Zip::File.open(Dumpman.dump_zip, Zip::File::CREATE) do |zipfile|
12
+ zipfile.add(Dumpman.dump_file_name, Dumpman.dump_folder + '/' + Dumpman.dump_file_name)
13
+ end
14
+ end
15
+
16
+ def unzip
17
+ # clean up from old zip
18
+ File.delete(Dumpman.dump_file) if File.exists?(Dumpman.dump_file)
19
+
20
+ Zip::File.open(Dumpman.dump_zip) do |zip_file|
21
+ zip_file.each do |entry|
22
+ puts "Extracting #{entry.name}"
23
+ entry.extract(Dumpman.dump_file)
24
+ end
25
+ end
26
+ end
27
+
28
+ def dump
29
+ Dumpman::Database.dump
30
+ end
31
+
32
+ def restore
33
+ Dumpman::Database.drop
34
+ Dumpman::Database.create
35
+ Dumpman::Database.restore
36
+ end
37
+
38
+ def drop_db
39
+ Dumpman::Database.drop
40
+ end
41
+
42
+ def create_db
43
+ Dumpman::Database.create
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,34 @@
1
+ module Dumpman
2
+ class Connection
3
+ attr_accessor :name, :app_env, :ssh_cmd, :app_path, :ssh_opts
4
+
5
+ def initialize(name)
6
+ @name = name
7
+ end
8
+
9
+ def attrs
10
+ {
11
+ app_env: @app_env,
12
+ ssh_cmd: @ssh_cmd,
13
+ ssh_opts: @ssh_opts,
14
+ app_path: @app_path,
15
+ }
16
+ end
17
+
18
+ def app_env(val)
19
+ self.app_env = val
20
+ end
21
+
22
+ def ssh_cmd(val)
23
+ self.ssh_cmd = val
24
+ end
25
+
26
+ def app_path(val)
27
+ self.app_path = val
28
+ end
29
+
30
+ def ssh_opts(val)
31
+ self.ssh_opts = val
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,38 @@
1
+ module Dumpman
2
+ module Database
3
+ def dump
4
+ cmd = strategy.dump_cmd
5
+ Dumpman::Executor.system(cmd)
6
+ end
7
+
8
+ def restore
9
+ cmd = strategy.restore_cmd
10
+ Dumpman::Executor.system(cmd)
11
+ end
12
+
13
+ def drop
14
+ cmd = strategy.drop_cmd
15
+ Dumpman::Executor.system(cmd)
16
+ end
17
+
18
+ def create
19
+ cmd = strategy.create_cmd
20
+ Dumpman::Executor.system(cmd)
21
+ end
22
+
23
+ def strategy
24
+ case ActiveRecord::Base.connection_config.fetch(:adapter)
25
+ when 'postgresql' then Dumpman::Adapters::Pg
26
+ when 'mysql', 'mysql2' then Dumpman::Adapters::Mysql
27
+ else
28
+ raise('unknown adapter in "config/database.yml"')
29
+ end
30
+ end
31
+
32
+ module_function :dump,
33
+ :restore,
34
+ :drop,
35
+ :create,
36
+ :strategy
37
+ end
38
+ end
@@ -0,0 +1,18 @@
1
+ module Dumpman
2
+ module Executor
3
+ extend self
4
+
5
+ def system(*commands)
6
+ cmd = commands.join(' && ')
7
+ puts("executing: #{cmd}")
8
+ Kernel.system(cmd)
9
+ end
10
+
11
+ def rake(*commands)
12
+ commands.each do |command|
13
+ Rake::Task["db:#{command}"].reenable
14
+ Rake::Task["db:#{command}"].invoke
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,29 @@
1
+ module Dumpman
2
+ class Fetcher < OpenStruct
3
+ def self.fetch(connection_name)
4
+ connection = Dumpman.connections.find do |connection|
5
+ connection.name == connection_name
6
+ end
7
+
8
+ instance = self.new(connection.attrs)
9
+ instance.fetch_remote_dump
10
+ end
11
+
12
+ def fetch_remote_dump
13
+ Dumpman::Executor.system(
14
+ compress_dump_remotely,
15
+ fetch_dump_to_local
16
+ )
17
+ end
18
+
19
+ private
20
+
21
+ def compress_dump_remotely
22
+ "ssh #{ssh_opts} #{ssh_cmd} 'cd #{app_path} && bash --login -c \"RAILS_ENV=#{app_env} bundle exec rake db:compress\"'"
23
+ end
24
+
25
+ def fetch_dump_to_local
26
+ "scp #{ssh_opts} #{ssh_cmd}:#{app_path}/#{Dumpman.dump_zip_name} #{Dumpman.dump_folder}/"
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,9 @@
1
+ require 'rails'
2
+
3
+ module Dumpman
4
+ class Railtie < ::Rails::Railtie
5
+ rake_tasks do
6
+ load 'tasks/db.rake'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Dumpman
2
+ VERSION = '1.2.7'
3
+ end
@@ -0,0 +1,8 @@
1
+ class DumpmanGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ desc 'This generator creates an dumpman config at config/initializers'
5
+ def copy_initializer
6
+ template 'dumpman.rb', 'config/initializers/dumpman.rb'
7
+ end
8
+ end
@@ -0,0 +1,20 @@
1
+ Dumpman.setup do
2
+ # dump file name
3
+ dump_file_name 'dumpman.sql'
4
+
5
+ # :prod is uniq connection name
6
+ define_source :prod do
7
+ # application environment (RAILS_ENV)
8
+ app_env 'production'
9
+
10
+ # ssh command for connection to the remote server
11
+ ssh_cmd 'root@192.168.1.1'
12
+
13
+ # ssh options for connection to the remote server
14
+ # example:
15
+ # ssh_opts '-i ~/.ssh/sertificate.pem'
16
+
17
+ # app path on the remote server
18
+ app_path '~/application/current'
19
+ end
20
+ end
@@ -0,0 +1,57 @@
1
+ require 'zip'
2
+ require 'dumpman'
3
+
4
+ namespace :db do
5
+ config = File.open(Rails.root.join('config', 'initializers', 'dumpman.rb')).read
6
+ eval(config)
7
+
8
+ Dumpman.connection_names.each do |name|
9
+ namespace name do
10
+ desc "up #{name} dump"
11
+ task :up => :environment do
12
+ Dumpman::Fetcher.fetch(name)
13
+ Dumpman::Executor.rake(:up)
14
+ end
15
+ end
16
+ end
17
+
18
+ desc 'up LOCAL dump'
19
+ task :up => :environment do
20
+ Dumpman::Executor.rake(
21
+ :extract,
22
+ :migrate
23
+ )
24
+ end
25
+
26
+ desc 'zips the database'
27
+ task :compress => :environment do
28
+ Dumpman::Commandor.dump
29
+ Dumpman::Commandor.zip
30
+ end
31
+
32
+ desc 'unzips the database'
33
+ task :extract => :environment do
34
+ Dumpman::Commandor.unzip
35
+ Dumpman::Commandor.restore
36
+ end
37
+
38
+ desc 'dumps the database'
39
+ task :dump => :environment do
40
+ Dumpman::Commandor.dump
41
+ end
42
+
43
+ desc 'restores the database'
44
+ task :restore => :environment do
45
+ Dumpman::Commandor.restore
46
+ end
47
+
48
+ desc 'dumps the database'
49
+ task :ddrop => :environment do
50
+ Dumpman::Commandor.drop_db
51
+ end
52
+
53
+ desc 'restores the database'
54
+ task :dcreate => :environment do
55
+ Dumpman::Commandor.create_db
56
+ end
57
+ end
data/tags ADDED
@@ -0,0 +1,9 @@
1
+ !_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
2
+ !_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
3
+ !_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/
4
+ !_TAG_PROGRAM_AUTHOR Universal Ctags Team //
5
+ !_TAG_PROGRAM_NAME Universal Ctags /Derived from Exuberant Ctags/
6
+ !_TAG_PROGRAM_URL https://ctags.io/ /official site/
7
+ !_TAG_PROGRAM_VERSION 0.0.0 /867163c/
8
+ Dumpman lib/dumpman.rb /^module Dumpman$/;" m
9
+ Dumpman lib/dumpman/version.rb /^module Dumpman$/;" m
metadata ADDED
@@ -0,0 +1,353 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dumpman
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.7
5
+ platform: ruby
6
+ authors:
7
+ - rafael
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-12-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.8
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.8
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 12.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 12.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubyzip
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.2.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.2.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '1.15'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '1.15'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mysql2
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pg
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 0.18.4
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 0.18.4
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: 3.5.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: 3.5.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: danger
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: danger-pronto
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: pronto
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: pronto-brakeman
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: pronto-fasterer
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: pronto-flay
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: pronto-poper
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ - !ruby/object:Gem::Dependency
238
+ name: pronto-rails_best_practices
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ - !ruby/object:Gem::Dependency
252
+ name: pronto-rails_schema
253
+ requirement: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - ">="
256
+ - !ruby/object:Gem::Version
257
+ version: '0'
258
+ type: :development
259
+ prerelease: false
260
+ version_requirements: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - ">="
263
+ - !ruby/object:Gem::Version
264
+ version: '0'
265
+ - !ruby/object:Gem::Dependency
266
+ name: pronto-reek
267
+ requirement: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - ">="
270
+ - !ruby/object:Gem::Version
271
+ version: '0'
272
+ type: :development
273
+ prerelease: false
274
+ version_requirements: !ruby/object:Gem::Requirement
275
+ requirements:
276
+ - - ">="
277
+ - !ruby/object:Gem::Version
278
+ version: '0'
279
+ - !ruby/object:Gem::Dependency
280
+ name: pronto-rubocop
281
+ requirement: !ruby/object:Gem::Requirement
282
+ requirements:
283
+ - - ">="
284
+ - !ruby/object:Gem::Version
285
+ version: '0'
286
+ type: :development
287
+ prerelease: false
288
+ version_requirements: !ruby/object:Gem::Requirement
289
+ requirements:
290
+ - - ">="
291
+ - !ruby/object:Gem::Version
292
+ version: '0'
293
+ description: it dumps
294
+ email:
295
+ - skcc321@gmail.com
296
+ executables: []
297
+ extensions: []
298
+ extra_rdoc_files: []
299
+ files:
300
+ - ".codeclimate.yml"
301
+ - ".gitignore"
302
+ - ".poper.yml"
303
+ - ".rspec"
304
+ - ".travis.yml"
305
+ - CODE_OF_CONDUCT.md
306
+ - Dangerfile
307
+ - Gemfile
308
+ - LICENSE.txt
309
+ - README.md
310
+ - Rakefile
311
+ - bin/console
312
+ - bin/setup
313
+ - dumpman.gemspec
314
+ - lib/dumpman.rb
315
+ - lib/dumpman/adapters/base.rb
316
+ - lib/dumpman/adapters/mysql.rb
317
+ - lib/dumpman/adapters/pg.rb
318
+ - lib/dumpman/comandor.rb
319
+ - lib/dumpman/connection.rb
320
+ - lib/dumpman/database.rb
321
+ - lib/dumpman/executor.rb
322
+ - lib/dumpman/fetcher.rb
323
+ - lib/dumpman/railtie.rb
324
+ - lib/dumpman/version.rb
325
+ - lib/generators/dumpman/dumpman_generator.rb
326
+ - lib/generators/dumpman/templates/dumpman.rb
327
+ - lib/tasks/db.rake
328
+ - tags
329
+ homepage: https://github.com/skcc321/dumpman
330
+ licenses:
331
+ - MIT
332
+ metadata: {}
333
+ post_install_message:
334
+ rdoc_options: []
335
+ require_paths:
336
+ - lib
337
+ required_ruby_version: !ruby/object:Gem::Requirement
338
+ requirements:
339
+ - - ">="
340
+ - !ruby/object:Gem::Version
341
+ version: '0'
342
+ required_rubygems_version: !ruby/object:Gem::Requirement
343
+ requirements:
344
+ - - ">="
345
+ - !ruby/object:Gem::Version
346
+ version: '0'
347
+ requirements: []
348
+ rubyforge_project:
349
+ rubygems_version: 2.7.6
350
+ signing_key:
351
+ specification_version: 4
352
+ summary: gem for playing with dumps
353
+ test_files: []