Skip to content

Instantly share code, notes, and snippets.

@pcreux
Created August 2, 2012 10:28

Revisions

  1. pcreux revised this gist Aug 2, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion migrate.rb
    Original file line number Diff line number Diff line change
    @@ -45,7 +45,7 @@ def db_name
    heroku! "pgbackups:restore #{db_name} --confirm #{app_name}"
    heroku! "pg:promote #{db_name}"
    heroku! "maintenance:off"
    heroku! "addons:remove shared-database --confirm#{app_name}"
    heroku! "addons:remove shared-database --confirm #{app_name}"


    puts "Done!"
  2. pcreux revised this gist Aug 2, 2012. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion migrate.rb
    Original file line number Diff line number Diff line change
    @@ -45,6 +45,7 @@ def db_name
    heroku! "pgbackups:restore #{db_name} --confirm #{app_name}"
    heroku! "pg:promote #{db_name}"
    heroku! "maintenance:off"
    heroku! "addons:remove shared-database --confirm#{app_name}"


    puts "Done!"
    puts "Done!"
  3. pcreux revised this gist Aug 2, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion migrate.rb
    Original file line number Diff line number Diff line change
    @@ -18,8 +18,8 @@ def app_name
    def heroku(cmd)
    full_cmd = "heroku #{cmd} -a #{app_name}"
    puts full_cmd

    system full_cmd
    true
    end

    def heroku!(cmd)
  4. pcreux created this gist Aug 2, 2012.
    50 changes: 50 additions & 0 deletions migrate.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    #!/usr/bin/env ruby
    #
    # This script migrates your Heroku app from a Shared DB to a Postgres `dev` Plan
    #
    # Usage:
    # ruby migrate.rb [app_name]
    #

    def usage
    puts "migrate.rb [app_name]"
    exit 0
    end

    def app_name
    ARGV.first or usage
    end

    def heroku(cmd)
    full_cmd = "heroku #{cmd} -a #{app_name}"
    puts full_cmd
    system full_cmd
    true
    end

    def heroku!(cmd)
    heroku(cmd) or exit 1
    end

    def db_name
    return @db_name if @db_name

    config_output = `heroku config -a #{app_name} | grep POSTGRESQL`
    @db_name = config_output.match(/(HEROKU_POSTGRESQL_\w+)_URL/)[1]
    raise "Can't extract db_color from config_output" if @db_name.nil?

    @db_name
    end

    puts "Let's migrate #{app_name} over to Heroku Postgres Dev Plan"

    heroku "addons:add heroku-postgresql:dev"
    heroku "addons:add pgbackups"
    heroku! "maintenance:on"
    heroku! "pgbackups:capture --expire"
    heroku! "pgbackups:restore #{db_name} --confirm #{app_name}"
    heroku! "pg:promote #{db_name}"
    heroku! "maintenance:off"


    puts "Done!"