capistrano-container-db 0.0.5 → 0.0.6

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: 4f236a486192089b4688459ad3439ab874821f17
4
- data.tar.gz: 37a43ae5ec9750be66df21d5d49094736c8d033d
3
+ metadata.gz: 6f9fafce47206c3a7e06f2738642dd8e4f1e474a
4
+ data.tar.gz: acbbaf8af6245ad654174f293d76df51a76c52ad
5
5
  SHA512:
6
- metadata.gz: 4f3cca20d9bb697923e2d1d572f8848eb8c05a73ea8baf28712f19737478a1272950f275cceac9954950904a5dac4f211256f07ff091debd731eb9c03a978d38
7
- data.tar.gz: d54bdf8c2518359144d3b4c37ccaa4ef3abdbb0fccddb5871de4d0f85c0a3d832bb8a725af252dbabc3ced11bf2d954c85d1d1d351ec43ace652631641bdff66
6
+ metadata.gz: 8b3c7918fc632dff312afb964d74aaa1a2057ec5a8591284e0c4fc86cb61edf33d9458a2b4826c29563ac5b52eaf89cd386d291180bd7eb91a41862ddb8a9af8
7
+ data.tar.gz: 3e831a15ffba3167f66759118441e5fcca4dc4d971f82ce3b28e1a38996d169acc732fd2bdc9fb646c1de8001bea5c62ded31c53fff4cd7f471f1b0f7741b481
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Helps managing databases on local and remote stages, also on remote [docker](https://www.docker.com/) container for Capistrano 3.x.
4
4
 
5
- This project is in an early stage but helps me alot dealing with my container deployments and keeps my code clean. It is not only ment for mysql, but at the moment there is only support for mysql, feel free to contribute =)
5
+ This project is in an early stage but helps me a lot dealing with my container deployments and keeps my code clean. It is not only meant for mysql, but at the moment there is only support for mysql, feel free to contribute =)
6
6
 
