rails_db_dump_restore 0.0.3

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bddd9b241052ea794ff118995ccd96bd42ddf39d
4
+ data.tar.gz: bb4cd0803311b54c5685333028c3314781c8880d
5
+ SHA512:
6
+ metadata.gz: e971e094c2497a3bfa38f6076cb118bca26e32db664bee15cf57ce4537ceb9a724aef393a4b87b18f0210b6d1a3d15666e7b8e4e26fbe590a3b6fcf50f65e5e8
7
+ data.tar.gz: 36b37c95c8712df3f41a2688161affff239a6bf94b7be3d40c9d125d1dda211293f0b07f580d8f326d384460d78627037e6b7c537e0ee699955d334a0e72fe12
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 Albert Arvidsson
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/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'RailsDbDumpRestore'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,2 @@
1
+ load File.expand_path("../../rails_db_dump_restore/dumpfile.rb", __FILE__)
2
+ load File.expand_path("../tasks/db.rake", __FILE__)
@@ -0,0 +1,35 @@
1
+ namespace :db do
2
+ def self.dumpfile
3
+ RailsDbDumpRestore::DUMPFILE
4
+ end
5
+
6
+ desc "Dump remote database to #{dumpfile}"
7
+ task :dump do
8
+ on roles(:app) do
9
+ within "#{current_path}" do
10
+ with rails_env: fetch(:rails_env) do
11
+ execute :rake, "db:dump"
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ desc "Download dumped database from remote to local"
18
+ task download: ["db:dump"] do
19
+ on roles(:app) do
20
+ dumpfile = RailsDbDumpRestore::DUMPFILE
21
+ path = "#{current_path}/#{dumpfile}"
22
+ puts "Fetching #{path} to #{dumpfile}"
23
+ download! path, dumpfile
24
+ end
25
+ end
26
+
27
+ desc "Replace local database with a remote one"
28
+ task pull: ["db:download"] do
29
+ run_locally do
30
+ with rails_env: :development do
31
+ system "rake", "db:restore"
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ require File.join(File.dirname(__FILE__), *%w[rails_db_dump_restore railtie]) if defined?(::Rails::Railtie)
2
+ require File.join(File.dirname(__FILE__), *%w[rails_db_dump_restore dumpfile])
3
+
4
+ module RailsDbDumpRestore
5
+ end
@@ -0,0 +1,3 @@
1
+ module RailsDbDumpRestore
2
+ DUMPFILE = "tmp/database.dump"
3
+ end
@@ -0,0 +1,10 @@
1
+ require 'rails_db_dump_restore'
2
+ require 'rails'
3
+
4
+ module RailsDbDumpRestore
5
+ class Railtie < Rails::Railtie
6
+ rake_tasks do
7
+ load File.expand_path('../../tasks/db.rake', __FILE__)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module RailsDbDumpRestore
2
+ VERSION = "0.0.3"
3
+ end
data/lib/tasks/db.rake ADDED
@@ -0,0 +1,94 @@
1
+ namespace :db do
2
+ def self.dumpfile
3
+ RailsDbDumpRestore::DUMPFILE
4
+ end
5
+
6
+ def dumpfile
7
+ self.class.dumpfile
8
+ end
9
+
10
+ desc "Dump database to #{dumpfile}"
11
+ task dump: [:environment] do
12
+ system "mkdir -p $(dirname #{dumpfile})"
13
+ path = "#{Rails.root}/#{dumpfile}"
14
+ case ActiveRecord::Base.connection_config[:adapter]
15
+ when "postgresql"
16
+ args = "--clean --no-owner --no-privileges"
17
+
18
+ run """
19
+ PGPASSWORD=#{password}
20
+ pg_dump #{args}
21
+ --host=#{host}
22
+ --username=#{username}
23
+ --dbname=#{database}
24
+ --file=#{path}
25
+ """
26
+ when "mysql2"
27
+ run """
28
+ MYSQL_PWD=#{password}
29
+ mysqldump
30
+ --host=#{host}
31
+ --user=#{username}
32
+ #{database} > #{path}
33
+ """
34
+ end
35
+
36
+ puts "#{Rails.env.to_s} database dumped to #{dumpfile}"
37
+ end
38
+
39
+ desc "Replace database with contents of #{dumpfile}"
40
+ task restore: [:environment] do
41
+ path = "#{Rails.root}/#{dumpfile}"
42
+ case ActiveRecord::Base.connection_config[:adapter]
43
+ when "postgresql"
44
+ run """
45
+ PGPASSWORD=#{password}
46
+ psql
47
+ --host=#{host}
48
+ --username=#{username}
49
+ --dbname=#{database}
50
+ --file=#{path}
51
+ """
52
+ when "mysql2"
53
+ run """
54
+ MYSQL_PWD=#{password}
55
+ mysql
56
+ --host=#{host}
57
+ --user=#{username}
58
+ #{database} < #{path}
59
+ """
60
+ end
61
+
62
+ puts "#{Rails.env.to_s} database replaced with contents of #{dumpfile}"
63
+ end
64
+
65
+ def run(multiline_command)
66
+ command = squeeze_into_one_line(multiline_command)
67
+
68
+ if ENV["DEBUG"]
69
+ puts command
70
+ else
71
+ system command
72
+ end
73
+ end
74
+
75
+ def host
76
+ ActiveRecord::Base.connection_config[:host]
77
+ end
78
+
79
+ def username
80
+ ActiveRecord::Base.connection_config[:username] || ENV["USER"]
81
+ end
82
+
83
+ def password
84
+ ActiveRecord::Base.connection_config[:password]
85
+ end
86
+
87
+ def database
88
+ ActiveRecord::Base.connection_config[:database]
89
+ end
90
+
91
+ def squeeze_into_one_line(multiline_string)
92
+ multiline_string.strip.gsub("\n", " ").squeeze(" ")
93
+ end
94
+ end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'bundler' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../../../../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('bundler', 'bundler')
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class RailsDbDumpRestoreTest < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, RailsDbDumpRestore
6
+ end
7
+ end
@@ -0,0 +1,16 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require "rails/test_help"
5
+
6
+ # Filter out Minitest backtrace while allowing backtrace from other libraries
7
+ # to be shown.
8
+ Minitest.backtrace_filter = Minitest::BacktraceFilter.new
9
+
10
+ # Load support files
11
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
12
+
13
+ # Load fixtures from the engine
14
+ if ActiveSupport::TestCase.respond_to?(:fixture_path=)
15
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
16
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_db_dump_restore
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Albert Arvidsson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "<"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: '3.2'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "<"
28
+ - !ruby/object:Gem::Version
29
+ version: '5.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '3.2'
33
+ - !ruby/object:Gem::Dependency
34
+ name: activerecord
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "<"
38
+ - !ruby/object:Gem::Version
39
+ version: '5.0'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '3.2'
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "<"
48
+ - !ruby/object:Gem::Version
49
+ version: '5.0'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '3.2'
53
+ description: Add rake db:dump, rake db:restore and cap db:pull
54
+ email:
55
+ - albert.arvidsson@gmail.com
56
+ executables: []
57
+ extensions: []
58
+ extra_rdoc_files: []
59
+ files:
60
+ - MIT-LICENSE
61
+ - Rakefile
62
+ - lib/capistrano/rails_db_dump_restore.rb
63
+ - lib/capistrano/tasks/db.rake
64
+ - lib/rails_db_dump_restore.rb
65
+ - lib/rails_db_dump_restore/dumpfile.rb
66
+ - lib/rails_db_dump_restore/railtie.rb
67
+ - lib/rails_db_dump_restore/version.rb
68
+ - lib/tasks/db.rake
69
+ - test/dummy-deploy/mysql/shared/bin/bundler
70
+ - test/rails_db_dump_restore_test.rb
71
+ - test/test_helper.rb
72
+ homepage: http://github.com/standout/rails_db_dump_restore
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Add rake db:dump, rake db:restore and cap db:pull
96
+ test_files:
97
+ - test/dummy-deploy/mysql/shared/bin/bundler
98
+ - test/rails_db_dump_restore_test.rb
99
+ - test/test_helper.rb