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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef06bcc9e687a964998b09e63bd2bb71aeba5d6d
4
- data.tar.gz: 1650f534c1e128d84d1d14b5da94a40f9581e18c
3
+ metadata.gz: 0b13e8390763a001058f09c528e101e1404269c3
4
+ data.tar.gz: cd3c96d96ab055228b7523e059cc95e304308bcd
5
5
  SHA512:
6
- metadata.gz: 62a47ea6112545a0a5e472f103fb127d3b5b71a24c312224cdfe91c77e780dafa041cc7ca69b0fd8d95aaa12d6de501760ebe6c5084bf352351f998eb26dce15
7
- data.tar.gz: ec28276dfcfaede3eb2ccbce292d61243e3fc111153231521f0f7059abcc4da99198858f6a14332b1009123e74be9bdc57d83049cc804d89c53460061aa37454
6
+ metadata.gz: b21fa62236a3b26f09dca63700af1c171eb394be08914e9372e597be1f5869d70af4e254954dffd621b726f50b540c629c135df26226c49a46d380257e4b94ec
7
+ data.tar.gz: b07bcf1fe16dda7e64c0fb240b2f131e642aef0fa1c6baed28e9ce9585c43171c88d68e2f0ba7681f74c9e2bf0f5668ab746fd180d5bc793af9302cd1e4decf9
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ *.gem
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
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 2.0.0
5
+ - 2.1.0
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
@@ -1,8 +1,7 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
2
 
3
3
  require 'rspec/core/rake_task'
4
4
 
5
5
  RSpec::Core::RakeTask.new('spec')
6
6
 
7
- task :default => :spec
8
-
7
+ task default: :spec
@@ -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 = "db_replicator"
7
+ spec.name = 'db_replicator'
8
8
  spec.version = DbReplicator::VERSION
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"
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 = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
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"
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
- $:.unshift(File.dirname(__FILE__))
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 "Creating MySQL dump file.", "Create complete." do
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 "Downloading MySQL dump file", "Download complete." do
13
- pb = ProgressBar.create(:format => '%t %B %p%% %a')
14
- session.scp.download!(DbReplicator.dump_file_name, DbReplicator.dumps_dir) do |ch, name, sent, total|
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}", "Delete complete." do
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 "Executing db:drop && db:create to get a fresh database", "Fresh database created." do
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", "Import complete." do
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 "Transfering db to sqlite3", "Transfer complete" do
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 "Executing: mysql -u root #{@to_db_configs['database']} < #{DbReplicator.dump_file}"
26
- exec "mysql -u root #{@to_db_configs['database']} < #{DbReplicator.dump_file}"
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 "Executing db:migrate to update database Just in case their are pending migrations", "Migrate complete." do
30
- system "bundle exec rake db:migrate"
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
- DbReplicator.document_action "Creating temp db for transfer #{create_tmp_db_configs['database']}", "Create complete" do
38
- ActiveRecord::Tasks::DatabaseTasks.create(create_tmp_db_configs)
39
- end
40
- DbReplicator.document_action "Importing data to temp db. DB: #{create_tmp_db_configs['database']}; File: #{DbReplicator.dump_file}", "Import complete" do
41
- puts "Executing: mysql -u root #{create_tmp_db_configs['database']} < #{DbReplicator.dump_file}"
42
- system "mysql -u root #{create_tmp_db_configs['database']} < #{DbReplicator.dump_file}"
43
- end
44
- DbReplicator.document_action "Starting data transfer", "Data transfer complete." do
45
- puts "Executing: sequel #{DbReplicator.prod_db_configs['adapter']}://localhost/#{create_tmp_db_configs['database']}?user=root -C sqlite://#{@to_db_configs['database']}"
46
- system "sequel #{DbReplicator.prod_db_configs['adapter']}://localhost/#{create_tmp_db_configs['database']}?user=root -C sqlite://#{@to_db_configs['database']}"
47
- end
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| ['password', 'username'].include?(k.to_s) || v.nil? }
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 "bundle exec rake db:drop db:create"
58
+ system 'bundle exec rake db:drop db:create'
60
59
  end
61
60
  end
62
61
  end
@@ -3,4 +3,3 @@ require 'rake'
3
3
  # Make tasks visible for Rails also when used as gem.
4
4
  Dir[File.join(File.dirname(__FILE__), '..', 'tasks', '**/*.rake')].each { |rake| load rake }
5
5
  Dir[File.join(File.dirname(__FILE__), '..', '..', 'tasks', '**/*.rake')].each { |rake| load rake }
6
-
@@ -1,3 +1,3 @@
1
1
  module DbReplicator
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.2'
3
3
  end
@@ -1,24 +1,24 @@
1
1
  module DbReplicator
2
2
  class InstallGenerator < Rails::Generators::Base
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."
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 "db_replicator.rb", "config/initializers/db_replicator.rb"
8
+ template 'db_replicator.rb', 'config/initializers/db_replicator.rb'
9
9
  end
10
10
 
11
11
  def create_dumps_dir
12
- empty_directory ".db_replicator_dumps"
12
+ empty_directory '.db_replicator_dumps'
13
13
  end
14
14
 
15
15
  def add_dumps_dir_to_gitignore
16
- if File.exists?(File.join(destination_root, '.gitignore'))
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 ".gitignore", ".db_replicator_dumps"
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 "Imports the production db into the current machines environment db"
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 "******* You now have production data in your current database *******"
9
+ puts '******* You now have production data in your current database *******'
10
10
  end
11
11
 
12
- desc "Download the production db dump to ~/mysql_dumps"
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
-
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
 
4
4
  module DbReplicator
5
5
  describe Configuration do
6
- describe "#proxy_host" do
6
+ describe '#proxy_host' do
7
7
  it 'default values' do
8
8
  Configuration.new.proxy_host.should eq 'example.com'
9
9
  Configuration.new.user.should eq Etc.getlogin
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  describe DbReplicator do
3
3
 
4
- describe "#configure" do
4
+ describe '#configure' do
5
5
  before do
6
6
  DbReplicator.configure do |config|
7
7
  config.proxy_host = 'www.example.com'
@@ -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("../../tmp", __FILE__)
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 "config/initializers/db_replicator.rb"
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 ".db_replicator_dumps"
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 ".gitignore" do
28
- ".db_replicator_dumps"
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 "active_record/railtie"
5
- require "action_controller/railtie"
6
- require "action_mailer/railtie"
7
- require "action_view/railtie"
8
- require "sprockets/railtie"
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 "rails_app"
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
-
@@ -1,3 +1,3 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- Rails.application.config.action_dispatch.cookies_serializer = :json
3
+ Rails.application.config.action_dispatch.cookies_serializer = :json
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.1
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