db-clone 1.1.1 → 2.0.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.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +12 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +5 -0
  5. data/Gemfile +9 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +61 -0
  8. data/Rakefile +13 -20
  9. data/bin/console +14 -0
  10. data/bin/setup +8 -0
  11. data/db-clone.gemspec +30 -0
  12. data/lib/db/clone.rb +50 -0
  13. data/lib/db/clone/base.rb +59 -0
  14. data/lib/{db_clone → db/clone}/cmd_builder.rb +10 -12
  15. data/lib/db/clone/cmd_prompt.rb +43 -0
  16. data/lib/db/clone/rake_task.rb +17 -0
  17. data/lib/db/clone/version.rb +5 -0
  18. data/screenshot.png +0 -0
  19. metadata +54 -123
  20. data/MIT-LICENSE +0 -20
  21. data/app/assets/javascripts/db_clone/application.js +0 -13
  22. data/app/assets/stylesheets/db_clone/application.css +0 -15
  23. data/app/controllers/db_clone/application_controller.rb +0 -5
  24. data/app/helpers/db_clone/application_helper.rb +0 -4
  25. data/app/views/layouts/db_clone/application.html.erb +0 -14
  26. data/config/routes.rb +0 -2
  27. data/lib/db_clone.rb +0 -27
  28. data/lib/db_clone/db_selections.rb +0 -65
  29. data/lib/db_clone/engine.rb +0 -14
  30. data/lib/db_clone/version.rb +0 -3
  31. data/lib/tasks/db_clone_tasks.rake +0 -6
  32. data/spec/cmd_builder_spec.rb +0 -73
  33. data/spec/db_clone_spec.rb +0 -15
  34. data/spec/db_selections_spec.rb +0 -74
  35. data/spec/dummy/README.rdoc +0 -28
  36. data/spec/dummy/Rakefile +0 -6
  37. data/spec/dummy/app/assets/javascripts/application.js +0 -13
  38. data/spec/dummy/app/assets/stylesheets/application.css +0 -15
  39. data/spec/dummy/app/controllers/application_controller.rb +0 -5
  40. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  41. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  42. data/spec/dummy/bin/bundle +0 -3
  43. data/spec/dummy/bin/rails +0 -4
  44. data/spec/dummy/bin/rake +0 -4
  45. data/spec/dummy/bin/setup +0 -29
  46. data/spec/dummy/config.ru +0 -4
  47. data/spec/dummy/config/application.rb +0 -31
  48. data/spec/dummy/config/boot.rb +0 -5
  49. data/spec/dummy/config/database.yml +0 -59
  50. data/spec/dummy/config/environment.rb +0 -5
  51. data/spec/dummy/config/environments/development.rb +0 -41
  52. data/spec/dummy/config/environments/production.rb +0 -79
  53. data/spec/dummy/config/environments/test.rb +0 -42
  54. data/spec/dummy/config/initializers/assets.rb +0 -11
  55. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  56. data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
  57. data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  58. data/spec/dummy/config/initializers/inflections.rb +0 -16
  59. data/spec/dummy/config/initializers/mime_types.rb +0 -4
  60. data/spec/dummy/config/initializers/session_store.rb +0 -3
  61. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  62. data/spec/dummy/config/locales/en.yml +0 -23
  63. data/spec/dummy/config/routes.rb +0 -4
  64. data/spec/dummy/config/secrets.yml +0 -22
  65. data/spec/dummy/log/test.log +0 -40
  66. data/spec/dummy/public/404.html +0 -67
  67. data/spec/dummy/public/422.html +0 -67
  68. data/spec/dummy/public/500.html +0 -66
  69. data/spec/dummy/public/favicon.ico +0 -0
  70. data/spec/rails_helper.rb +0 -59
  71. data/spec/spec_helper.rb +0 -92