7
7
  This gem depends on [capistrano-container](https://github.com/creative-workflow/capistrano-container).
8
8
 
@@ -90,6 +90,10 @@ set :filter_on_import, lambda{ |sql_dump| return sql_dump } -> !not implemented
90
90
  * add db:execute task
91
91
 
92
92
  ## Changes
93
+ ### Version 0.0.6
94
+ * use clean module namespaces
95
+ * add `--lock-tables=false` as default dump arg
96
+
93
97
  ### Version 0.0.5
94
98
  * add "CREATE DATABASE IF NOT EXISTS" to import statements
95
99
  * provide additional mysql auth/dump/restore args
@@ -4,8 +4,8 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'capistrano-container-db'
7
- spec.version = '0.0.5'
8
- spec.date = '2016-09-30'
7
+ spec.version = '0.0.6'
8
+ spec.date = '2018-02-03'
9
9
  spec.summary = 'Helps managing databases on local and remote stages, also on remote docker container'
10
10
  spec.description = spec.summary
11
11
  spec.authors = ['Tom Hanoldt']
@@ -1,11 +1,4 @@
1
1
  require_relative '../tasks/db.rb'
2
-
3
- module Capistrano
4
- module Container
5
- module DB
6
- require_relative '../../db/helper.rb'
7
- require_relative '../../db/load_helper.rb'
8
- require_relative '../../db/dump_helper.rb'
9
- end
10
- end
11
- end
2
+ require_relative '../../db/helper.rb'
3
+ require_relative '../../db/load_helper.rb'
4
+ require_relative '../../db/dump_helper.rb'
@@ -7,7 +7,7 @@ namespace :db do
7
7
  task :execute do
8
8
  on roles(:db, :container_host) do |host|
9
9
  ask(:tmp_cmd, "mysql command")
10
- Helper.execute_db_command_autodetect fetch(:tmp_cmd)
10
+ Capistrano::Container::DB::Helper.execute_db_command_autodetect fetch(:tmp_cmd)
11
11
  end
12
12
  end
13
13
 
@@ -16,14 +16,14 @@ namespace :db do
16
16
  task :export do
17
17
  on roles(:db, :container_host) do |host|
18
18
  if fetch(:db_is_container)
19
- DumpHelper::dump_on_container_and_download container_by_name(fetch(:db_container_name))
20
- elsif Helper::local_stage?
21
- DumpHelper::dump_on_local
19
+ Capistrano::Container::DB::DumpHelper::dump_on_container_and_download container_by_name(fetch(:db_container_name))
20
+ elsif Capistrano::Container::DB::Helper::local_stage?
21
+ Capistrano::Container::DB::DumpHelper::dump_on_local
22
22
  else
23
- DumpHelper::dump_on_server_and_download
23
+ Capistrano::Container::DB::DumpHelper::dump_on_server_and_download
24
24
  end
25
25
 
26
- Helper::duplicate_local_dump_to_staged_dump
26
+ Capistrano::Container::DB::Helper::duplicate_local_dump_to_staged_dump
27
27
  end
28
28
  end
29
29
 
@@ -31,11 +31,11 @@ namespace :db do
31
31
  task :import do
32
32
  on roles(:db, :container_host) do
33
33
  if fetch(:db_is_container)
34
- LoadHelper::import_on_container container_by_name(fetch(:db_container_name))
35
- elsif Helper::local_stage?
36
- LoadHelper::import_on_local
34
+ Capistrano::Container::DB::LoadHelper::import_on_container container_by_name(fetch(:db_container_name))
35
+ elsif Capistrano::Container::DB::Helper::local_stage?
36
+ Capistrano::Container::DB::LoadHelper::import_on_local
37
37
  else
38
- LoadHelper::import_on_server
38
+ Capistrano::Container::DB::LoadHelper::import_on_server
39
39
  end
40
40
  end
41
41
  end
@@ -50,7 +50,7 @@ namespace :load do
50
50
  set :db_additional_restore_args, []
51
51
  # dont use --database statement, so no use '...' will be generated and we
52
52
  # can have different db names local and remote
53
- set :db_additional_dump_args, ['--no-create-db']
53
+ set :db_additional_dump_args, ['--no-create-db --lock-tables=false']
54
54
  set :db_remote_dump, '/tmp/dump.sql'
55
55
  set :db_local_dump, 'config/db/dump.sql'
56
56
  set :db_is_container, false
@@ -1,27 +1,34 @@
1
1
  require_relative "helper.rb"
2
2
 
3
- module DumpHelper
4
- def self.dump_on_local()
5
- args = Helper::mysql_dump_args
3
+ module Capistrano
4
+ module Container
5
+ module DB
6
+ module DumpHelper
7
+ def self.dump_on_local()
8
+ args = Helper::mysql_dump_args
6
9
 
7
- run_locally do
8
- execute "mysqldump #{args} > #{fetch(:db_local_dump)}"
9
- end
10
- end
10
+ run_locally do
11
+ execute "mysqldump #{args} > #{fetch(:db_local_dump)}"
12
+ end
13
+ end
11
14
 
12
- def self.dump_on_server_and_download()
13
- args = Helper::mysql_dump_args
15
+ def self.dump_on_server_and_download()
16
+ args = Helper::mysql_dump_args
14
17
 
15
- execute "mysqldump #{args} > #{fetch(:db_remote_dump)}"
18
+ execute "mysqldump #{args} > #{fetch(:db_remote_dump)}"
16
19
 
17
- download!(fetch(:db_remote_dump), fetch(:db_local_dump))
18
- end
20
+ download!(fetch(:db_remote_dump), fetch(:db_local_dump))
21
+ end
19
22
 
20
- def self.dump_on_container_and_download(container)
21
- args = Helper::mysql_dump_args
23
+ def self.dump_on_container_and_download(container)
24
+ args = Helper::mysql_dump_args
22
25
 
23
- container.execute("mysqldump #{args} > #{fetch(:db_remote_dump)}")
26
+ container.execute("mysqldump #{args} > #{fetch(:db_remote_dump)}")
24
27
 
25
- container.download!(fetch(:db_remote_dump), fetch(:db_local_dump))
28
+ container.download!(fetch(:db_remote_dump), fetch(:db_local_dump))
29
+ end
30
+ end
31
+
32
+ end
26
33
  end
27
34
  end
data/lib/db/helper.rb CHANGED
@@ -1,52 +1,59 @@
1
- module Helper
2
- def self.mysql_dump_args
3
- command = mysql_auth_args
4
- command+= " #{fetch(:db_additional_dump_args).join(' ')} "
5
- command+= " #{fetch(:db_name)}" unless fetch(:db_name).empty?
6
- command
7
- end
8
-
9
- def self.mysql_restore_args
10
- command = mysql_auth_args
11
- command+= " #{fetch(:db_additional_restore_args).join(' ')} "
12
- command+= " #{fetch(:db_name)}" unless fetch(:db_name).empty?
13
- command
14
- end
15
-
16
- def self.mysql_auth_args
17
- command = " -u #{fetch(:db_user)}"
18
- command+= " -p#{fetch(:db_pass)}" unless fetch(:db_pass).empty?
19
- command+= " #{fetch(:db_additional_auth_args).join(' ')} "
20
- command
21
- end
22
-
23
- def self.append_stage_to_filename(file_name, stage = 'local')
24
- splitted = file_name.split('.')
25
- extension = splitted.pop
26
- splitted.push stage, extension
27
- splitted.join('.')
28
- end
29
-
30
- def self.duplicate_local_dump_to_staged_dump()
31
- staged_file = append_stage_to_filename(fetch(:db_local_dump), fetch(:stage))
32
-
33
- FileUtils.cp(fetch(:db_local_dump), staged_file)
34
- end
35
-
36
- def self.local_stage?
37
- fetch(:local_stage_name).to_sym == fetch(:stage).to_sym
38
- end
39
-
40
- def self.execute_db_command_autodetect(cmd)
41
- cmd = "mysql #{Helper::mysql_auth_args} -e \"#{cmd}\""
42
-
43
- if fetch(:db_is_container)
44
- db_container = container_by_name fetch(:db_container_name)
45
- on_container db_container do |container|
46
- container.execute cmd
1
+ module Capistrano
2
+ module Container
3
+ module DB
4
+ module Helper
5
+ def self.mysql_dump_args
6
+ command = mysql_auth_args
7
+ command+= " #{fetch(:db_additional_dump_args).join(' ')} "
8
+ command+= " #{fetch(:db_name)}" unless fetch(:db_name).empty?
9
+ command
10
+ end
11
+
12
+ def self.mysql_restore_args
13
+ command = mysql_auth_args
14
+ command+= " #{fetch(:db_additional_restore_args).join(' ')} "
15
+ command+= " #{fetch(:db_name)}" unless fetch(:db_name).empty?
16
+ command
17
+ end
18
+
19
+ def self.mysql_auth_args
20
+ command = " -u #{fetch(:db_user)}"
21
+ command+= " -p#{fetch(:db_pass)}" unless fetch(:db_pass).empty?
22
+ command+= " #{fetch(:db_additional_auth_args).join(' ')} "
23
+ command
24
+ end
25
+
26
+ def self.append_stage_to_filename(file_name, stage = 'local')
27
+ splitted = file_name.split('.')
28
+ extension = splitted.pop
29
+ splitted.push stage, extension
30
+ splitted.join('.')
31
+ end
32
+
33
+ def self.duplicate_local_dump_to_staged_dump()
34
+ staged_file = append_stage_to_filename(fetch(:db_local_dump), fetch(:stage))
35
+
36
+ FileUtils.cp(fetch(:db_local_dump), staged_file)
37
+ end
38
+
39
+ def self.local_stage?
40
+ fetch(:local_stage_name).to_sym == fetch(:stage).to_sym
41
+ end
42
+
43
+ def self.execute_db_command_autodetect(cmd)
44
+ cmd = "mysql #{Helper::mysql_auth_args} -e \"#{cmd}\""
45
+
46
+ if fetch(:db_is_container)
47
+ db_container = container_by_name fetch(:db_container_name)
48
+ on_container db_container do |container|
49
+ container.execute cmd
50
+ end
51
+ else
52
+ execute_local_or_remote cmd
53
+ end
54
+ end
47
55
  end
48
- else
49
- execute_local_or_remote cmd
56
+
50
57
  end
51
58
  end
52
59
  end
@@ -1,32 +1,39 @@
1
1
  require_relative "helper.rb"
2
2
  require 'capistrano/container'
3
3
 
4
- module LoadHelper
5
- def self.import_on_local()
6
- LoadHelper.create_db_if_not_exists fetch(:db_name)
4
+ module Capistrano
5
+ module Container
6
+ module DB
7
+ module LoadHelper
8
+ def self.import_on_local()
9
+ LoadHelper.create_db_if_not_exists fetch(:db_name)
7
10
 
8
- run_locally do
9
- execute "mysql #{Helper::mysql_restore_args} < #{fetch(:db_local_dump)}"
10
- end
11
- end
11
+ run_locally do
12
+ execute "mysql #{Helper::mysql_restore_args} < #{fetch(:db_local_dump)}"
13
+ end
14
+ end
12
15
 
13
- def self.import_on_container(container)
14
- container.upload!(fetch(:db_local_dump), fetch(:db_remote_dump))
16
+ def self.import_on_container(container)
17
+ container.upload!(fetch(:db_local_dump), fetch(:db_remote_dump))
15
18
 
16
- LoadHelper.create_db_if_not_exists fetch(:db_name)
19
+ LoadHelper.create_db_if_not_exists fetch(:db_name)
17
20
 
18
- container.execute "mysql #{Helper::mysql_restore_args} < #{fetch(:db_remote_dump)}"
19
- end
21
+ container.execute "mysql #{Helper::mysql_restore_args} < #{fetch(:db_remote_dump)}"
22
+ end
20
23
 
21
- def self.import_on_server()
22
- upload!(fetch(:db_local_dump), fetch(:db_remote_dump))
24
+ def self.import_on_server()
25
+ upload!(fetch(:db_local_dump), fetch(:db_remote_dump))
23
26
 
24
- LoadHelper.create_db_if_not_exists fetch(:db_name)
27
+ LoadHelper.create_db_if_not_exists fetch(:db_name)
25
28
 
26
- execute("mysql #{Helper::mysql_restore_args} < #{fetch(:db_remote_dump)}")
27
- end
29
+ execute("mysql #{Helper::mysql_restore_args} < #{fetch(:db_remote_dump)}")
30
+ end
31
+
32
+ def self.create_db_if_not_exists(db)
33
+ Helper.execute_db_command_autodetect "CREATE DATABASE IF NOT EXISTS #{db};"
34
+ end
35
+ end
28
36
 
29
- def self.create_db_if_not_exists(db)
30
- Helper.execute_db_command_autodetect "CREATE DATABASE IF NOT EXISTS #{db};"
37
+ end
31
38
  end
32
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-container-db
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Hanoldt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-30 00:00:00.000000000 Z
11
+ date: 2018-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  version: '0'
107
107
  requirements: []
108
108
  rubyforge_project:
109
- rubygems_version: 2.5.1
109
+ rubygems_version: 2.6.14
110
110
  signing_key:
111
111
  specification_version: 4
112
112
  summary: Helps managing databases on local and remote stages, also on remote docker