0

I'm new on RoR. I build a little app using ActiveAdmin and Devise and I wish to deploy it on Heroku.

When I had push my app on Heroku it run properly but the db seems to be empty ! In effect, my local login dont match when I try to log in my ActiveAdmin administration panel...

In addition, the others db of my app are totaly empty...

I guess that i had not fill the database.yml correctly but I dont find how I'm suppose to do it... :/

Database.yml :

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
default: &default
  adapter: sqlite3
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000

development:
  <<: *default
  database: db/development.sqlite3

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: db/test.sqlite3

production:
  <<: *default
  database: db/production.sqlite3

I would be grateful if you could help me or direct me to a solution!

Thank you for your attention ! ^^

2 Answers2

0
production:
  <<: *default
  database: db/production.sqlite3

You can't use sqlite3 on heroku, because it is filesystem-based and on each restart a new dyno is created, with a completely new filesystem. The old dyno is killed and your sqlite3 data file with it.

Use a client-server DB on heroku, like Postgresql. This is well covered in heroku guides.

Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367
  • Ty for your answer :) How I'm suppose to "ask" that to my app ? – Emilien Lecoffre Jul 18 '18 at 19:55
  • @EmilienLecoffre: that's too big a topic for a small answer and it's out of scope anyway. Also it's very well described in the internets. Start with googling sometihng like "rails use postgresql on heroku" – Sergio Tulentsev Jul 18 '18 at 19:59
  • I changed : production: adapter: postgresql pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> timeout: 5000 database: db/production.pg And now I'm able to edit the db on the online app but, is it possible to push the content of a local db in a production db ? – Emilien Lecoffre Jul 18 '18 at 20:14
0

These steps is how to push the local database to heroku and to create database

heroku pg:backups:restore 'https://s3.amazonaws.com/me/items/3H0q/mydb.dump' DATABASE_URL
  1. Get database info

    heroku pg
    

-> Gave me the name of the database eg: HEROKU_POSTGRESQL_CYAN

  1. Reset the database on heroku

    heroku pg:reset HEROKU_POSTGRESQL_CYAN
    
  2. Look for the name of the local database

    • Opened config/database.yml and found the database name for the development environment. eg: fashions_development => put the name that the terminal give it to you
  3. Run push the local database to Heroku Opened config/database.yml and found the database

    heroku pg:push fashions_development HEROKU_POSTGRESQL_CYAN
    
nourza
  • 2,215
  • 2
  • 16
  • 42
  • I already done these steps and it work exactly like you. My problem is that my local db informations has not been pushed into my production db :( – Emilien Lecoffre Jul 19 '18 at 06:50
  • rake db:migrate will only create your database structure – nourza Jul 19 '18 at 07:05
  • So how to push both structure AND data ? ^^ – Emilien Lecoffre Jul 19 '18 at 07:11
  • @EmilienLecoffre I just edit the answer its how to push the local data base to heroku in four steps. Try it and let me know if you need any help! – nourza Jul 19 '18 at 07:47
  • Ty for this edit :) In a first time : I had the "The local psql command could not be located ! For help installing psql, see local-postgresql" error that I have fixed by installing PostgreSQL and update manualy my PATH variable. Then I get the following error :( $ heroku pg:push db/development.sqlite3 DATABASE_URL heroku-cli: Pushing db/development.sqlite3 ---> postgresql-flat-56203 pg_dump: [programme d'archivage (db)] la connexion à la base de données « db » a échoué : FATAL: role "Lecoffre Emilien" does not exist – Emilien Lecoffre Jul 20 '18 at 07:11
  • According to this link (https://www.1and1.com/cloud-community/learn/database/postgresql/solve-the-postgresql-error-psql-fatal-database-root-does-not-exist/), the problem coming from my PostgreSQL Username... :/ I search currently how to modify it – Emilien Lecoffre Jul 20 '18 at 07:36
  • here they answer my question that i think is similar to yours https://stackoverflow.com/questions/50311186/changing-sqlite-to-postgresql-in-ruby-on-rails – mrpepo877 Jul 21 '18 at 06:13