cloner 0.9.2 → 0.13.0

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
  SHA256:
3
- metadata.gz: 5f868fc34e630fd4d7cf91feed0e10677c104d1c9544f2ab9724c56e5cacc1d0
4
- data.tar.gz: 799f6879a9355879f954766b971c081a222e47beeefe1b534d9ff6e7ce95a1a8
3
+ metadata.gz: 688e6f12b2564228e07d5dec84b14a1cdaec1604c1d42a068217489f799a1277
4
+ data.tar.gz: b6ee8c6a77806f52d93db7489f69d9743370ff0de38e81c7a11e5a9b939a1965
5
5
  SHA512:
6
- metadata.gz: 8c1b04ebd2ad21597a614bd24912b7c4f4c11daa2b147a32c36213a1c7bbd288d527a8af429fdc0070c8366a69b6a7d48438f80e7615557f927912ee2ee596ac
7
- data.tar.gz: 82f4ae3722521acf3e46843c07bcee0da07a461434b8757897e98487ee8a688f14f00c79415b5181d5f468eae8d209ddfd809b7e61f2c6a10635833ee4707a59
6
+ metadata.gz: da35a85ce9e5229ca1ebbb0f134b686f8b2b3802489f8d3e97f30e3cc9ff60f84df233b72a35c832437fb82b36c0e4c2513e52ab436add8198296096bdf3ce80
7
+ data.tar.gz: 2bb381ab3429508fd9097502956345e146fc13c5b5fa6bda32a7189237c876d4af256203ac133910c80feec8115f0ece73dd5ac05b1092e5e5de10d3dbf3dfce
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.6.6
1
+ 2.7.4
data/README.md CHANGED
@@ -109,6 +109,24 @@ All functions from cloner/internal.rb can be overriden, for example:
109
109
 
110
110
  ## Changelog
111
111
 
112
+ ### 0.10.0
113
+
114
+ - Support rails 6 multi database activerecord apps via option
115
+
116
+ ```
117
+ def multi_db?
118
+ true
119
+ end
120
+ def clone_databases
121
+ ["primary", "gis"]
122
+ # nil - clone all databases
123
+ end
124
+ ```
125
+
126
+ - Backwards incompatible change:
127
+
128
+ Changed default dump file name to cloner.bak in postgresql to make it same, and to allow to override it and multiple files.
129
+
112
130
  ### 0.9.0
113
131
 
114
132
  - Add option to rsync to allow sync one file (thx @AnatolyShirykalov)
data/lib/cloner/ar.rb CHANGED
@@ -1,9 +1,25 @@
1
1
  module Cloner::Ar
2
- def ar_conf
2
+ def read_ar_conf
3
3
  @conf ||= begin
4
- YAML.load_file(Rails.root.join('config', 'database.yml'))[env_database]
4
+ YAML.load(ERB.new(File.read(Rails.root.join('config', 'database.yml'))).result)[env_database]
5
5
  end
6
6
  end
7
+ def ar_conf
8
+ if multi_db?
9
+ read_ar_conf[@current_database]
10
+ else
11
+ read_ar_conf
12
+ end
13
+ end
14
+
15
+ def multi_db?
16
+ false
17
+ end
18
+
19
+ def clone_databases
20
+ # clone all databases by default
21
+ nil
22
+ end
7
23
 
8
24
  def env_database
9
25
  Rails.env
@@ -13,13 +29,13 @@ module Cloner::Ar
13
29
  ar_conf['database']
14
30
  end
15
31
 
16
- def ar_r_conf
32
+ def read_ar_r_conf
17
33
  @ar_r_conf ||= begin
18
34
  do_ssh do |ssh|
19
35
  ret = ssh_exec!(ssh, "cat #{e(remote_app_path + '/config/database.yml')}")
20
36
  check_ssh_err(ret)
21
37
  begin
22
- res = YAML.load(ret[0])[env_from]
38
+ res = YAML.load(ERB.new(ret[0]).result)[env_from]
23
39
  raise 'no data' if res.blank?
24
40
  #res['host'] ||= '127.0.0.1'
25
41
  rescue Exception => e
@@ -32,7 +48,23 @@ module Cloner::Ar
32
48
  end
33
49
  end
34
50
 
35
- def clone_ar
51
+ def db_file_name
52
+ if multi_db?
53
+ "cloner_" + @current_database
54
+ else
55
+ "cloner"
56
+ end
57
+ end
58
+
59
+ def ar_r_conf
60
+ if multi_db?
61
+ read_ar_r_conf[@current_database]
62
+ else
63
+ read_ar_r_conf
64
+ end
65
+ end
66
+
67
+ def run_clone_ar
36
68
  if ar_conf["adapter"] != ar_r_conf["adapter"]
37
69
  puts "Error: ActiveRecord adapter mismatch: local #{ar_conf["adapter"]}, remote #{ar_r_conf["adapter"]}"
38
70
  puts "it is not possible to convert from one database to another via this tool."
@@ -50,5 +82,22 @@ module Cloner::Ar
50
82
  exit
51
83
  end
52
84
  end
