Heroku application reads database.yml file

From what I can compile, Heroku should automatically generate the database.yml file and ignore the local one. However, I see an error where this is not the case, and my changes to local database.yml affect the Heroku application. This is problematic because I have no idea how to set up the production part of the file so that Heroku can find the database I need.

For example, with the following

production: adapter: sqlite3 database: db/production.sqlite3 pool: 5 timeout: 5000 

and then db: migration

 $:~/Apps/DancingCupid/DancingCupid$ heroku rake --trace db:migrate 

spits out

 rake aborted! unable to open database file /app/.bundle/gems/ruby/1.8/gems/activerecord-3.0.5/lib/active_record/connection_adapters/sqlite3_adapter.rb:27:in `initialize' ... 

I can get different errors depending on what type of database I sent for production.

Besides removing the application and creating a new one, is there any way to fix this problem?

+4
source share
5 answers

Heroku definitely rewrites your .yml database to push, so it doesn't matter what version control is there.

To confirm this, make a heroku run bash that connects you to the bash session in your application, and then look at cat config\database.yml and you will see how they rewrote it.

+6
source

Other answers NOT TRUE longer by 4.1 the Rails .

config / database.yml will no longer be overwritten when Rails 4.1.0 RC1 application is detected. Instead, it will be combined with DATABASE_URL, so additional parameters, such as pool size, can be set in config / database.yml.

To double check the contents of your .yml database on a Heroku server, you can run remote bash via heroku run bash and then cat config/database.yml to view its contents on the server and compare with your local one.

+4
source

I don’t think you are crazy! (But I thought I was)

I searched for this problem several times over the course of several days and finally found this article: http://article.gmane.org/gmane.comp.lang.ruby.rails.heroku/1003/match=database+yml

It made me believe that maybe it wasn’t my code at all!

Then I just destroyed the heroku application and created a new one and clicked on it. Suddenly, everything works fine! I do not know how and when and why, but I think that it is possible to overwrite or corrupt the database.yml file created by Heroku.

Hope this helps!

+2
source

Try removing database.yml from version control. It is good practice to make a copy of database.yml with something like database.yml.example and add database.yml to your .gitignore file.

Thus, when you click on Heroku, it will not have any database configuration.

You probably also don’t want the sqlite3 created gem to be produced. Make sure it is in the development / testing team in your Gemfile.

+1
source

database.yml should not be specified in Heroku. It will try to connect to this database, timeout and then fail.

Add it to your .gitignore so that it doesn't get up there.

-1
source

Source: https://habr.com/ru/post/1345498/


All Articles