Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Run db:migrate after deploy

  • Loading branch information...
commit ceb5ec422f95304aef13c8cba5b150983add00e6 1 parent 6446304
Gabe Berke-Williams gabebw authored
8 lib/kumade.rb
@@ -7,10 +7,14 @@ def self.load_tasks
7 7
8 8 class << self
9 9 attr_writer :staging, :production
  10 + attr_accessor :staging_app, :production_app
10 11
11   - def reset_remotes!
12   - @staging = nil
  12 + def reset!
  13 + @staging = nil
13 14 @production = nil
  15 +
  16 + @staging_app = nil
  17 + @production_app = nil
14 18 end
15 19
16 20 def staging
12 lib/kumade/deployer.rb
@@ -14,11 +14,13 @@ def pre_deploy
14 14 def deploy_to_staging
15 15 pre_deploy
16 16 git_force_push(Kumade.staging)
  17 + heroku_migrate(:staging)
17 18 end
18 19
19 20 def deploy_to_production
20 21 pre_deploy
21 22 git_force_push(Kumade.production)
  23 + heroku_migrate(:production)
22 24 end
23 25
24 26 def git_push(remote)
@@ -33,6 +35,16 @@ def git_force_push(remote)
33 35 announce "Force pushed master -> #{remote}"
34 36 end
35 37
  38 + def heroku_migrate(environment)
  39 + app = if environment == :staging
  40 + Kumade.staging_app
  41 + elsif environment == :production
  42 + Kumade.production_app
  43 + end
  44 +
  45 + run("bundle exec heroku rake db:migrate --app #{app}")
  46 + end
  47 +
36 48 def ensure_clean_git
37 49 if git_dirty?
38 50 raise "Cannot deploy: repo is not clean."
43 spec/deployer_spec.rb
@@ -30,6 +30,8 @@ class Kumade
30 30
31 31 describe Deployer, "#deploy_to_staging" do
32 32 it "calls the correct methods in order" do
  33 + subject.stub(:run => true)
  34 +
33 35 subject.should_receive(:pre_deploy).
34 36 ordered.
35 37 and_return(true)
@@ -39,11 +41,16 @@ class Kumade
39 41 with('staging').
40 42 and_return(true)
41 43
  44 + subject.should_receive(:heroku_migrate).
  45 + ordered.
  46 + with(:staging)
  47 +
42 48 subject.deploy_to_staging
43 49 end
44 50
45 51 it "deploys to Kumade.staging" do
46   - subject.stub(:pre_deploy => true)
  52 + subject.stub(:pre_deploy => true,
  53 + :run => true)
47 54 Kumade.staging = 'orange'
48 55
49 56 subject.should_receive(:git_force_push).with('orange')
@@ -54,6 +61,8 @@ class Kumade
54 61
55 62 describe Deployer, "#deploy_to_production" do
56 63 it "calls the correct methods in order" do
  64 + subject.stub(:run => true)
  65 +
57 66 subject.should_receive(:pre_deploy).
58 67 ordered.
59 68 and_return(true)
@@ -63,11 +72,16 @@ class Kumade
63 72 with('production').
64 73 and_return(true)
65 74
  75 + subject.should_receive(:heroku_migrate).
  76 + ordered.
  77 + with(:production)
  78 +
66 79 subject.deploy_to_production
67 80 end
68 81
69 82 it "deploys to Kumade.production" do
70   - subject.stub(:pre_deploy => true)
  83 + subject.stub(:pre_deploy => true,
  84 + :run => true)
71 85 Kumade.production = 'orange'
72 86
73 87 subject.should_receive(:git_force_push).with('orange')
@@ -462,4 +476,29 @@ class More
462 476 subject.more_installed?.should be_true
463 477 end
464 478 end
  479 +
  480 + describe Deployer, "#heroku_migrate" do
  481 + let(:staging_app) { 'staging-sushi' }
  482 + let(:production_app){ 'production-sushi' }
  483 +
  484 + before do
  485 + Kumade.reset!
  486 + Kumade.staging_app = staging_app
  487 + Kumade.production_app = production_app
  488 + end
  489 +
  490 + it "runs db:migrate with the correct staging app" do
  491 + subject.should_receive(:run).
  492 + with("bundle exec heroku rake db:migrate --app #{staging_app}")
  493 +
  494 + subject.heroku_migrate(:staging)
  495 + end
  496 +
  497 + it "runs db:migrate with the correct production app" do
  498 + subject.should_receive(:run).
  499 + with("bundle exec heroku rake db:migrate --app #{production_app}")
  500 +
  501 + subject.heroku_migrate(:production)
  502 + end
  503 + end
465 504 end
30 spec/kumade_spec.rb
... ... @@ -1,7 +1,7 @@
1 1 require 'spec_helper'
2 2
3 3 describe Kumade, "staging remote" do
4   - before { Kumade.reset_remotes! }
  4 + before { Kumade.reset! }
5 5 it "defaults to staging" do
6 6 Kumade.staging.should == 'staging'
7 7 end
@@ -12,8 +12,21 @@
12 12 end
13 13 end
14 14
  15 +describe Kumade, "staging app" do
  16 + before { Kumade.reset! }
  17 +
  18 + it "defaults to nil" do
  19 + Kumade.staging_app.should be_nil
  20 + end
  21 +
  22 + it "can be set" do
  23 + Kumade.staging_app = 'orange'
  24 + Kumade.staging_app.should == 'orange'
  25 + end
  26 +end
  27 +
15 28 describe Kumade, "production remote" do
16   - before { Kumade.reset_remotes! }
  29 + before { Kumade.reset! }
17 30
18 31 it "defaults to production" do
19 32 Kumade.production.should == 'production'
@@ -24,3 +37,16 @@
24 37 Kumade.production.should == 'orange'
25 38 end
26 39 end
  40 +
  41 +describe Kumade, "production app" do
  42 + before { Kumade.reset! }
  43 +
  44 + it "defaults to nil" do
  45 + Kumade.production_app.should be_nil
  46 + end
  47 +
  48 + it "can be set" do
  49 + Kumade.production_app = 'orange'
  50 + Kumade.production_app.should == 'orange'
  51 + end
  52 +end

0 comments on commit ceb5ec4

Please sign in to comment.
Something went wrong with that request. Please try again.