@@ -1,14 +0,0 @@
1
- module DbClone
2
- class Engine < ::Rails::Engine
3
- isolate_namespace DbClone
4
-
5
- engine_name 'db-clone'
6
-
7
- config.generators do |g|
8
- g.test_framework :rspec, :fixture => false
9
- g.fixture_replacement :factory_girl, :dir => 'spec/factories'
10
- g.assets false
11
- g.helper false
12
- end
13
- end
14
- end
@@ -1,3 +0,0 @@
1
- module DbClone
2
- VERSION = '1.1.1'
3
- end
@@ -1,6 +0,0 @@
1
- namespace :db do
2
- desc 'clones a source database to a destination database'
3
- task :clone, [:manual] => :environment do |t, args|
4
- DbClone.clone! manual: args[:manual].present?
5
- end
6
- end
@@ -1,73 +0,0 @@
1
- require 'rails_helper'
2
-
3
- module DbClone
4
- describe CmdBuilder do
5
- describe 'postgresql command builder' do
6
- h = {
7
- src: {
8
- 'adapter' => 'postgresql',
9
- 'encoding' => 'unicode',
10
- 'database' => 'other_postgresql_db',
11
- 'username' => 'other_postgresql_user',
12
- 'password' => 'other_postgresql_password',
13
- 'host' => 'fake_postgresql_host',
14
- 'port' => 5432,
15
- :label => 'second_test_postgresql'
16
- },
17
- dest: {
18
- 'adapter' => 'postgresql',
19
- 'encoding' => 'unicode',
20
- 'database' => 'fake_postgresql_db',
21
- 'username' => 'fake_postgresql_user',
22
- 'password' => 'fake_postgresql_password',
23
- 'host' => 'fake_postgresql_host',
24
- 'port' => 5432,
25
- :label => 'test_postgresql'
26
- }
27
- }
28
- cb = CmdBuilder.new h
29
-
30
- it 'should be able to generate a pg_dump command' do
31
- expect(cb.get_cmd).to eql("pg_dump --no-password --clean --host=fake_postgresql_host --port=5432 --username=other_postgresql_user other_postgresql_db | psql --host=fake_postgresql_host --port=5432 --username=fake_postgresql_user fake_postgresql_db")
32
- end
33
- end
34
-
35
- describe 'mysql command builder' do
36
- before(:each) do
37
- @h = {
38
- :src => {
39
- 'adapter' => 'mysql2',
40
- 'database' => 'fake_mysql_db',
41
- 'username' => 'fake_mysql_usr',
42
- 'password' => 'fake_mysql_password',
43
- 'host' => 'fake_mysql_host',
44
- 'port' => 3306,
45
- :label => 'test_mysql'
46
- },
47
- :dest => {
48
- 'adapter' => 'mysql2',
49
- 'database' => 'other_mysql_db',
50
- 'username' => 'other_mysql_usr',
51
- 'password' => 'other_mysql_password',
52
- 'host' => 'other_mysql_host',
53
- 'port' => 3306,
54
- :label => 'second_test_mysql'
55
- }
56
- }
57
- end
58
-
59
- it 'should be able to generate a mysqldump command' do
60
- cb = CmdBuilder.new @h
61
- expect(cb.get_cmd).to eql("mysqldump --no-create-db --add-drop-table --lock-tables=false --user=fake_mysql_usr --password=fake_mysql_password --host=fake_mysql_host --port=3306 fake_mysql_db | mysql --user=other_mysql_usr --password=other_mysql_password --host=other_mysql_host --port=3306 other_mysql_db")
62
- end
63
-
64
- it 'should be able to generate a mysqldump command with ignore tables' do
65
- DbClone.config = {
66
- ignore_tables: ['tableAAAA', 'tableBBBB', 'tableCCCC']
67
- }
68
- cb = CmdBuilder.new @h
69
- expect(cb.get_cmd).to eql("mysqldump --no-create-db --add-drop-table --lock-tables=false --user=fake_mysql_usr --password=fake_mysql_password --host=fake_mysql_host --port=3306 --ignore-table=fake_mysql_db.tableAAAA --ignore-table=fake_mysql_db.tableBBBB --ignore-table=fake_mysql_db.tableCCCC fake_mysql_db | mysql --user=other_mysql_usr --password=other_mysql_password --host=other_mysql_host --port=3306 other_mysql_db")
70
- end
71
- end
72
- end
73
- end
@@ -1,15 +0,0 @@
1
- require 'rails_helper'
2
-
3
- module DbClone
4
- describe DbClone do
5
- it 'should be able to auto clone' do
6
- DbClone.config = {
7
- default_source: 'second_test_mysql',
8
- default_destination: 'test_mysql',
9
- }
10
- ds = DbSelections.new Rails.root.join('config', 'database.yml')
11
- cb = CmdBuilder.new ds.selections( use_defaults: true )
12
- expect(cb.get_cmd).to eql("mysqldump --no-create-db --add-drop-table --lock-tables=false --user=other_mysql_usr --password=other_mysql_password --host=other_mysql_host --port=3306 other_mysql_db | mysql --user=fake_mysql_usr --password=fake_mysql_password --host=fake_mysql_host --port=3306 fake_mysql_db")
13
- end
14
- end
15
- end
@@ -1,74 +0,0 @@
1
- require 'rails_helper'
2
-
3
- module DbClone
4
- describe DbSelections do
5
- describe 'db selections' do
6
- DbClone.config = {
7
- default_source: 'production',
8
- default_destination: 'development',
9
- }
10
- ds = DbSelections.new Rails.root.join('config', 'database.yml')
11
-
12
- it 'should prompt for a source' do
13
- str = "\n Choose a \e[0;35;49msource\e[0m database from one of the blocks defined in \e[0;92;49mconfig/database.yml\e[0m:\n\n [ \e[0;94;49m1\e[0m ] \e[0;33;49mdefault\e[0m\n [ \e[0;94;49m2\e[0m ] \e[0;33;49mdevelopment\e[0m\n [ \e[0;94;49m3\e[0m ] \e[0;33;49mproduction\e[0m\n [ \e[0;94;49m4\e[0m ] \e[0;33;49msecond_test_mysql\e[0m\n [ \e[0;94;49m5\e[0m ] \e[0;33;49msecond_test_postgresql\e[0m\n [ \e[0;94;49m6\e[0m ] \e[0;33;49mtest\e[0m\n [ \e[0;94;49m7\e[0m ] \e[0;33;49mtest_mysql\e[0m\n [ \e[0;94;49m8\e[0m ] \e[0;33;49mtest_postgresql\e[0m\n\n Choose a \e[0;35;49msource\e[0m database (\e[0;94;49m1\e[0m-\e[0;94;49m8\e[0m) [production = \e[0;94;49m3\e[0m]: "
14
- expect { ds.source_prompt }.to output(str).to_stdout
15
- end
16
-
17
- it 'should set a source' do
18
- allow(STDIN).to receive(:gets) { '5' }
19
- str = "\n \e[0;35;49mSource\e[0m set to: \e[0;33;49msecond_test_postgresql\e[0m\n"
20
- expect { ds.source_get }.to output(str).to_stdout
21
- end
22
-
23
- it 'should prompt for a destination' do
24
- str = "\n Choose a \e[0;35;49mdestination\e[0m database from one of the blocks defined in \e[0;92;49mconfig/database.yml\e[0m:\n\n [ \e[0;94;49m1\e[0m ] \e[0;33;49mdefault\e[0m\n [ \e[0;94;49m2\e[0m ] \e[0;33;49mdevelopment\e[0m\n [ \e[0;94;49m3\e[0m ] \e[0;33;49mproduction\e[0m\n [ \e[0;94;49m4\e[0m ] \e[0;33;49msecond_test_mysql\e[0m\n [ \e[0;31;49mX\e[0m ] \e[0;31;49msecond_test_postgresql\e[0m\n [ \e[0;94;49m6\e[0m ] \e[0;33;49mtest\e[0m\n [ \e[0;94;49m7\e[0m ] \e[0;33;49mtest_mysql\e[0m\n [ \e[0;94;49m8\e[0m ] \e[0;33;49mtest_postgresql\e[0m\n\n Choose a \e[0;35;49mdestination\e[0m database (\e[0;94;49m1\e[0m-\e[0;94;49m8\e[0m) [development = \e[0;94;49m2\e[0m]: "
25
- expect { ds.dest_prompt }.to output(str).to_stdout
26
- end
27
-
28
- it 'should set a destination' do
29
- allow(STDIN).to receive(:gets) { '8' }
30
- str = "\n \e[0;35;49mDestination\e[0m set to: \e[0;33;49mtest_postgresql\e[0m\n"
31
- expect { ds.dest_get }.to output(str).to_stdout
32
- end
33
-
34
- it 'should have a source and destination set' do
35
- expected_selections = {
36
- src: {
37
- 'adapter' => 'postgresql',
38
- 'encoding' => 'unicode',
39
- 'database' => 'other_postgresql_db',
40
- 'username' => 'other_postgresql_user',
41
- 'password' => 'other_postgresql_password',
42
- 'host' => 'fake_postgresql_host',
43
- 'port' => 5432,
44
- :label => 'second_test_postgresql'
45
- },
46
- dest: {
47
- 'adapter' => 'postgresql',
48
- 'encoding' => 'unicode',
49
- 'database' => 'fake_postgresql_db',
50
- 'username' => 'fake_postgresql_user',
51
- 'password' => 'fake_postgresql_password',
52
- 'host' => 'fake_postgresql_host',
53
- 'port' => 5432,
54
- :label => 'test_postgresql'
55
- }
56
- }
57
- expect(ds.selections).to eql(expected_selections)
58
- end
59
- end
60
-
61
- describe 'db mismatched selections' do
62
- ds = DbSelections.new Rails.root.join('config', 'database.yml')
63
-
64
- it 'should prohibit cloneing between different adapters' do
65
- expect { ds.source_prompt }.to output.to_stdout
66
- allow(STDIN).to receive(:gets) { '7' }
67
- expect { ds.source_get }.to output.to_stdout
68
- expect { ds.dest_prompt }.to output.to_stdout
69
- allow(STDIN).to receive(:gets) { '8' }
70
- expect { ds.dest_get }.to raise_error(ArgumentError)
71
- end
72
- end
73
- end
74
- end
@@ -1,28 +0,0 @@
1
- == README
2
-
3
- This README would normally document whatever steps are necessary to get the
4
- application up and running.
5
-
6
- Things you may want to cover:
7
-
8
- * Ruby version
9
-
10
- * System dependencies
11
-
12
- * Configuration
13
-
14
- * Database creation
15
-
16
- * Database initialization
17
-
18
- * How to run the test suite
19
-
20
- * Services (job queues, cache servers, search engines, etc.)
21
-
22
- * Deployment instructions
23
-
24
- * ...
25
-
26
-
27
- Please feel free to use a different markup language if you do not plan to run
28
- <tt>rake doc:app</tt>.
@@ -1,6 +0,0 @@
1
- # Add your own tasks in files placed in lib/tasks ending in .rake,
2
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
-
4
- require File.expand_path('../config/application', __FILE__)
5
-
6
- Rails.application.load_tasks
@@ -1,13 +0,0 @@
1
- // This is a manifest file that'll be compiled into application.js, which will include all the files
2
- // listed below.
3
- //
4
- // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
- // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
- //
7
- // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
- // compiled file.
9
- //
10
- // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
- // about supported directives.
12
- //
13
- //= require_tree .
@@ -1,15 +0,0 @@
1
- /*
2
- * This is a manifest file that'll be compiled into application.css, which will include all the files
3
- * listed below.
4
- *
5
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
- *
8
- * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
- * compiled file so the styles you add here take precedence over styles defined in any styles
10
- * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
- * file per style scope.
12
- *
13
- *= require_tree .
14
- *= require_self
15
- */
@@ -1,5 +0,0 @@
1
- class ApplicationController < ActionController::Base
2
- # Prevent CSRF attacks by raising an exception.
3
- # For APIs, you may want to use :null_session instead.
4
- protect_from_forgery with: :exception
5
- end
@@ -1,2 +0,0 @@
1
- module ApplicationHelper
2
- end
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Dummy</title>
5
- <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
- <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
- <%= csrf_meta_tags %>
8
- </head>
9
- <body>
10
-
11
- <%= yield %>
12
-
13
- </body>
14
- </html>
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
- load Gem.bin_path('bundler', 'bundle')
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
- APP_PATH = File.expand_path('../../config/application', __FILE__)
3
- require_relative '../config/boot'
4
- require 'rails/commands'
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require_relative '../config/boot'
3
- require 'rake'
4
- Rake.application.run
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'pathname'
3
-
4
- # path to your application root.
5
- APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6
-
7
- Dir.chdir APP_ROOT do
8
- # This script is a starting point to setup your application.
9
- # Add necessary setup steps to this file:
10
-
11
- puts "== Installing dependencies =="
12
- system "gem install bundler --conservative"
13
- system "bundle check || bundle install"
14
-
15
- # puts "\n== Copying sample files =="
16
- # unless File.exist?("config/database.yml")
17
- # system "cp config/database.yml.sample config/database.yml"
18
- # end
19
-
20
- puts "\n== Preparing database =="
21
- system "bin/rake db:setup"
22
-
23
- puts "\n== Removing old logs and tempfiles =="
24
- system "rm -f log/*"
25
- system "rm -rf tmp/cache"
26
-
27
- puts "\n== Restarting application server =="
28
- system "touch tmp/restart.txt"
29
- end
@@ -1,4 +0,0 @@
1
- # This file is used by Rack-based servers to start the application.
2
-
3
- require ::File.expand_path('../config/environment', __FILE__)
4
- run Rails.application
@@ -1,31 +0,0 @@
1
- require File.expand_path('../boot', __FILE__)
2
-
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"
9
- # require "rails/test_unit/railtie"
10
-
11
- Bundler.require(*Rails.groups)
12
- require "db_clone"
13
-
14
- module Dummy
15
- class Application < Rails::Application
16
- # Settings in config/environments/* take precedence over those specified here.
17
- # Application configuration should go into files in config/initializers
18
- # -- all .rb files in that directory are automatically loaded.
19
-
20
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
21
- # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
22
- # config.time_zone = 'Central Time (US & Canada)'
23
-
24
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
25
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
26
- # config.i18n.default_locale = :de
27
-
28
- # Do not swallow errors in after_commit/after_rollback callbacks.
29
- config.active_record.raise_in_transactional_callbacks = true
30
- end
31
- end
@@ -1,5 +0,0 @@
1
- # Set up gems listed in the Gemfile.
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
-
4
- require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
- $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
@@ -1,59 +0,0 @@
1
- # SQLite version 3.x
2
- # gem install sqlite3
3
- #
4
- # Ensure the SQLite 3 gem is defined in your Gemfile
5
- # gem 'sqlite3'
6
- #
7
- default: &default
8
- adapter: sqlite3
9
- pool: 5
10
- timeout: 5000
11
-
12
- development:
13
- <<: *default
14
- database: db/development.sqlite3
15
-
16
- # Warning: The database defined as "test" will be erased and
17
- # re-generated from your development database when you run "rake".
18
- # Do not set this db to the same as development or production.
19
- test:
20
- <<: *default
21
- database: db/test.sqlite3
22
-
23
- production:
24
- <<: *default
25
- database: db/production.sqlite3
26
-
27
- test_mysql:
28
- adapter: mysql2
29
- database: fake_mysql_db
30
- username: fake_mysql_usr
31
- password: fake_mysql_password
32
- host: fake_mysql_host
33
- port: 3306
34
-
35
- test_postgresql:
36
- adapter: postgresql
37
- encoding: unicode
38
- database: fake_postgresql_db
39
- username: fake_postgresql_user
40
- password: fake_postgresql_password
41
- host: fake_postgresql_host
42
- port: 5432
43
-
44
- second_test_mysql:
45
- adapter: mysql2
46
- database: other_mysql_db
47
- username: other_mysql_usr
48
- password: other_mysql_password
49
- host: other_mysql_host
50
- port: 3306
51
-
52
- second_test_postgresql:
53
- adapter: postgresql
54
- encoding: unicode
55
- database: other_postgresql_db
56
- username: other_postgresql_user
57
- password: other_postgresql_password
58
- host: fake_postgresql_host
59
- port: 5432
@@ -1,5 +0,0 @@
1
- # Load the Rails application.
2
- require File.expand_path('../application', __FILE__)
3
-
4
- # Initialize the Rails application.
5
- Rails.application.initialize!