2

I have deployed a rails app to heroku, using mysql database hosted on a remote server. For this I have added the heroku addon 'cleardb' and setup correct ENV Config vars specifying:

DATABASE_URL = mysql2://user:password@host?reconnect=true

I have also setup Heroku continuous deployment for three branches, (branch -> environment)

develop -> devint,
staging -> staging,
master -> production

Continuous deployment works fine, and the database is setup fine too (because when I create a record in rails app, I can see the data in remote mysql host).

My issue is that when I enable HEROKU CI, the build fails every time with an error saying Mysql2::Error: Can't connect to MySQL server on '127.0.0.1' (111)

Full error here: https://gist.github.com/siddhantbhardwaj/dab7c435815e7729d0f70081449f21ff#file-gistfile1-txt

This occurs when Heroku CI tries to perform rake db:schema:load_if_ruby for the :test env

My database.yml looks like:

default: &default
  adapter: mysql2
  encoding: utf8
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  database: what_course_development
  username: user
  password: password
  socket: /tmp/mysql.sock

test:
  <<: *default
  database: what_course_test

devint:
  <<: *default
  url: <%= ENV['DATABASE_URL'] %>

staging:
  <<: *default
  url: <%= ENV['DATABASE_URL'] %>

production:
  <<: *default
  url: <%= ENV['DATABASE_URL'] %>
Siddhant
  • 293
  • 1
  • 3
  • 8

1 Answers1

1

Please review below suggestion for configure your database.yml from DATABASE_URL:

DatabaseUrl.to_active_record_hash('postgres://uuu:xxx@127.0.0.1:1234/abc')

This will provide the below result:

{:adapter=>"postgres", :host=>"127.0.0.1", :port=>1234, :database=>"abc", :user=>"uuu", :password=>"xxx"}

Please refer seamusabshere database_url for more information.

  • Hi Darpan, do you want me to use the above command to convert DATABASE_URL into ruby hash and use that in database.yml? If so, I think heroku config of DATABASE_URL is working fine, it is just that the Heroku CI build fails when it tries to prepare database for test env. – Siddhant Jun 22 '18 at 02:38
  • Yes i was suggested you the same and as per your comment i think you have fixed the issue, Thanks Siddhant. – Darpan Chhatravala Jun 25 '18 at 08:39
  • No, the database was already working fine and records are saved in the database, but Heroku CI build fails with the error mentioned in the question. – Siddhant Jun 27 '18 at 02:24
  • @Siddhant did you ever figure this out? I am running into a similar issue My thought is that the 127... in your error gist means that it is trying to connect to a local mysql instance inside the heroku-ci dyno. This won't work. I am thinking I instead need to set up a remote database for the test environment but am getting errors as I initially try to connect to a custom Amazon RDS DB – Dan Nov 22 '18 at 02:04