Run heroku migrations on each deploy by piggybacking on assets:precompile

A simple solution to an annoying problem!

# Rakefile
task "assets:precompile" => "db:migrate" if ENV['MIGRATE_ON_PRECOMPILE']

# run to enable
heroku config:set MIGRATE_ON_PRECOMPILE=1

Config files for heroku or duostack

To get config variables to herkou / duostack simply base64 encode them and store them into the ENV.
The cfg.rb is kept very simple, so you can also load it where rails is not yet loaded.
This scales to up to 3900 characters for duostack and 10000+ for heroku. Add gzip to get even more…

# lib/cfg.rb
require 'active_support/core_ext/hash/indifferent_access'

env = defined?(Rails.env) ? Rails.env : (ENV['RAILS_ENV'] || 'development')
config = if encoded = ENV['CONFIG_YML']
  require 'base64'
CFG = YAML.load(config)[env].with_indifferent_access.freeze

# config/application.rb
require File.expand_path('../../lib/cfg', __FILE__)

# script/configure_heroku.rb
#! /usr/bin/env ruby
require 'rubygems'
require 'rake'
require 'base64'

config = Base64.encode64('config/config.heroku.yml')).gsub("\n","")
sh "heroku config:add CONFIG_YML=#{config}"