cloner 0.9.2 → 0.10.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: 61ad9f101c4e5a38fe4d2f15afadcd915e2bf8cff332e9b0d6f2e95a54f325ce
4
+ data.tar.gz: '08e3824a1bb16fb0f5d65451ed98d928c94f14192fc11ee9b01e3797fe6c727b'
5
5
  SHA512:
6
- metadata.gz: 8c1b04ebd2ad21597a614bd24912b7c4f4c11daa2b147a32c36213a1c7bbd288d527a8af429fdc0070c8366a69b6a7d48438f80e7615557f927912ee2ee596ac
7
- data.tar.gz: 82f4ae3722521acf3e46843c07bcee0da07a461434b8757897e98487ee8a688f14f00c79415b5181d5f468eae8d209ddfd809b7e61f2c6a10635833ee4707a59
6
+ metadata.gz: '07080d76a94e16d7139648bc1d696ae311dc559927f9987614075def3f42e787300eb3609ad350a3dafcfa1f318915e1a630c61904b572eb7cbae7bc817b0bfa'
7
+ data.tar.gz: e51e3aa735fe16734ed22b1c03973f3c06f1797d0ef796f57e00d33c1299757e9182ea5f30f263f3a4c0c71acb8a6c00df9dcc8edaa36ce39a5fe4b86b1a3e17
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
4
  YAML.load_file(Rails.root.join('config', 'database.yml'))[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,7 +29,7 @@ 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')}")
@@ -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.10.0"
3
3
  end
4
4
 
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.10.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-02-10 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.0.3
130
130
  signing_key:
131
131
  specification_version: 4
132
132
  summary: Easily clone your production Mongoid database and files for local development