How do I deploy my rails app to Heroku using an existing SQL database? - ruby-on-rails

I have an existing MySQL database and would like to build a Rails app on top of it. How do I deploy my app to Heroku but still use my existing database instead of the default PostgreSQL database?
EDIT
Rephrasing the question slightly (formerly, it was "Is it possible to deploy...").

Yes. You can configure your application any way you like including specifying a non-Heroku database in your config file, and including using the default Heroku paradigm of using environment variables for config but with manually set database URLs in the environment variables.
You can either continue hosting your MySQL database separately, or migrate your data to a MySQL database hosted within the Heroku platform, like ClearDB (provided as a Heroku add-on).

Yes, although Heroku recommends that you use PostgreSQL, it is possible to migrate MySQL to Postgres with their service. They have an article in their docs for just such a scenario: https://devcenter.heroku.com/articles/heroku-mysql
They recommend you first install the http://rubygems.org/gems/mysql2psql gem
If your needs are MySQL specific and you have to use heroku clearDB has and addon https://addons.heroku.com/cleardb that you can use with your heroku app.

Related

Connecting Rails to AWS MySQL database

I've recently created a rails app. I pushed the initial files onto github.
My problem is that I want to connect my rails app to AWS in order to use a MySQL database. I keep seeing tutorials on EC2 and Beanstalk, but I am not sure which one I should use. I have all the drivers needed for ruby through the gem installations.
I'm looking to figure out the main differences between Beanstalk and created a MySQL instance as well as what to put in my database.yml file in my rails app to connect to a database. Thank you in advance!
Just to give an idea, after you provision/create your instance on AWS (EC2 or wherever), you will then push your app's code to that remote server somewhere. You can do it manually via scripts, or you can use Capistrano for this. Once your app is deployed to the server, you need to connect to the server via SSH and manually edit the config/database.yml file to point to the staging/production MySQL database. (I'm generalizing, but I think you just need a step in the right direction.)

Deploying a Rails app to Heroku using SmartFile

I have deployed a Rails app to Heroku but most of my images and text are stored using Postgres and are only accessible locally, so my app is incomplete. I've done a PG dump of my database and I have an account with Smartfile, but I'm not sure how to use Smartfile with Heroku. I just want my app to access my files right now. Have any of you used Smartfile in conjunction with Heroku? Any advice would be appreciated. Thanks!
I decided not to use Smartfile and just used Heroku pg:push instead, as I don't think the app will be big enough to need more than the local database.

Should the database.yml be configured when testing locally for Heroku with foreman?

Can someone explain to me what they do when they initialise a rails app locally with foreman (part of Heroku toolbelt) (using postgreSQL), destined to run on Heroku?
I'm going by this guide: developing locally with foreman and what I don't understand is if we are expected to specify database username and passwords or if foreman is supposed to handle it as Heroku itself does?
This perplexes me a little as if we are supposed to modify the database.yml to hook it up to postgreSQL, then what is the point of using foreman instead of rails server?
If it does handle it, how does it handle it, and how would I configure my pg_hba.conf to respect it? Something like local all myuser trust?
Yes, database.yml needs to be configured with valid information for your development and test databases.
Foreman is only running what's in your Procfile, not ripping things out and plugging different things in like Heroku does.
So why do you want to use Foreman instead of rails server? Because it:
Runs all roles defined in your Procfile with one command
Automatically loads your .env
Will fail if any of your roles fail (so less scratching your head because some necessary backend service isn't running)

How do I sync a local rails database with a remote database?

I've used Taps before on Heroku, but what is a good solution on non-heroku rails apps?
You could create a capistrano task/s to mysqldump on the source database, gzip the file, then scp it to the destination and execute the mysql script there to import.
I wrote a Capistrano recipe some time ago to sync a MySQL database and files between different environments: https://gist.github.com/111597
OK, there are some things you need to keep in mind. If you are using SQlite for development and MySQL / Postgre for production on the server, then sinking is almost impossible. On the contrary if you are using the same DB engines you can use administrator interface like MySQL administrator on your desktop and generate a backup file and upload it to server and vice versa.
May hosting providers provide PHPMyAdmin to take backups and restore it on the server.

Use Heroku DB into Engine Yard

I am using postgresql database for my Heroku Application.
I have very large database on AmazonAws as heroku not providing the Postgresql Database.
Now my client want to switch to EngineYard from Heroku.
Can i use same database (w/o taking backup and then reload) for my application on the EngineYard?
If YES
How can i use or steps for using the Existing AmazonAws Database with the new EngineYard Application.
You can, but only if you are using a dedicated database. From the Heroku database FAQ
Shared Database
No, connecting to your database from machines outside of Heroku is not
supported. We recommend that you encapsulate data access in an API to
manipulate it.
Dedicated Database
It's possible to connect to our dedicated databases using our
pg:ingress feature. Please see using the PG console for more
information.
The database connection string is available in the DATABASE_URL config. You can run
$ heroku config --long
to view it. However, it won't probably work if you use a shared database because it seems connection is restricted to the Heroku net.
Surely this is just a case of getting the correct connection credentials for the DB regardless of where it's hosted?
For instance, if the DB is on Heroku, then ENV['DATABASE_URL'] give you everything you need. All these details then go in your database.yml as normal (assuming you're using ActiveRecord)
For the record, Heroku do provide Postgres and it's part of their core business.

Resources