Uable to run migration on heroku on a postgre database - ruby-on-rails-3

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?

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.

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.

Related

Rails 4 Engine not migrating migrations

I created a new rails 4 engine and added a model. I am trying to migrate the database using
RAILS_ENV=test rake db:migrate
and it comes back with no errors. However, when I run:
rspec spec
an error returns stating there are pending migrations.
Migrations are pending; run 'rake db:migrate RAILS_ENV=test' to resolve this issue. (ActiveRecord::PendingMigrationError)
It's true if I look at my database (tried on pg and sqlite) that they have not been run and no tables have been created. Running the suggested command listed above does not run the migrations.
There is only one migration in 'engine_name/db/migrate', and no migrations inside the dummy app.
I am using ruby 2.0 and rails 4.0.0.rc1.
You need to copy migrations into dummy app rake app:<engine_name>:install:migrations
Add code in your engine task
https://gist.github.com/doabit/5692865 .
I've experienced this same issue. doabit's fix worked for me. thanks!
There is an open issue for this with the rails core team.
https://github.com/rails/rails/issues/10622

How can I run oink in heroku?

I'm having a problem running the oink gem on my app in Heroku. I've included it in my gemfile and gemfile.lock, uploaded those, and it installs. It even creates the oink.log (which I have no way of viewing, unfortunately). When I run
heroku run bundle exec oink --threshold=0 log/* --app my_app
I get
Running bundle exec oink --threshold=0
log/delayed_job.log log/development.log log/oink.log log/production.log log/test.log attached to terminal... up, run.3
/app/.bundle/gems/ruby/1.8/gems/oink-0.9.3/bin/../lib/oink/cli.rb:88:in get_file_listing':
Could not find "log/delayed_job.log" (RuntimeError)
from /app/.bundle/gems/ruby/1.8/gems/oink-0.9.3/bin/../lib/oink/cli.rb:86:ineach'
from /app/.bundle/gems/ruby/1.8/gems/oink-0.9.3/bin/../lib/oink/cli.rb:86:in get_file_listing'
from /app/.bundle/gems/ruby/1.8/gems/oink-0.9.3/bin/../lib/oink/cli.rb:59:inprocess'
from /app/.bundle/gems/ruby/1.8/gems/oink-0.9.3/bin/oink:4
from /app/.bundle/gems/ruby/1.8/bin/oink:19:in 'load'
from /app/.bundle/gems/ruby/1.8/bin/oink:19
I've tried running each of the individual files, too, and get the same result. This command runs fine on my local machine.
In my production.rb file, I have
config.logger = Hodel3000CompliantLogger.new(config.paths.log.first)
config.middleware.use( Oink::Middleware )
as configuration.
Can you enlighten me on what I'm doing wrong here? My understanding is that the logs are read only, but I don't know if that means they're only accessible through the heroku logs command. If there's a way I can see the oink.log file, too--knowing how to do that is also appreciated, or knowing how to see it in the actual Heroku log using heroku logs.
UPDATE: The configuration for oink shown above allows the commands to be run successfully on my localhost.
Thanks!
-Andrew

Automate a cross-environment db restore in Heroku

I have two heroku environments and I'd like to copy the latest backup of the Production database to my Development environment.
With the CLI, this is easy:
heroku pgbackups:restore DATABASE `heroku pgbackups:url --app Production` --app Development --confirm Development
But I'd like to automate this. So I made it a rake task that uses the heroku_api gem. This should allow to call it from the Heroku Scheduler.
task :auto_refresh do
#heroku = Heroku::API.new(...)
#heroku.post_ps('Development', 'heroku pgbackups:restore DATABASE `heroku pgbackups:url --app Production` --app Development --confirm Development')
end
This does not work. All it does is refresh Development from the latest Development backup.
Any ideas how I can automate this?
Using the 'heroku' gem (not 'heroku-api' gem), you can manipulate the list of backups from one app to another
When you install the pgbackups addon, it creates a config variable PGBACKUPS_URL. You'll need to use this value in your Dev app like so:
# Get the latest backup
client = Heroku::Client::Pgbackups.new('https://bigmessything#pgbackups.heroku.com/client')
backup = client.get_latest_backup
backup['public_url] should contain the URL you want to restore from using the code you have above

Queue_Classic: How to run the rake task automatically on Heroku without Procfile

i need to know how to run the queue_classic (rake qc:work) rake task automatically on Heroku. I tried with Procfile, but i am using Bamboo and i get the next error: "Heroku push rejected, Procfile is not supported on the Bamboo stack"
any idea??
Thanks.
On heroku there is a addon viz heroku-scheduler, its free. Add this addon to your application. It will appear in your application addon lists, click it, and you will lead to worker dashboard where you can add job for example
bundle exec rake task_name
and schedule the task.

delayed job starts but does not process any jobs in production

I have a rails app using delayed job, it works fine in development.
However, when I pushed to production it doesn't do anything.
Delayed job starts up fine using either one of these commands:
RAILS_ENV=production rake jobs:work
or
RAILS_ENV=production script/delayed_job start
However, once the process has started it just sits there and does not process any of the jobs in the delayed_backend_mongoid table.
I checked the delayed_job.log and it shows that the process starts up fine but does not throw any errors.
And for the heck of it I checked the production.log and there are no errors there as well.
Also if I run
RAILS_ENV=production rake jobs:clear
It will delete the jobs that are in the que, so I don't think it has an issue communicating with mongodb.
I'm using
Rails 3.1.1
gem 'delayed_job'
gem 'delayed_job_mongoid'
Any insight will be greatly appreciated.
Ok so I finally got it to work, it wasn't related to delayed job at all. It had to do with the ruby gem Anemone. Anemone could not get proper authorization to the mongodb. Fixed, thanks anyways.