drush-deploy 1.0.10 → 1.0.11

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.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- version 1.0.10
1
+ version 1.0.11
2
2
 
3
3
  ## DESCRIPTION
4
4
 
data/drush-deploy.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'drush-deploy'
3
- s.version = '1.0.10'
3
+ s.version = '1.0.11'
4
4
  s.summary = "Deployment strategy for Drupal using Drush"
5
5
  s.description = "Utilizes capistrano to allow for doing intellegent deployments of drupal projects."
6
6
  s.authors = ["Matt Edlefsen"]
@@ -158,12 +158,12 @@ module DrushDeploy
158
158
 
159
159
  def config(*args)
160
160
  options = (args.size>0 && args.last.is_a?(Hash)) ? args.pop : {}
161
- site_name = args[0] || :default
162
- db_name = args[1] || :default
163
- if databases[site_name] && databases[site_name][db_name]
164
- conf = databases[site_name][db_name].dup
161
+ db_name = args[0] || :default
162
+ instance_name = args[1] || :default
163
+ if databases[db_name] && databases[db_name][instance_name]
164
+ conf = databases[db_name][instance_name].dup
165
165
  else
166
- throw ConfigNotFound.new site_name,db_name
166
+ throw ConfigNotFound.new db_name,instance_name
167
167
  end
168
168
  if options[:admin] && conf[:admin_username]
169
169
  conf[:username] = conf[:admin_username]
@@ -184,8 +184,8 @@ module DrushDeploy
184
184
  end
185
185
  end
186
186
 
187
- def db_empty?(db = nil)
188
- conf = config
187
+ def db_empty?(db = nil, conf_name = nil)
188
+ conf = config(conf_name)
189
189
  conf[:database] = db if db
190
190
  db = conf[:database]
191
191
  if @db_status[db].nil?
@@ -200,8 +200,9 @@ module DrushDeploy
200
200
  @db_status[db]
201
201
  end
202
202
 
203
- def db_versions
204
- conf = config(:admin => true)
203
+ def db_versions(db = nil, conf_name = nil)
204
+ conf = config(conf_name,:admin => true)
205
+ conf[:database] = db if db
205
206
  throw FieldNotFound.new 'database' unless conf[:database]
206
207
  logger.info "Getting list of databases versions"