85
+
86
+ def clone_ar
87
+ if multi_db?
88
+ dblist = clone_databases
89
+ if dblist.nil?
90
+ dblist = read_ar_conf.keys
91
+ end
92
+ puts "cloning multiple databases: #{dblist.join(", ")}"
93
+ dblist.each do |dbn|
94
+ @current_database = dbn
95
+ run_clone_ar
96
+ end
97
+ @current_database = nil
98
+ else
99
+ run_clone_ar
100
+ end
101
+ end
53
102
  end
54
103
 
data/lib/cloner/mysql.rb CHANGED
@@ -35,7 +35,7 @@ module Cloner::MySQL
35
35
  check_ssh_err(ret)
36
36
  host = ar_r_conf['host'].present? ? " --host #{e ar_r_conf['host']}" : ""
37
37
  port = ar_r_conf['port'].present? ? " --port #{e ar_r_conf['port']}" : ""
38
- dump = "#{my_bin_path 'mysqldump'} #{my_dump_param} --user #{e ar_r_conf['username']} #{my_remote_auth}#{host}#{port} #{e ar_r_conf['database']} > #{e(remote_dump_path + '/cloner.sql')}"
38
+ dump = "#{my_bin_path 'mysqldump'} #{my_dump_param} --user #{e ar_r_conf['username']} #{my_remote_auth}#{host}#{port} #{e ar_r_conf['database']} > #{e(remote_dump_path + '/'+db_file_name+'.sql')}"
39
39
  puts dump if verbose?
40
40
  ret = ssh_exec!(ssh, dump)
41
41
  check_ssh_err(ret)
@@ -46,7 +46,7 @@ module Cloner::MySQL
46
46
  puts "restoring DB"
47
47
  host = ar_conf['host'].present? ? " --host #{e ar_conf['host']}" : ""
48
48
  port = ar_conf['port'].present? ? " --port #{e ar_conf['port']}" : ""
49
- restore = "#{my_bin_path 'mysql'} #{my_restore_param} --user #{e ar_conf['username']} #{my_local_auth}#{host}#{port} #{e ar_to} < #{e(my_path + '/cloner.sql')}"
49
+ restore = "#{my_bin_path 'mysql'} #{my_restore_param} --user #{e ar_conf['username']} #{my_local_auth}#{host}#{port} #{e ar_to} < #{e(my_path + '/'+db_file_name+'.sql')}"
50
50
  puts restore if verbose?
51
51
  pipe = IO.popen(restore)
52
52
  while (line = pipe.gets)
@@ -52,7 +52,7 @@ module Cloner::Postgres
52
52
  check_ssh_err(ret)
53
53
  host = ar_r_conf['host'].present? ? " -h #{e ar_r_conf['host']}" : ""
54
54
  port = ar_r_conf['port'].present? ? " -p #{e ar_r_conf['port']}" : ""
55
- dump = pg_remote_auth + "#{pg_remote_bin_path 'pg_dump'} #{pg_dump_param} -U #{e ar_r_conf['username']}#{host}#{port} #{e ar_r_conf['database']} > #{e(remote_dump_path + '/tmp.bak')}"
55
+ dump = pg_remote_auth + "#{pg_remote_bin_path 'pg_dump'} #{pg_dump_param} -U #{e ar_r_conf['username']}#{host}#{port} #{e ar_r_conf['database']} > #{e(remote_dump_path + '/'+db_file_name+'.bak')}"
56
56
  puts dump if verbose?
57
57
  ret = ssh_exec!(ssh, dump)
58
58
  check_ssh_err(ret)
@@ -63,7 +63,7 @@ module Cloner::Postgres
63
63
  puts "restoring DB"
64
64
  host = ar_conf['host'].present? ? " -h #{e ar_conf['host']}" : ""
65
65
  port = ar_conf['port'].present? ? " -p #{e ar_conf['port']}" : ""
66
- restore = pg_local_auth + "#{pg_local_bin_path 'pg_restore'} #{pg_restore_param} -U #{e ar_conf['username']}#{host}#{port} -d #{e ar_to} #{e(pg_path + '/tmp.bak')}"
66
+ restore = pg_local_auth + "#{pg_local_bin_path 'pg_restore'} #{pg_restore_param} -U #{e ar_conf['username']}#{host}#{port} -d #{e ar_to} #{e(pg_path + '/'+db_file_name+'.bak')}"
67
67
  puts restore if verbose?
68
68
  pipe = IO.popen(restore)
69
69
  while (line = pipe.gets)
@@ -1,4 +1,4 @@
1
1
  module Cloner
2
- VERSION = "0.9.2"
2
+ VERSION = "0.13.0"
3
3
  end
4
4
 
data/lib/cloner.rb CHANGED
@@ -1,6 +1,8 @@
1
- require "cloner/version"
1
+ require 'cloner/version'
2
2
  require 'thor'
3
3
  require 'active_support/concern'
4
+ require 'fileutils'
5
+
4
6
  module Cloner
5
7
  autoload :Base, "cloner/base"
6
8
  autoload :Internal, "cloner/internal"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - glebtv
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-29 00:00:00.000000000 Z
11
+ date: 2021-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -126,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
126
  - !ruby/object:Gem::Version
127
127
  version: '0'
128
128
  requirements: []
129
- rubygems_version: 3.1.4
129
+ rubygems_version: 3.1.6
130
130
  signing_key:
131
131
  specification_version: 4
132
132
  summary: Easily clone your production Mongoid database and files for local development