webmat (owner)

Revisions

gist: 118061 Download_button fork
public
Public Clone URL: git://gist.github.com/118061.git
Embed All Files: show embed
deploy.pending.migrations.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Our deployment tags are s or p followed by YYmmdd-HHMMSS
namespace :deploy do
  namespace :pending do
    desc "Show the list of new migrations since the last deployments to staging and production"
    task :migrations do
      tags = run_locally("git tag").split
      staging = tags.grep(/\As\d{6}-\d{6}\Z/).sort.last
      production = tags.grep(/\Ap\d{6}-\d{6}\Z/).sort.last
      %w(staging production).each do |stage|
        puts '', stage
        result = run_locally %(git diff --numstat #{ eval(stage) }..master | grep "db\/migrate")
        puts(result.strip == '' ? '(none)' : result.gsub(/\d*\t\d*\t/, '') )
      end
    end
  end
end
 
=begin
Example output:
$ cap deploy:pending:migrations
triggering start callbacks for `deploy:pending:migrations'
* executing `multistage:ensure'
*** Defaulting to `staging'
* executing `staging'
* executing `deploy:pending:migrations'
executing locally: "git tag"
 
staging
executing locally: "git diff --numstat s090525-165241..master | grep \"db/migrate\""
(none)
 
production
executing locally: "git diff --numstat p090522-090244..master | grep \"db/migrate\""
db/migrate/20090511155004_create_audits.rb
=end