squasher icon indicating copy to clipboard operation
squasher copied to clipboard

Squasher couldn't load `database.yml`. Please, make sure that it's present and doesn't include any ruby code.

Open YutoYasunaga opened this issue 3 years ago • 3 comments

Hello, this issue happen recently. When I run squasher, this error occurred:

Squasher couldn't load database.yml. Please, make sure that it's present and doesn't include any ruby code.

And this is my config/database.yml file:

default: &default
  adapter: mysql2
  encoding: utf8mb4
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: root
  password: docker
  host: '127.0.0.1'

development:
  <<: *default
  database: tiengnhatit_development

test:
  <<: *default
  database: tiengnhatit_test

YutoYasunaga avatar Jan 11 '22 15:01 YutoYasunaga

I think this is related to Ruby 3.1 which upgrades to Psych 4.0.

  • Psych 4.0 changes Psych.load to use safe_load by default. You may need to use Psych 3.3.2 for migrating to this behavior. [Bug #17866]

(Source: https://www.ruby-lang.org/en/news/2021/12/25/ruby-3-1-0-released/)

The corresponding PR can be found here:

  • https://github.com/ruby/psych/pull/487

.safe_load uses aliases: false meaning that if you have something like this

default: &default

test:
  <<: *default

the load won't work anymore. One solution would be to use YAML.unsafe_load here

https://github.com/jalkoby/squasher/blob/714ac99d549adc05b31af664ad5354ccaeb6393f/lib/squasher/config.rb#L13

or maybe something like this YAML.load_file(path, aliases: true)?

lxxxvi avatar Jan 19 '22 10:01 lxxxvi

I think this is related to Ruby 3.1 which upgrades to Psych 4.0.

  • Psych 4.0 changes Psych.load to use safe_load by default. You may need to use Psych 3.3.2 for migrating to this behavior. [Bug #17866]

(Source: https://www.ruby-lang.org/en/news/2021/12/25/ruby-3-1-0-released/)

The corresponding PR can be found here:

.safe_load uses aliases: false meaning that if you have something like this

default: &default

test:
  <<: *default

the load won't work anymore. One solution would be to use YAML.unsafe_load here

https://github.com/jalkoby/squasher/blob/714ac99d549adc05b31af664ad5354ccaeb6393f/lib/squasher/config.rb#L13

or maybe something like this YAML.load_file(path, aliases: true)?

Thank you very much. I temporary resolved that by duplicate code in database.yml

development:
  adapter: mysql2
  encoding: utf8mb4
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: root
  password: docker
  host: '127.0.0.1'
  database: imeezi_development

test:
  adapter: mysql2
  encoding: utf8mb4
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: root
  password: docker
  host: '127.0.0.1'
  database: imeezi_test

YutoYasunaga avatar Jan 25 '22 16:01 YutoYasunaga

@YutoYasunaga Yeah, that should do the trick too. You can revert it after you squashed the migrations.

However, I'd keep the issue open here, because it looks like it should be fixed. 👀

lxxxvi avatar Jan 25 '22 16:01 lxxxvi

Hi there! Any news?

n-rodriguez avatar Mar 03 '23 05:03 n-rodriguez

Hi there! Any news?

Seems like this commit should fix it. If so, issue should be closed.

airled avatar Mar 07 '23 13:03 airled

yes, version 0.7.2 is released

jalkoby avatar Mar 07 '23 14:03 jalkoby