207
208
  sql = %q{SELECT SCHEMA_NAME FROM information_schema.SCHEMATA
@@ -209,8 +210,8 @@ module DrushDeploy
209
210
  (remote_sql(sql, :config => conf, :capture => true).split(/\n/)[1..-1] || []).sort.reverse
210
211
  end
211
212
 
212
- def db_exists?(db = nil)
213
- conf = config(:admin => true)
213
+ def db_exists?(db = nil, conf_name = nil)
214
+ conf = config(conf_name,:admin => true)
214
215
  conf[:database] = db if db
215
216
  throw FieldNotFound.new 'database' unless conf[:database]
216
217
  logger.info "Checking existence of #{conf[:database]}"
@@ -219,8 +220,8 @@ module DrushDeploy
219
220
  remote_sql(sql, :config => conf, :capture => true).split(/\n/)[1].to_i != 0
220
221
  end
221
222
 
222
- def db_tables(db = nil)
223
- conf = config(:admin => true)
223
+ def db_tables(db = nil, conf_name = nil)
224
+ conf = config(conf_name,:admin => true)
224
225
  conf[:database] = db if db
225
226
  db = conf[:database]
226
227
  throw FieldNotFound.new 'database' unless conf[:database]
@@ -235,10 +236,10 @@ module DrushDeploy
235
236
  tables
236
237
  end
237
238
 
238
- def copy_database(from,to)
239
+ def copy_database(from,to,conf_name = nil)
239
240
  logger.info "Copying database #{from} to #{to}"
240
- tables = db_tables
241
- conf = config(:database => from, :admin => true)
241
+ tables = db_tables(nil,conf_name)
242
+ conf = config(conf_name,:database => from, :admin => true)
242
243
 
243
244
  remote_sql("CREATE DATABASE #{to};", :config => conf)
244
245
  sql = ''
@@ -252,13 +253,13 @@ module DrushDeploy
252
253
  @db_status.delete(to)
253
254
  end
254
255
 
255
- def rename_database(from,to)
256
+ def rename_database(from,to,conf_name = nil)
256
257
  logger.info "Renaming database #{from} to #{to}"
257
- conf = config(:database => from, :admin => true)
258
+ conf = config(conf_name,:database => from, :admin => true)
258
259
  sql = ''
259
260
  if conf[:driver] == :mysql
260
261
  sql += "CREATE DATABASE `#{to}`;"
261
- db_tables(from).each do |table|
262
+ db_tables(from,conf_name).each do |table|
262
263
  sql += "RENAME TABLE `#{from}`.`#{table}` TO `#{to}`.`#{table}`;"
263
264
  end
264
265
  sql += "DROP DATABASE `#{from}`;"
@@ -269,9 +270,9 @@ module DrushDeploy
269
270
  @db_status.delete(to)
270
271
  end
271
272
 
272
- def drop_database(db)
273
+ def drop_database(db,conf_name = nil)
273
274
  logger.info "Dropping database #{db}"
274
- conf = config(:database => db, :admin => true)
275
+ conf = config(conf_name,:database => db, :admin => true)
275
276
  remote_sql("DROP DATABASE #{db};", :config => conf)
276
277
  @db_status[db] = false
277
278
  end
@@ -71,13 +71,16 @@ namespace :db do
71
71
  desc "Create a versioned backup of the database"
72
72
  task :create, :roles => :web do
73
73
  if releases.size > 1
74
- current = drupal_db.config[:database]
75
- backup = "#{current}_#{releases[-2]}"
76
- unless drupal_db.db_empty? or drupal_db.db_exists? backup
77
- on_rollback do
78
- drupal_db.drop_database backup
74
+ versioned_databases.each do |conf_name|
75
+ current = drupal_db.config(conf_name)[:database]
76
+ backup = "#{current}_#{releases[-2]}"
77
+ unless drupal_db.db_empty?(current,conf_name) or drupal_db.db_exists? backup,conf_name
78
+ on_rollback do
79
+ drupal_db.drop_database backup, conf_name
80
+ end
81
+ logger.info "Creating backup version of #{conf_name} database as #{backup}"
82
+ drupal_db.copy_database(current,backup,conf_name)
79
83
  end
80
- drupal_db.copy_database(current,backup)
81
84
  end
82
85
  end
83
86
  end
@@ -87,14 +90,17 @@ namespace :db do
87
90
  unless releases.size > 1
88
91
  throw DrushDeploy::Error.new "No previous versions to rollback to"
89
92
  end
90
- current = drupal_db.config[:database]
91
- release = releases.last
92
- source = "#{current}_#{releases[-2]}"
93
- backup = "#{current}_backup"
94
- if drupal_db.db_exists? source
95
- drupal_db.rename_database(current,backup)
96
- drupal_db.rename_database(source,current)
97
- drupal_db.drop_database(backup)
93
+ versioned_databases.each do |conf_name|
94
+ current = drupal_db.config(conf_name)[:database]
95
+ release = releases.last
96
+ source = "#{current}_#{releases[-2]}"
97
+ backup = "#{current}_backup"
98
+ if drupal_db.db_exists? source,conf_name
99
+ logger.info "Rolling back #{conf_name} database to #{source}"
100
+ drupal_db.rename_database(current,backup,conf_name)
101
+ drupal_db.rename_database(source,current,conf_name)
102
+ drupal_db.drop_database(backup,conf_name)
103
+ end
98
104
  end
99
105
  end
100
106
 
@@ -102,8 +108,11 @@ namespace :db do
102
108
  task :cleanup, :roles => :web do
103
109
  # Subtract one because the latest release won't be counted
104
110
  count = fetch(:keep_releases, 5).to_i - 1
105
- drupal_db.db_versions.drop(count).each do |db|
106
- drupal_db.drop_database(db)
111
+ versioned_databases.each do |conf_name|
112
+ logger.info "Cleaning up #{conf_name} database"
113
+ drupal_db.db_versions(nil,conf_name).drop(count).each do |db|
114
+ drupal_db.drop_database(db,conf_name)
115
+ end
107
116
  end
108
117
  end
109
118
  end
@@ -2,14 +2,10 @@ require 'drush_deploy/database'
2
2
 
3
3
  on :start, "drupal:load_targets"
4
4
  before "deploy", "drupal:setup_build"
5
- before "deploy:symlink", "drupal:symlink"
5
+ after "deploy:update_code", "drupal:symlink"
6
6
  before "deploy:setup", "drupal:setup"
7
7
  after "drupal:setup", "drupal:check_permissions"
8
- if version_database
9
- after "db:version:create", "drupal:clearcache"
10
- else
11
- after "deploy:update_code", "drupal:clearcache"
12
- end
8
+ before "deploy:symlink", "drupal:clearcache"
13
9
  before "drupal:install_profile", "db:drupal:configure"
14
10
 
15
11
  namespace :drupal do
@@ -42,3 +42,5 @@ set :configured, false
42
42
 
43
43
  set(:drush_cap) { DrushDeploy::Capistrano.new(self)}
44
44
  set(:drupal_db) { DrushDeploy::Database.new(self)}
45
+ set :versioned_databases, [:default]
46
+ set(:targets) { drush_cap.targets }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: drush-deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.10
4
+ version: 1.0.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-29 00:00:00.000000000 Z
12
+ date: 2012-08-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano