How to have Rails migrations run automatically on Heroku - ruby-on-rails

I have more than 10 different Ruby on Rails apps where I have to deploy the same code. I have connected the git repo to my Heroku apps, so whenever I push new changes it deploys on all of them.
The issue is with the database migration step. I want to run migrations automatically after each deployment. None of custom build pack is working. Can someone please help me? I am using rails 4 and spree.
So far, I have tried:
https://github.com/heroku/heroku-buildpack-ruby.git
https://github.com/gunpowderlabs/buildpack-ruby-db-migrate.git
This solution is not working.
Is there any other solution to run Rails migrations on Heroku automatically?

No need to use gems or write scripts.
Heroku have a 'release' phase features (https://devcenter.heroku.com/articles/release-phase).
Thank to this, you just have to add to your Procfile some code to automatically run rake db:migrate to all your push :
Procfile (root app)
release: rake db:migrate

You can use Travis-ci. Pretty simple to setup and provides the desired functionality

Add gem 'iconv', '~> 1.0.3' to your gemfile and then try it will work as worked for me!
I take this as a duplicate of this answer
If you are looking for alternative then you can write a deploy script in .sh file and run it everytime like bash script.

Related

Rails 5 console not working when deploying with Capistrano

I amm using Rails 5, and I have half way deployed my app through Capistrano on server. due to specific need to loadschema, i ssh in and cd into the release/### directory and tried to run
rails --version # came out 5.0.3beta
bundle # works, everything installed
rails c # but this fail
running rails db:migrate also failed.
it seems to return rails generic help as like my directory isn't a rails directory.
i tried deleting bin folder, but still the same.
anyone know what could be wrong?
thank you
It seems you're using capistrano to deploy your application. Have a look at this issue: https://github.com/capistrano/bundler/issues/45
The solution would be:
remove bin from the linked_dirs
add set :bundle_binstubs, nil to your config/deploy.rb to generate the binstubs
To run the console try rails console. To run a migration try rake db:migrate

Heroku automatic db backup via cron job

Is it possible to backup Heroku database using cron jobs?
I tried putting the following line into cron.rake:
heroku pgbackups:capture --expire
However it didn't work. The line works when I run it from Terminal.
Can you help?
Check out the heroku_s3_backup gem, which packages up the code necessary to do this in a neat way.
The gem heroku_backup_task integrates directly with the free PG Backups add-on for Heroku.

Facebooker-rails3 installation problem?

I am trying to install facebooker-rails3 plugin like this
rails plugin install git://github.com/kulbirsaini/facebooker-rails3.git
it does install in it vendor directory but it doesnt create facebooker.yml
should it create it all?
if not thn where should i configure facebook settings?
Thanks
The plugin adds some useful tasks to rake.
you should run the rake task command on the console on the rails project directory:
rake facebooker:setup
After that the facebooker.yml is created and is pretty straight forward to complete.
Hope you find it useful.
Greetings!

Can some one summarize briefly what each line is doing here please?

Just got this RoR app working, and just want some clarification to what exactly went on behind the scenes, briefly so I can look into each step:
Clone the git repo
git clone git://github.com/railsdog/spree.git spree
cd spree
Install the gem dependencies
bundle install
Create a sanbox rails application for testing purposes
rails new sandbox -m sample/sandbox_template.rb
cd sandbox
Generate the necessary Spree files
rails g spree:install
Bootstrap the database (run the migrations, create seed data, optionally load sample data.)
rake db:migrate db:seed db:sample
Start the server
rails server
I know what the 1st line is doing, git clone ...
But does bundle install download all the dependancies from what file?
Where does the call to rails g spree:install look to generate the files?
I know rake is like 'make', but is it really compiling new code?
Or does rake just run the migration scripts etc. i.e. no compiling going on.
Let's go through it step-by-step:
git clone git://github.com/railsdog/spree.git spree
This checks out the latest code from git to the directory spree
bundle install
This parses the Gemfile in your directory and installs the dependencies for your application accordingly.
rails new sandbox -m sample/sandbox_template.rb
This creates a new rails project from a rails-template, this template instructs rails to generate the application with certain pre-defined parameters.
rails g spree:install
A generator that comes with spree that has instructions on how to make your spree application ready for use.
rake db:migrate db:seed db:sample
Migration the database migrations and feel the application with seed and demo-date.
Rake might compile certain things, if the sqlite gem needs to be installed for instance rake will make sure you compile it correctly. It differs per situation.

Rails Dreamhost Cron Job

I'm trying to get some cron jobs going through Dreamost using their panel. I'm also using rake to execute these jobs
My rake files are located in
app/lib/tasks/example.rake
But I don't know what code to give the panel to execute them
My recommendation would be to avoid trying to do that in the first place.
Editing cron jobs manually is a pain in the ass, and rails has some nice utilities to avoid it.
There's a railscast on using the wheneverize gem to prvent these problems.
http://asciicasts.com/episodes/164-cron-in-ruby
If you want these cron jobs to be automatically updated every time you deploy to dreamhost, just put it in as part of your Capistrano deploy.rb
If you're not using Capistrano, I strongly recommend you look into:
http://www.capify.org/index.php/Capistrano
EDIT
If you do want to take the DH cron route, the following should work
cd /full/path/to/your/project && rake example
if you're using rake, you could put
rake whatevertask
in the command field

Resources