0

I'm mobile devices programmer and I'm a newbie in DB, web, server programming and this problem make me sick :(

I've dug all day long for this situation, and no answer solve my problem.

I have production.sqlite3 in my Ruby on Rails project, and this was in AWS server using sqlite3 DB in production mode.

Now I uploaded this application to heroku using postgresql DB with no data(empty), changing sqlite3 -> postgresql in production mode.

I want to transfer data in production.sqlite3 to empty remove postgresql DB.

How can I do that? I couldn't get the concept how I achieve this.

1) local sqlite3 -> remote empty postgresql DB directly ?

2) local sqlite3 -> local postgresql (migrate) -> remote empty postgresql DB ?

I installed postgresql92 (because of heroku remote postgresql version) via macports,

so the path is '/opt/local/lib/postgresql92'.

I tried

  • pg:transfer

  • psql

  • pg_ctl

and still have no idea to do this. please help me solve this situation.

1 Answer 1

1

It's best to use the same database in all environments. I can't post comments yet to ask for clarification so I'll try to answer your question. Sorry if I get too basic.

If you need to transfer data from an SQLite to a PostgreSQL database you'll have to do this manually with a tool such as https://github.com/ricardochimal/taps. You will have to setup the local PostgreSQL database and import the data from the SQL database. Then, you can push the data to heroku using:

db:push [<database_url>] # push a local database into the app's remote database

Add the PostgreSQL gem to the Gemfile

gem 'pg'

Example database.yml file for using PostgreSQL

development:
  adapter: postgresql
  encoding: unicode
  database: app_development
  pool: 5


test:
  adapter: postgresql
  encoding: unicode
  database: app_test
  pool: 5


production:
  adapter: postgresql
  encoding: unicode
  database: app_production
  pool: 5

Next, you'll need to create the database

rake db:create:all

Make sure after all this that the rails development database is psql (run rails db)

That's how you ensure rails is using psql.

Sign up to request clarification or add additional context in comments.

2 Comments

I heard heroku db:push and db:pull is deprecated. That why I'm look for other ways.
No, actually previous SQlite3 DB is for production and used about 1 year and that why I really want to transfer this DB to new one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.