Skip to content
Browse files

Run db:migrate after deploy

  • Loading branch information...
1 parent 6446304 commit ceb5ec422f95304aef13c8cba5b150983add00e6 @gabebw gabebw committed Jul 26, 2011
Showing with 87 additions and 6 deletions.
  1. +6 −2 lib/kumade.rb
  2. +12 −0 lib/kumade/deployer.rb
  3. +41 −2 spec/deployer_spec.rb
  4. +28 −2 spec/kumade_spec.rb
View
8 lib/kumade.rb
@@ -7,10 +7,14 @@ def self.load_tasks
class << self
attr_writer :staging, :production
+ attr_accessor :staging_app, :production_app
- def reset_remotes!
- @staging = nil
+ def reset!
+ @staging = nil
@production = nil
+
+ @staging_app = nil
+ @production_app = nil
end
def staging
View
12 lib/kumade/deployer.rb
@@ -14,11 +14,13 @@ def pre_deploy
def deploy_to_staging
pre_deploy
git_force_push(Kumade.staging)
+ heroku_migrate(:staging)
end
def deploy_to_production
pre_deploy
git_force_push(Kumade.production)
+ heroku_migrate(:production)
end
def git_push(remote)
@@ -33,6 +35,16 @@ def git_force_push(remote)
announce "Force pushed master -> #{remote}"
end
+ def heroku_migrate(environment)
+ app = if environment == :staging
+ Kumade.staging_app
+ elsif environment == :production
+ Kumade.production_app
+ end
+
+ run("bundle exec heroku rake db:migrate --app #{app}")
+ end
+
def ensure_clean_git
if git_dirty?
raise "Cannot deploy: repo is not clean."
View
43 spec/deployer_spec.rb
@@ -30,6 +30,8 @@ class Kumade
describe Deployer, "#deploy_to_staging" do
it "calls the correct methods in order" do
+ subject.stub(:run => true)
+
subject.should_receive(:pre_deploy).
ordered.
and_return(true)
@@ -39,11 +41,16 @@ class Kumade
with('staging').
and_return(true)
+ subject.should_receive(:heroku_migrate).
+ ordered.
+ with(:staging)
+
subject.deploy_to_staging
end
it "deploys to Kumade.staging" do
- subject.stub(:pre_deploy => true)
+ subject.stub(:pre_deploy => true,
+ :run => true)
Kumade.staging = 'orange'
subject.should_receive(:git_force_push).with('orange')
@@ -54,6 +61,8 @@ class Kumade
describe Deployer, "#deploy_to_production" do
it "calls the correct methods in order" do
+ subject.stub(:run => true)
+
subject.should_receive(:pre_deploy).
ordered.
and_return(true)
@@ -63,11 +72,16 @@ class Kumade
with('production').
and_return(true)
+ subject.should_receive(:heroku_migrate).
+ ordered.
+ with(:production)
+
subject.deploy_to_production
end
it "deploys to Kumade.production" do
- subject.stub(:pre_deploy => true)
+ subject.stub(:pre_deploy => true,
+ :run => true)
Kumade.production = 'orange'
subject.should_receive(:git_force_push).with('orange')
@@ -462,4 +476,29 @@ class More
subject.more_installed?.should be_true
end
end
+
+ describe Deployer, "#heroku_migrate" do
+ let(:staging_app) { 'staging-sushi' }
+ let(:production_app){ 'production-sushi' }
+
+ before do
+ Kumade.reset!
+ Kumade.staging_app = staging_app
+ Kumade.production_app = production_app
+ end
+
+ it "runs db:migrate with the correct staging app" do
+ subject.should_receive(:run).
+ with("bundle exec heroku rake db:migrate --app #{staging_app}")
+
+ subject.heroku_migrate(:staging)
+ end
+
+ it "runs db:migrate with the correct production app" do
+ subject.should_receive(:run).
+ with("bundle exec heroku rake db:migrate --app #{production_app}")
+
+ subject.heroku_migrate(:production)
+ end
+ end
end
View
30 spec/kumade_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
describe Kumade, "staging remote" do
- before { Kumade.reset_remotes! }
+ before { Kumade.reset! }
it "defaults to staging" do
Kumade.staging.should == 'staging'
end
@@ -12,8 +12,21 @@
end
end
+describe Kumade, "staging app" do
+ before { Kumade.reset! }
+
+ it "defaults to nil" do
+ Kumade.staging_app.should be_nil
+ end
+
+ it "can be set" do
+ Kumade.staging_app = 'orange'
+ Kumade.staging_app.should == 'orange'
+ end
+end
+
describe Kumade, "production remote" do
- before { Kumade.reset_remotes! }
+ before { Kumade.reset! }
it "defaults to production" do
Kumade.production.should == 'production'
@@ -24,3 +37,16 @@
Kumade.production.should == 'orange'
end
end
+
+describe Kumade, "production app" do
+ before { Kumade.reset! }
+
+ it "defaults to nil" do
+ Kumade.production_app.should be_nil
+ end
+
+ it "can be set" do
+ Kumade.production_app = 'orange'
+ Kumade.production_app.should == 'orange'
+ end
+end

0 comments on commit ceb5ec4

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