db_replicator 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +74 -0
- data/.travis.yml +5 -0
- data/README.md +2 -2
- data/Rakefile +2 -3
- data/db_replicator.gemspec +13 -12
- data/lib/db_replicator.rb +1 -4
- data/lib/db_replicator/downloader.rb +5 -6
- data/lib/db_replicator/importer.rb +21 -22
- data/lib/db_replicator/tasks.rb +0 -1
- data/lib/db_replicator/version.rb +1 -1
- data/lib/generators/db_replicator/install_generator.rb +6 -6
- data/lib/tasks/dbr.rake +3 -8
- data/spec/db_replicator/configuration_spec.rb +1 -1
- data/spec/db_replicator_spec.rb +1 -1
- data/spec/generators/db_replicator/install_generator_spec.rb +7 -7
- data/spec/rails_app/config/application.rb +6 -7
- data/spec/rails_app/config/initializers/cookies_serializer.rb +1 -1
- metadata +17 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b13e8390763a001058f09c528e101e1404269c3
|
4
|
+
data.tar.gz: cd3c96d96ab055228b7523e059cc95e304308bcd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b21fa62236a3b26f09dca63700af1c171eb394be08914e9372e597be1f5869d70af4e254954dffd621b726f50b540c629c135df26226c49a46d380257e4b94ec
|
7
|
+
data.tar.gz: b07bcf1fe16dda7e64c0fb240b2f131e642aef0fa1c6baed28e9ce9585c43171c88d68e2f0ba7681f74c9e2bf0f5668ab746fd180d5bc793af9302cd1e4decf9
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- 'spec/rails_app/**/*'
|
4
|
+
|
5
|
+
# Offense count: 2
|
6
|
+
# Cop supports --auto-correct.
|
7
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
8
|
+
Style/HashSyntax:
|
9
|
+
Enabled: true
|
10
|
+
|
11
|
+
# Offense count: 1
|
12
|
+
# Cop supports --auto-correct.
|
13
|
+
Style/IndentationWidth:
|
14
|
+
Enabled: true
|
15
|
+
|
16
|
+
# Offense count: 1
|
17
|
+
# Cop supports --auto-correct.
|
18
|
+
# Configuration parameters: SupportedStyles.
|
19
|
+
Style/SpaceAroundEqualsInParameterDefault:
|
20
|
+
EnforcedStyle: no_space
|
21
|
+
|
22
|
+
# Offense count: 1
|
23
|
+
# Cop supports --auto-correct.
|
24
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
25
|
+
Style/SpaceBeforeBlockBraces:
|
26
|
+
Enabled: true
|
27
|
+
|
28
|
+
# Offense count: 1
|
29
|
+
# Cop supports --auto-correct.
|
30
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
|
31
|
+
Style/SpaceInsideBlockBraces:
|
32
|
+
Enabled: true
|
33
|
+
|
34
|
+
# Offense count: 58
|
35
|
+
# Cop supports --auto-correct.
|
36
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
37
|
+
Style/StringLiterals:
|
38
|
+
Enabled: true
|
39
|
+
|
40
|
+
# Offense count: 5
|
41
|
+
# Cop supports --auto-correct.
|
42
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
43
|
+
Style/TrailingBlankLines:
|
44
|
+
Enabled: true
|
45
|
+
|
46
|
+
# Offense count: 7
|
47
|
+
# Cop supports --auto-correct.
|
48
|
+
Style/TrailingWhitespace:
|
49
|
+
Enabled: true
|
50
|
+
|
51
|
+
# Offense count: 1
|
52
|
+
Lint/Void:
|
53
|
+
Enabled: false
|
54
|
+
|
55
|
+
# Offense count: 24
|
56
|
+
# Configuration parameters: AllowURI, URISchemes.
|
57
|
+
Metrics/LineLength:
|
58
|
+
Enabled: false
|
59
|
+
Max: 210
|
60
|
+
|
61
|
+
# Offense count: 3
|
62
|
+
# Configuration parameters: CountComments.
|
63
|
+
Metrics/MethodLength:
|
64
|
+
Enabled: false
|
65
|
+
Max: 16
|
66
|
+
|
67
|
+
# Offense count: 7
|
68
|
+
Style/Documentation:
|
69
|
+
Enabled: false
|
70
|
+
|
71
|
+
# Offense count: 2
|
72
|
+
Style/RegexpLiteral:
|
73
|
+
Enabled: false
|
74
|
+
MaxSlashes: 0
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# DbReplicator
|
1
|
+
# DbReplicator [![Build Status](https://travis-ci.org/meatherly/db_replicator.svg?branch=master)](https://travis-ci.org/meatherly/db_replicator)
|
2
2
|
|
3
3
|
This gem allow you to down load and import your production db to test with.
|
4
4
|
|
@@ -9,7 +9,7 @@ As of now I only suport MySQL. I plan to add more adapters in the future. See TO
|
|
9
9
|
Add this line to your application's Gemfile:
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
gem 'db_replicator'
|
12
|
+
gem 'db_replicator', '~> 0.0.1'
|
13
13
|
```
|
14
14
|
|
15
15
|
And then execute:
|
data/Rakefile
CHANGED
data/db_replicator.gemspec
CHANGED
@@ -4,24 +4,25 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'db_replicator/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'db_replicator'
|
8
8
|
spec.version = DbReplicator::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
9
|
+
spec.authors = ['Michael Eatherly']
|
10
|
+
spec.email = ['meatherly@gmail.com']
|
11
|
+
spec.summary = ''
|
12
|
+
spec.description = ''
|
13
|
+
spec.homepage = 'https://github.com/meatherly/db_replicator'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_development_dependency
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'generator_spec'
|
24
|
+
spec.add_development_dependency 'rspec'
|
25
|
+
spec.add_development_dependency 'rubocop'
|
25
26
|
spec.add_runtime_dependency 'sequel', '~> 4.15.0'
|
26
27
|
spec.add_runtime_dependency 'ruby-progressbar'
|
27
28
|
spec.add_runtime_dependency 'rails', '>= 4'
|
data/lib/db_replicator.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
2
|
require 'db_replicator/version'
|
3
3
|
require 'db_replicator/tasks'
|
4
4
|
require 'db_replicator/configuration'
|
@@ -9,8 +9,6 @@ require 'colorize'
|
|
9
9
|
module DbReplicator
|
10
10
|
class << self
|
11
11
|
attr_writer :configuration
|
12
|
-
|
13
|
-
|
14
12
|
end
|
15
13
|
|
16
14
|
def self.configuration
|
@@ -46,5 +44,4 @@ module DbReplicator
|
|
46
44
|
def self.prod_db_configs
|
47
45
|
@prod_configs ||= DbReplicator.db_configs('production')
|
48
46
|
end
|
49
|
-
|
50
47
|
end
|
@@ -4,19 +4,18 @@ require 'ruby-progressbar'
|
|
4
4
|
module DbReplicator
|
5
5
|
class Downloader
|
6
6
|
def self.download_production
|
7
|
-
pp DbReplicator.prod_db_configs['database']
|
8
7
|
Net::SSH.start(DbReplicator.configuration.proxy_host, DbReplicator.configuration.user) do |session|
|
9
|
-
DbReplicator.document_action
|
8
|
+
DbReplicator.document_action 'Creating MySQL dump file.', 'Create complete.' do
|
10
9
|
session.exec! "mysqldump -u #{DbReplicator.prod_db_configs['user']} --password=#{DbReplicator.prod_db_configs['password']} #{DbReplicator.prod_db_configs['database']} > #{DbReplicator.dump_file_name}"
|
11
10
|
end
|
12
|
-
DbReplicator.document_action
|
13
|
-
pb = ProgressBar.create(:
|
14
|
-
session.scp.download!(DbReplicator.dump_file_name, DbReplicator.dumps_dir) do |
|
11
|
+
DbReplicator.document_action 'Downloading MySQL dump file', 'Download complete.' do
|
12
|
+
pb = ProgressBar.create(format: '%t %B %p%% %a')
|
13
|
+
session.scp.download!(DbReplicator.dump_file_name, DbReplicator.dumps_dir) do |_ch, _name, sent, total|
|
15
14
|
pb.total = total
|
16
15
|
pb.progress = sent
|
17
16
|
end
|
18
17
|
end
|
19
|
-
DbReplicator.document_action "Deleting MySQL dump file on #{DbReplicator.configuration.proxy_host}",
|
18
|
+
DbReplicator.document_action "Deleting MySQL dump file on #{DbReplicator.configuration.proxy_host}", 'Delete complete.' do
|
20
19
|
session.exec! "rm -f #{DbReplicator.dump_file_name}"
|
21
20
|
end
|
22
21
|
end
|
@@ -12,51 +12,50 @@ module DbReplicator
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def import_db!
|
15
|
-
DbReplicator.document_action
|
15
|
+
DbReplicator.document_action 'Executing db:drop && db:create to get a fresh database', 'Fresh database created.' do
|
16
16
|
create_fresh_db
|
17
17
|
end
|
18
|
-
DbReplicator.document_action "Importing mysql dump to #{@to_db_configs['database']} database",
|
19
|
-
pp @tmp_db_configs
|
18
|
+
DbReplicator.document_action "Importing mysql dump to #{@to_db_configs['database']} database", 'Import complete.' do
|
20
19
|
if @tmp_db_configs
|
21
|
-
DbReplicator.document_action
|
20
|
+
DbReplicator.document_action 'Transfering db to sqlite3', 'Transfer complete' do
|
22
21
|
convert_sql_dump_and_import
|
23
22
|
end
|
24
23
|
else
|
25
|
-
puts "
|
26
|
-
|
24
|
+
puts "mysql -u root --database=#{@to_db_configs['database']} < #{DbReplicator.dump_file}"
|
25
|
+
puts system "mysql -u root --database=#{@to_db_configs['database']} < #{DbReplicator.dump_file}"
|
27
26
|
end
|
28
27
|
end
|
29
|
-
DbReplicator.document_action
|
30
|
-
system
|
28
|
+
DbReplicator.document_action 'Executing db:migrate to update database Just in case their are pending migrations', 'Migrate complete.' do
|
29
|
+
system 'bundle exec rake db:migrate'
|
31
30
|
end
|
32
31
|
end
|
33
|
-
|
32
|
+
|
34
33
|
private
|
35
34
|
|
36
35
|
def convert_sql_dump_and_import
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
36
|
+
DbReplicator.document_action "Creating temp db for transfer #{create_tmp_db_configs['database']}", 'Create complete' do
|
37
|
+
ActiveRecord::Tasks::DatabaseTasks.create(create_tmp_db_configs)
|
38
|
+
end
|
39
|
+
DbReplicator.document_action "Importing data to temp db. DB: #{create_tmp_db_configs['database']}; File: #{DbReplicator.dump_file}", 'Import complete' do
|
40
|
+
puts "Executing: mysql -u root #{create_tmp_db_configs['database']} < #{DbReplicator.dump_file}"
|
41
|
+
system "mysql -u root #{create_tmp_db_configs['database']} < #{DbReplicator.dump_file}"
|
42
|
+
end
|
43
|
+
DbReplicator.document_action 'Starting data transfer', 'Data transfer complete.' do
|
44
|
+
puts "Executing: sequel #{DbReplicator.prod_db_configs['adapter']}://localhost/#{create_tmp_db_configs['database']}?user=root -C sqlite://#{@to_db_configs['database']}"
|
45
|
+
system "sequel #{DbReplicator.prod_db_configs['adapter']}://localhost/#{create_tmp_db_configs['database']}?user=root -C sqlite://#{@to_db_configs['database']}"
|
46
|
+
end
|
48
47
|
end
|
49
48
|
|
50
49
|
def create_tmp_db_configs
|
51
50
|
tmp_configs = @to_db_configs.clone
|
52
51
|
tmp_configs['database'] = "#{DbReplicator.prod_db_configs['database']}_db_replicator"
|
53
52
|
# tmp_configs['host'] = 'localhost'
|
54
|
-
tmp_configs.reject!{|k, v|
|
53
|
+
tmp_configs.reject! { |k, v| %w(password username).include?(k.to_s) || v.nil? }
|
55
54
|
tmp_configs
|
56
55
|
end
|
57
56
|
|
58
57
|
def create_fresh_db
|
59
|
-
system
|
58
|
+
system 'bundle exec rake db:drop db:create'
|
60
59
|
end
|
61
60
|
end
|
62
61
|
end
|
data/lib/db_replicator/tasks.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
module DbReplicator
|
2
2
|
class InstallGenerator < Rails::Generators::Base
|
3
|
-
source_root File.expand_path(
|
4
|
-
desc
|
3
|
+
source_root File.expand_path('../../templates', __FILE__)
|
4
|
+
desc 'Creates the base config file for DbReplicator, the .db_replicator_dumps directory, and adds .db_replicator_dumps to your .gitignore file.'
|
5
5
|
|
6
6
|
def copy_initializer
|
7
7
|
puts destination_root
|
8
|
-
template
|
8
|
+
template 'db_replicator.rb', 'config/initializers/db_replicator.rb'
|
9
9
|
end
|
10
10
|
|
11
11
|
def create_dumps_dir
|
12
|
-
empty_directory
|
12
|
+
empty_directory '.db_replicator_dumps'
|
13
13
|
end
|
14
14
|
|
15
15
|
def add_dumps_dir_to_gitignore
|
16
|
-
if File.
|
16
|
+
if File.exist?(File.join(destination_root, '.gitignore'))
|
17
17
|
append_to_file '.gitignore' do
|
18
18
|
'.db_replicator_dumps'
|
19
19
|
end
|
20
20
|
else
|
21
|
-
create_file
|
21
|
+
create_file '.gitignore', '.db_replicator_dumps'
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
data/lib/tasks/dbr.rake
CHANGED
@@ -2,20 +2,15 @@ db_replicator_lib = File.expand_path(File.dirname(File.dirname(__FILE__)))
|
|
2
2
|
require "#{db_replicator_lib}/db_replicator"
|
3
3
|
|
4
4
|
namespace :dbr do
|
5
|
-
desc
|
5
|
+
desc 'Imports the production db into the current machines environment db'
|
6
6
|
task prod_to_local: [:environment, :download_prod_db] do
|
7
7
|
importer = DbReplicator::Importer.new('development')
|
8
8
|
importer.import_db!
|
9
|
-
puts
|
9
|
+
puts '******* You now have production data in your current database *******'
|
10
10
|
end
|
11
11
|
|
12
|
-
desc
|
12
|
+
desc 'Download the production db dump to ~/mysql_dumps'
|
13
13
|
task download_prod_db: :environment do
|
14
14
|
DbReplicator::Downloader.download_production
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
data/spec/db_replicator_spec.rb
CHANGED
@@ -5,7 +5,7 @@ require 'generators/db_replicator/install_generator'
|
|
5
5
|
|
6
6
|
describe DbReplicator::InstallGenerator, type: :generator do
|
7
7
|
include GeneratorSpec::TestCase
|
8
|
-
destination File.expand_path(
|
8
|
+
destination File.expand_path('../../tmp', __FILE__)
|
9
9
|
|
10
10
|
before do
|
11
11
|
prepare_destination
|
@@ -13,21 +13,21 @@ describe DbReplicator::InstallGenerator, type: :generator do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'should have created the initializer with the correct contents' do
|
16
|
-
assert_file
|
16
|
+
assert_file 'config/initializers/db_replicator.rb'
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should create the SQL dumps directory' do
|
20
20
|
destination_root.should have_structure {
|
21
|
-
directory
|
22
|
-
}
|
21
|
+
directory '.db_replicator_dumps'
|
22
|
+
}
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'should add .db_replicator_dumps to the .gitignore file' do
|
26
26
|
destination_root.should have_structure {
|
27
|
-
file
|
28
|
-
|
27
|
+
file '.gitignore' do
|
28
|
+
'.db_replicator_dumps'
|
29
29
|
end
|
30
|
-
}
|
30
|
+
}
|
31
31
|
end
|
32
32
|
|
33
33
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
require File.expand_path('../boot', __FILE__)
|
2
2
|
|
3
3
|
# Pick the frameworks you want:
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
4
|
+
require 'active_record/railtie'
|
5
|
+
require 'action_controller/railtie'
|
6
|
+
require 'action_mailer/railtie'
|
7
|
+
require 'action_view/railtie'
|
8
|
+
require 'sprockets/railtie'
|
9
9
|
# require "rails/test_unit/railtie"
|
10
10
|
|
11
11
|
Bundler.require(*Rails.groups)
|
12
|
-
require
|
12
|
+
require 'rails_app'
|
13
13
|
|
14
14
|
module Dummy
|
15
15
|
class Application < Rails::Application
|
@@ -26,4 +26,3 @@ module Dummy
|
|
26
26
|
# config.i18n.default_locale = :de
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: db_replicator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Eatherly
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
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'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: sequel
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,6 +144,8 @@ extensions: []
|
|
130
144
|
extra_rdoc_files: []
|
131
145
|
files:
|
132
146
|
- ".gitignore"
|
147
|
+
- ".rubocop.yml"
|
148
|
+
- ".travis.yml"
|
133
149
|
- Gemfile
|
134
150
|
- LICENSE.txt
|
135
151
|
- README.md
|