I've set up two Heroku instances, one for production and one for
staging. When I deploy to staging I copy the production database over
(using "heroku db:pull" followed by "heroku db:push --app
cohuman-staging") and run all migrations (using "heroku rake
db:migrate --app cohuman-staging"). So far so good.

Sometimes we don't want to push to production right away; we need to
fix bugs or whatever on staging. But then we have to deploy to staging
again.

Here comes the problem: since I copy the production database again, I
need to run migrations again. But if one of those migrations renames a
table, I get a Postgres error:

/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract_adapter.rb:219:in
`log': An error has occurred, this and all later migrations canceled:
(StandardError)

PGError: ERROR:  relation "followings" already exists
: ALTER TABLE "interests" RENAME TO "followings"

Apparently "heroku db:push" doesn't clear out the database first, so
the old new table (if that makes sense) is still around.

My solution was to add the following in my "rename" migration:

  def self.up
    execute "DROP TABLE IF EXISTS followings"
    rename_table :interests, :followings
  end

It's kind of annoying, partly since this code is only necessary on
staging, so it's needlessly complicating things when run on
production...

I'd be interested to hear if anyone has any cleaner solutions. For
example, if I start using Heroku Bundles for backup, can I restore
from my production backup to my staging database? (I admit I haven't
used bundles yet and am sketchy on the details so feel free to RTFM
me.)

 - Alex

P.S. I've got a relatively clean rakefile for wrapping deploys to
Heroku with things like grepping git logs and sending an email; let me
know if anyone's interested and I'll post it in a gist or something.

---
Alex Chaffee - a...@cohuman.com - http://alexch.github.com
Stalk me: http://friendfeed.com/alexch | http://twitter.com/alexch |
http://alexch.tumblr.com

-- 
You received this message because you are subscribed to the Google Groups 
"Heroku" group.
To post to this group, send email to her...@googlegroups.com.
To unsubscribe from this group, send email to 
heroku+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/heroku?hl=en.

Reply via email to