dbdump 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f7fb48d5d7b04ce2f5a217a2c82e4c302a8684f2
4
+ data.tar.gz: 9311eb324b3d8e612d51ddaca35d417a21677eac
5
+ SHA512:
6
+ metadata.gz: 0a10026a45cfb056f44f5cff8a55fb413c453e61a7babd9819eb204ef3cd214fd6977f280046bb33794c11fdac7ac8bb8938a874b067dacdfd0e5c2153f6d1d9
7
+ data.tar.gz: d014546820bddf95df7cf2d28778b00198232e2cef5c0714b1fa98563589afd0b0516b95a15c4981353d44cd8bb489538cb8d69e633116cb50839a71b1ef72d0
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rake-db.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Martin Fernandez
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.
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # Dbdump
2
+
3
+ Simple rake tasks for dumping and restoring the database.
4
+
5
+ Supported active_record adapters:
6
+
7
+ - postgresql
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'dbdump'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ ```
24
+ gem install dbdump
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ### Dump
30
+
31
+ To dump the database you need to run:
32
+
33
+ ```
34
+ rake db:dump
35
+ ```
36
+
37
+ This will dump the development database and store the dump file in `db/development.dump`. You can change the
38
+ environment with the `RAILS_ENV` variable.
39
+
40
+ ```
41
+ RAILS_ENV=production rake db:dump
42
+ ```
43
+
44
+ ### Restore
45
+
46
+ For restoring the database is pretty similar.
47
+
48
+ ```
49
+ rake db:restore
50
+ ```
51
+
52
+ and
53
+
54
+ ```
55
+ RAILS_ENV=production rake db:dump
56
+ ```
57
+
58
+ You need to have the `db/env.dump` file available in order to work properly.
59
+
60
+ ## Development
61
+
62
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
63
+
64
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
65
+
66
+ ## Contributing
67
+
68
+ Bug reports and pull requests are welcome on GitHub at https://github.com/g8labs/dbdump.
69
+
70
+
71
+ ## License
72
+
73
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "./lib/tasks/db"
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rake/db"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/dbdump.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dbdump/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dbdump"
8
+ spec.version = Dbdump::VERSION
9
+ spec.authors = ["Martin Fernandez"]
10
+ spec.email = ["martin.fernandez@g8labs.co"]
11
+
12
+ spec.summary = %q{Database rake tasks.}
13
+ spec.description = %q{Simple rake tasks for dumping and restoring the database.}
14
+ spec.homepage = "https://github.com/g8labs/dbdump"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "rails", "~> 4"
23
+ spec.add_development_dependency "bundler", "~> 1.10"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ end
@@ -0,0 +1,3 @@
1
+ module Dbdump
2
+ VERSION = "0.1.0"
3
+ end
data/lib/dbdump.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "dbdump/version"
2
+
3
+ module Dbdump
4
+ class Railtie < Rails::Railtie
5
+ rake_tasks do
6
+ load "tasks/db.rake"
7
+ end
8
+ end
9
+
10
+ end
data/lib/tasks/db.rake ADDED
@@ -0,0 +1,38 @@
1
+ namespace :db do
2
+
3
+ desc 'Dump the database from the RAILS_ENV environment database.'
4
+ task :dump => [:environment] do
5
+ with_config do |host, database, username, path|
6
+ system "pg_dump -i -h #{host} -U #{username} -d #{database} -F c -b -v -f #{path}"
7
+ end
8
+ end
9
+
10
+ desc 'Restore the database to the RAILS_ENV environment database.'
11
+ task :restore => [:environment] do
12
+ unless (env == 'development' || env == 'test')
13
+ STDOUT.puts "Are you sure you want to restore #{env} database? (y/n)"
14
+ next unless STDIN.gets.strip == 'y'
15
+ end
16
+
17
+ with_config do |host, database, username, path|
18
+ system "pg_restore -i -h #{host} --username #{username} --clean -d #{database} -v #{path}"
19
+ end
20
+ end
21
+
22
+ def with_config(&block)
23
+ yield config['host'], config['database'], config['username'], dump_path
24
+ end
25
+
26
+ def env
27
+ Rails.env
28
+ end
29
+
30
+ def config
31
+ Rails.configuration.database_configuration[env]
32
+ end
33
+
34
+ def dump_path
35
+ "db/#{env}.dump"
36
+ end
37
+
38
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dbdump
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Martin Fernandez
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-19 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'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Simple rake tasks for dumping and restoring the database.
70
+ email:
71
+ - martin.fernandez@g8labs.co
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - dbdump.gemspec
86
+ - lib/dbdump.rb
87
+ - lib/dbdump/version.rb
88
+ - lib/tasks/db.rake
89
+ homepage: https://github.com/g8labs/dbdump
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.2.2
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Database rake tasks.
113
+ test_files: []