Two different databases - ruby-on-rails

Is it possible to have two different databases for development or production? One for Heroku and one for local development?
Heroku uses PostgreSQL but I prefer SQLlite for local development.

yes, it's totally possible - you can then use heroku db:push to push your local SQLite database into postgres running on Heroku.
BUT
And this is from personal experience, I've run into situations where SQL I've written is different between sqlite/postgres/mysql AND also gems I've used which themselves used findbysql which weren't tested against postgres and has then caught my out when I've put it on Heroku.
For the few seconds it takes to install postgres locally I would STRONGLY recommend you use the DB platform you are ultimately going to deploy to.

Related

Rails app can't find connect to postgres after working on a different app for a while

So I just need to direction on understanding a postgres installation better, because clearly I only know enough to be dangerous.
I had an app that was my project with a postgres DB installed via homebrew
Then I started collaborating on a project with other people
There was some difficulty getting my existing prostgres install to work with the new project so I installed the postgres app with the gui interface to start stop the db.
That new project is finished and I wanted to get back to work on my other project
When I started the first app up, it couldn't find a db. I tried drop the db, and recreating it, but when I run the migrations it says the tables already exist.
What can I do to get around this?
A good approach would be using Docker so everyone have the same environment. This would mean even you, across your machines or your working colleagues or collaborators would have the same environment. You could have many containers running (watching exposing different ports for Postgres, i.e: 5433...) and when a project finishes just get rid of the container.
This approach saves you the overhead of having to maintain multiple databases locally or depending on a running Postgres process (which I sometimes forget to start).
If you need to solve this locally, try starting your postgres service, connecting to your localhost instance and running:
> psql
psql (9.6.2)
Type "help" for help.
> \l
and you should see all of your databases and debug them. Perhaps deleting and creating the conflicting database (if you don't need your local data) could help.

how to export postgres database from aws rds

I have a Rails 4 app deployed to Elastic Beanstalk using Postgresql. My question is: what is the best way (or a good way) to export the database?
I tried to use pg_dump from the ec2 instance which is part of the RDS security group but the ec2 instance has a different postgres version (9.2.9). I was also unable to make this happen using the AWS console.
Any general advice on how best to proceed would be much appreciated.
pg_dump is the way to go, but sounds like you'll just need to ensure that the host running pg_dump is running with the same version as the RDS server instance.

How to copy production database to another production server - Rails

I am creating a Rails app for work and until I can install the app on a "in house" server, I am deploying it to Heroku so that we can start using it now. However, I am going to want to be able to copy its database with all of its data over to the final production server when I ready. I am assuming this is somehow possible, but I don't know where to start. Is there a way you can copy a production database (Postgres) from Heroku and move it to a new server to be used there? How would one go about doing this with Rails?
Heroku provides all of this functionality via the PGBackups plugins. There you'll find everything you need to know about importing, exporting, etc...

Creating and deploying new Heroku applications with a Rails application hosted on Heroku

I have a rails application running on heroku. I would like to make that application to create & deploy other applications on heroku.
Since the Cedar stack allows writing to the filesystem I can generate the files needed for the new application. My question is how to issue the "heroku create" and "git push heroku master" commands for deployment.
Is there any gems out there / can I use the heroku CLI in heroku together with the ruby system call?
You can do everything that you need to do Heroku wise with the Heroku gem. Bear in mind though that this will need credentials to authenticate, so you'll need to be happy with storing these in the applications config.
From a git point of view, use ruby-git.
It's probably worth looking at making whatever it is you're making multi-tenanted so you don't have to worry about this problem, and also won't have to worry about hundreds of applications to maintain (updates, bugfixes and the like)

Emulating Heroku on local computer

I'm new to Heroku and Ruby on Rails and this may seem trivial. But I could not find the answer.
The Google App Engine has a web server application that emulates all of the App Engine services on local computer. Does Heroku have something similar?
Basically I want to run/debug RoR app on local machine before pushing it to Heroku.
If you are on the Cedar stack, there is a local utility called foreman that can read your procfile to simulate how it will run on Heroku. More info about it is on Dev Center here:
https://devcenter.heroku.com/articles/procfile#developing-locally-with-foreman
Heroku CLI has the local command to run your app locally. Without options, it will run the processes defined in the Procfile in the app root, using any environment variables defined in .env:
heroku local
For configuration options such as using different paths for .env and Procfile and local subcommands see: https://devcenter.heroku.com/articles/heroku-local
I use http://pow.cx/ and https://github.com/Rodreegez/powder for that. Is not emulating Heroku, but it allows you to set up a 'production' environment quickly.
Also, check http://devcenter.heroku.com/articles/multiple-environments and consider if you need a staging deploy.
Nothing like that exists for Heroku but to be honest you don't really need it. Develop locally, use Ruby 1.9.2 as that's the heroku default these days - keep in mind the constraints of Heroku http://devcenter.heroku.com/categories/platform-constraints. Use Postgres locally since that is what heroku shared DB is and you'll be off to a good start.

Resources