capistrano-exts 1.11.1 → 1.11.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,7 +18,7 @@ gem install capistrano-exts
18
18
  or add it to your Gemfile
19
19
 
20
20
  ```ruby
21
- gem 'capistrano-exts', '>=1.11.1', :require => false
21
+ gem 'capistrano-exts', '>=1.11.2', :require => false
22
22
  ```
23
23
 
24
24
  # Setup
@@ -103,6 +103,12 @@ set :mysql_db_name, -> { "#{fetch :application}_#{fetc
103
103
  # NOTE: This is only used if you run deploy:server:setup which calls mysql:create_db_user
104
104
  set :mysql_db_user, -> { "#{fetch :application}" }
105
105
 
106
+ # Tables to skip on import
107
+ # set :skip_tables_on_import, [
108
+ # 'tl_formdata',
109
+ # 'tl_formdata_details',
110
+ # ]
111
+
106
112
  # Where the database credentials are stored on the server ?
107
113
  set :mysql_credentials_file, -> { "#{deploy_to}/.mysql_password"}
108
114
 
@@ -102,6 +102,12 @@ set :mysql_db_name, -> { "#{fetch :application}_#{fetc
102
102
  # What is the database user ?
103
103
  set :mysql_db_user, -> { "#{fetch :application}" }
104
104
 
105
+ # Tables to skip on import
106
+ set :skip_tables_on_import, [
107
+ 'tl_formdata',
108
+ 'tl_formdata_details',
109
+ ]
110
+
105
111
  # Where the database credentials are stored on the server ?
106
112
  set :mysql_credentials_file, -> { "#{deploy_to}/.mysql_password"}
107
113
 
@@ -102,6 +102,12 @@ set :mysql_db_name, -> { "#{fetch :application}_#{fetc
102
102
  # What is the database user ?
103
103
  set :mysql_db_user, -> { "#{fetch :application}" }
104
104
 
105
+ # Tables to skip on import
106
+ # set :skip_tables_on_import, [
107
+ # 'tl_formdata',
108
+ # 'tl_formdata_details',
109
+ # ]
110
+
105
111
  # Where the database credentials are stored on the server ?
106
112
  set :mysql_credentials_file, -> { "#{deploy_to}/.mysql_password"}
107
113
 
@@ -104,6 +104,11 @@ set :mysql_db_name, -> { "#{fetch :application}_#{fetc
104
104
  # What is the database user ?
105
105
  set :mysql_db_user, -> { "#{fetch :application}" }
106
106
 
107
+ # Tables to skip on import
108
+ # set :skip_tables_on_import, [
109
+ # 'sessions',
110
+ # ]
111
+
107
112
  # Where the database credentials are stored on the server ?
108
113
  set :mysql_credentials_file, -> { "#{deploy_to}/.mysql_password"}
109
114
 
@@ -104,6 +104,11 @@ set :mysql_db_name, -> { "#{fetch :application}_#{fetc
104
104
  # What is the database user ?
105
105
  set :mysql_db_user, -> { "#{fetch :application}" }
106
106
 
107
+ # Tables to skip on import
108
+ # set :skip_tables_on_import, [
109
+ # 'sessions',
110
+ # ]
111
+
107
112
  # Where the database credentials are stored on the server ?
108
113
  set :mysql_credentials_file, -> { "#{deploy_to}/.mysql_password"}
109
114
 
@@ -104,6 +104,11 @@ set :mysql_db_name, -> { "#{fetch :application}_#{fetc
104
104
  # What is the database user ?
105
105
  set :mysql_db_user, -> { "#{fetch :application}" }
106
106
 
107
+ # Tables to skip on import
108
+ # set :skip_tables_on_import, [
109
+ # 'sessions',
110
+ # ]
111
+
107
112
  # Where the database credentials are stored on the server ?
108
113
  set :mysql_credentials_file, -> { "#{deploy_to}/.mysql_password"}
109
114
 
@@ -104,6 +104,11 @@ set :mysql_db_name, -> { "#{fetch :application}_#{fetc
104
104
  # What is the database user ?
105
105
  set :mysql_db_user, -> { "#{fetch :application}" }
106
106
 
107
+ # Tables to skip on import
108
+ # set :skip_tables_on_import, [
109
+ # 'sessions',
110
+ # ]
111
+
107
112
  # Where the database credentials are stored on the server ?
108
113
  set :mysql_credentials_file, -> { "#{deploy_to}/.mysql_password"}
109
114
 
@@ -104,6 +104,11 @@ set :mysql_db_name, -> { "#{fetch :application}_#{fetc
104
104
  # What is the database user ?
105
105
  set :mysql_db_user, -> { "#{fetch :application}" }
106
106
 
107
+ # Tables to skip on import
108
+ # set :skip_tables_on_import, [
109
+ # 'sessions',
110
+ # ]
111
+
107
112
  # Where the database credentials are stored on the server ?
108
113
  set :mysql_credentials_file, -> { "#{deploy_to}/.mysql_password"}
109
114
 
@@ -104,6 +104,11 @@ set :mysql_db_name, -> { "#{fetch :application}_#{fetc
104
104
  # What is the database user ?
105
105
  set :mysql_db_user, -> { "#{fetch :application}" }
106
106
 
107
+ # Tables to skip on import
108
+ # set :skip_tables_on_import, [
109
+ # 'sessions',
110
+ # ]
111
+
107
112
  # Where the database credentials are stored on the server ?
108
113
  set :mysql_credentials_file, -> { "#{deploy_to}/.mysql_password"}
109
114
 
@@ -8,9 +8,7 @@ $: << ROOT_PATH if File.directory?(ROOT_PATH) and not $:.include?(ROOT_PATH)
8
8
  require 'capistrano-exts/core_ext'
9
9
 
10
10
  # require Capistrano colors
11
- require 'capistrano/configuration'
12
11
  require 'capistrano/logger'
13
- require 'capistrano_colors/configuration'
14
12
  require 'capistrano_colors/logger'
15
13
 
16
14
  # Printed credentials
@@ -23,7 +21,7 @@ Capistrano::Logger.add_color_matcher({ :match => /WARNING:/, :color => :yellow,
23
21
  Capistrano::Logger.add_color_matcher({ :match => /ERROR:/, :color => :red, :level => Capistrano::Logger::IMPORTANT, :prio => -20 })
24
22
 
25
23
  # Require requested receipts
26
- require 'capistrano-exts/receipts'
24
+ require 'capistrano-exts/receipts' if defined?(Capistrano::Configuration)
27
25
 
28
26
  # Require all servers
29
27
  Dir["#{ROOT_PATH}/capistrano-exts/servers/*.rb"].each { |f| require f }
@@ -187,6 +187,9 @@ Capistrano::Configuration.instance(:must_exist).load do
187
187
  # Create the database
188
188
  find_and_execute_task("mysql:create_db")
189
189
 
190
+ # Backup skiped tables
191
+ find_and_execute_task "mysql:backup_skiped_tables"
192
+
190
193
  run <<-CMD
191
194
  mysql \
192
195
  --host='#{mysql_credentials[:host]}' \
@@ -202,6 +205,9 @@ Capistrano::Configuration.instance(:must_exist).load do
202
205
  rm -f '#{random_file}'
203
206
  CMD
204
207
 
208
+ # Restore skiped tables
209
+ find_and_execute_task "mysql:restore_skiped_tables"
210
+
205
211
  # Exit because capistrano will rollback, the next argument is a file name and not a task
206
212
  # TODO: Find a better solution!
207
213
  exit 0
@@ -247,6 +253,65 @@ Capistrano::Configuration.instance(:must_exist).load do
247
253
  end
248
254
  end
249
255
 
256
+ desc "[internal] Backup tables listed in skip_tables_on_import"
257
+ task :backup_skiped_tables, :roles => :db, :except => { :no_release => true } do
258
+ if exists?(:skip_tables_on_import)
259
+ mysql_credentials = fetch :mysql_credentials
260
+ # Generate a random file
261
+ random_file = random_tmp_file
262
+ # Set the random file so it can be accessed later
263
+ set :backuped_skiped_tables_file, random_file
264
+ # Add a rollback hook
265
+ on_rollback { run "rm -f #{random_file}" }
266
+
267
+ run <<-CMD
268
+ #{try_sudo} touch #{random_file}
269
+ CMD
270
+
271
+ fetch(:skip_tables_on_import).each do |t|
272
+ begin
273
+ run <<-CMD
274
+ #{try_sudo} mysqldump \
275
+ --host='#{mysql_credentials[:host]}'\
276
+ --user='#{mysql_credentials[:user]}' \
277
+ --password='#{mysql_credentials[:pass]}' \
278
+ --default-character-set=utf8 \
279
+ '#{mysql_db_name}' '#{t}' >> \
280
+ '#{random_file}'
281
+ CMD
282
+ rescue Capistrano::CommandError
283
+ logger.info "WARNING: It seems the database does not have the table '#{t}', skipping it."
284
+ end
285
+ end
286
+ end
287
+ end
288
+
289
+ desc "[internal] Restore tables listed in skip_tables_on_import"
290
+ task :restore_skiped_tables, :roles => :db, :except => { :no_release => true } do
291
+ if exists?(:skip_tables_on_import) && exists?(:backuped_skiped_tables_file)
292
+ mysql_credentials = fetch :mysql_credentials
293
+ backuped_skiped_tables_file = fetch :backuped_skiped_tables_file
294
+
295
+ begin
296
+ run <<-CMD
297
+ mysql \
298
+ --host='#{mysql_credentials[:host]}' \
299
+ --user='#{mysql_credentials[:user]}' \
300
+ --password='#{mysql_credentials[:pass]}' \
301
+ --default-character-set=utf8 \
302
+ '#{mysql_db_name}' < \
303
+ #{backuped_skiped_tables_file}
304
+ CMD
305
+
306
+ run <<-CMD
307
+ #{try_sudo} rm -f #{backuped_skiped_tables_file}
308
+ CMD
309
+ rescue
310
+ abort "ERROR: I couldn't restore the tables defined in skip_tables_on_import"
311
+ end
312
+ end
313
+ end
314
+
250
315
  ['credentials', 'root_credentials'].each do |var|
251
316
  desc "print database #{var.gsub(/_/, ' ')}"
252
317
  task "print_#{var}" do
@@ -349,4 +414,8 @@ Capistrano::Configuration.instance(:must_exist).load do
349
414
 
350
415
  before "mysql:print_credentials", "mysql:credentials"
351
416
  before "mysql:print_root_credentials", "mysql:root_credentials"
417
+
418
+ # Import_db_dump => backup/restore skiped_tables
419
+ before "mysql:backup_skiped_tables", "mysql:credentials"
420
+ before "mysql:restore_skiped_tables", "mysql:credentials"
352
421
  end
@@ -101,6 +101,11 @@ set :mysql_db_name, -> { "#{fetch :application}_#{fetc
101
101
  # What is the database user ?
102
102
  set :mysql_db_user, -> { "#{fetch :application}" }
103
103
 
104
+ # Tables to skip on import
105
+ # set :skip_tables_on_import, [
106
+ # 'sessions',
107
+ # ]
108
+
104
109
  # Where the database credentials are stored on the server ?
105
110
  set :mysql_credentials_file, -> { "#{deploy_to}/.mysql_password"}
106
111
 
@@ -3,7 +3,7 @@ module Capistrano
3
3
  module Version #:nodoc:
4
4
  MAJOR = 1
5
5
  MINOR = 11
6
- TINY = 1
6
+ TINY = 2
7
7
 
8
8
  ARRAY = [MAJOR, MINOR, TINY]
9
9
  STRING = ARRAY.join(".")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-exts
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.1
4
+ version: 1.11.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-09-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
16
- requirement: &2161329300 !ruby/object:Gem::Requirement
16
+ requirement: &2156995460 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.8.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2161329300
24
+ version_requirements: *2156995460
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: capistrano_colors
27
- requirement: &2161320280 !ruby/object:Gem::Requirement
27
+ requirement: &2156994900 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.5.5
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2161320280
35
+ version_requirements: *2156994900
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: i18n
38
- requirement: &2161318720 !ruby/object:Gem::Requirement
38
+ requirement: &2156994320 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.6.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2161318720
46
+ version_requirements: *2156994320
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: activesupport
49
- requirement: &2161317140 !ruby/object:Gem::Requirement
49
+ requirement: &2156993520 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 3.1.0
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *2161317140
57
+ version_requirements: *2156993520
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: guard
60
- requirement: &2161316040 !ruby/object:Gem::Requirement
60
+ requirement: &2156992300 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.6.2
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2161316040
68
+ version_requirements: *2156992300
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: guard-bundler
71
- requirement: &2161315140 !ruby/object:Gem::Requirement
71
+ requirement: &2156991500 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.1.3
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2161315140
79
+ version_requirements: *2156991500
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: guard-rspec
82
- requirement: &2161314480 !ruby/object:Gem::Requirement
82
+ requirement: &2156990900 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 0.4.3
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2161314480
90
+ version_requirements: *2156990900
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rspec
93
- requirement: &2161312120 !ruby/object:Gem::Requirement
93
+ requirement: &2156990240 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: 2.6.0
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *2161312120
101
+ version_requirements: *2156990240
102
102
  description: ! 'Capistrano exts is a set of helper tasks to help with the initial
103
103
  server
104
104