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?
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
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.
database_sample.yml
default: &default
adapter: postgresql
encoding: unicode
host: localhost
port: 5432
# For details on connection pooling, see Rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
development:
<<: *default
database: [name of app]_dev
test:
<<: *default
database: [name of app]_test
staging:
<<: *default
database: [name of app]
production:
<<: *default
database: [name of app]
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