0

I need to add a property/column to a table in a production database(Postgre) on Heroku.com (Rails app) by doing migration. When I do the migration it looks ok, but when I view the columns on the table it has has not added the column!

My development db is sqlite3 and the production db is postgre

I do the following:

heroku run rails generate migration AddUtc_OffsetToEvents utc_offset:integer RAILS_ENV=production --app app-name-1111

and it returns:

invoke  active_record
      create    db/migrate/20130304070946_add_utc_offset_to_events.rb

And then I run the migration

heroku run rake db:migrate RAILS_ENV=production --app app-name-1111 

And then:

heroku restart

When I run

heroku pg:psql HEROKU_POSTGRESQL_GRAY_URL --app app-name-1111

and check the columns of the table:

\d+ events

It still does not have the utc_offset column, and no errors are displyed while doing the previous cmds.

Any ideas or hints?

jacob
  • 541
  • 1
  • 9
  • 19
  • What are the contents of the migration file? And why are you creating migrations in production? You should be doing that in dev first. – Richard Brown Mar 04 '13 at 14:27
  • Content of migration: `class AddUtcOffsetToEvents < ActiveRecord::Migration def change add_column :events, :utc_offset, :integer end end ` This is necessary as the migration done in dev was not added to version control by mistake before deploying to heroku – jacob Mar 04 '13 at 15:12
  • Can you try without `RAILS_ENV=production`? That may be screwing up the Toolbelt when it parses the command. `RAILS_ENV=production` will be automatic in this case anyway. `heroku run rake db:migrate --app app-name-1111` – catsby Mar 04 '13 at 17:19

2 Answers2

2

It looks like you are doing several calls to heroku run

Each time you do heroku run it spins up a completely new dyno with your latest code, and when run is over that dyno is destroyed. So the second heroku run does not have the migration filed created in the first.

Since you are already familiar with psql you can just use ALTER TABLE directly. Otherwise you'll need to check your migration into your code and git push heroku master it to heroku, then run it.

Will
  • 2,921
  • 16
  • 12
0

Why not just download the code, add the migration and push the changes ? After, just run the heroku run rake db:migrate on the app.

Mihai
  • 1,254
  • 2
  • 15
  • 27