I have an existing Ruby on Rails app that already has data loaded into it.
I used the default SQLite database setup, so that is where all my data is located, but I need all my data to go into my Postgres database on heroku.
How do I do that?
I have an existing Ruby on Rails app that already has data loaded into it.
I used the default SQLite database setup, so that is where all my data is located, but I need all my data to go into my Postgres database on heroku.
How do I do that?
10 Minutes Move from Local SQLite to a Heroku Postgres
-- updates your local dev to postgres along the way --
This is assuming you have a development database in sqlite and you want to move the structure and data to heroku. You will be first changing your local environment to postgres, then moving it all up.
Why change? You should always have your development environment mirror your production environment. Using Postgres is the default on heroku.
You will need to install and configure Postgres locally first with a user that has your username
Software needed: postgresql, pgloader, heroku-cli
Steps
Move from SQLite to Postgres on your dev environment
gem 'pg'
to main section of your Gemfilepgloader ./db/development.sqlite3 postgresql:///[name of postgres dev db]
gem 'sqlite3'
rails server
Setup new app on heroku
Follow these instructions from heroku
Move data to heroku
heroku pg:info
heroku pg:reset DATABASE_URL --app [name of app]
heroku pg:push [name of postgres dev db] DATABASE_URL --app [name of app]
NOTE: if that database has greater than 10k rows, you will also need to upgrade to a hobby-basic tier on heroku
Upgrading Heroku to Hobby Tier Basic
heroku pg:info
heroku maintenance:on --app [name of app]
heroku pg:copy DATABASE_URL [HEROKU_POSTGRESQL_COLOR_URL] --app [name of app]
heroku pg:promote [HEROKU_POSTGRESQL_COLOR_URL] --app [name of app]
In case you run into issues or edge cases, here are some resources to help.
Resources:
database_sample.yml
Hey dude you have all you need inside the link below
How to change from SQLite to PostgreSQL and deploy on heroku
let me know if you any more doubts regards