hanami / cli

Hanami command line
MIT License
28 stars 31 forks source link

Fix no implicit conversion of nil into String for schema_migrations_sql_dump #239

Closed bkuhlmann closed 3 weeks ago

bkuhlmann commented 1 month ago

Why

Hello. :wave: When attempting to run bundle exec hanami db prepare on a newly created Hanami application which has no migrations, you'll send up with the following:

Stack Dump ``` /demo/.cache/frum/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/cli-8b48ea139f46/lib/hanami/cli/commands/app/db/utils/postgres.rb:63:in `schema_migrations_sql_dump': no implicit conversion of nil into String (TypeError) private ^^^^^^^ from /demo/.cache/frum/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/cli-8b48ea139f46/lib/hanami/cli/commands/app/db/structure/dump.rb:35:in `block (4 levels) in call' from /demo/.cache/frum/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/cli-8b48ea139f46/lib/hanami/cli/commands/app/db/structure/dump.rb:34:in `open' from /demo/.cache/frum/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/cli-8b48ea139f46/lib/hanami/cli/commands/app/db/structure/dump.rb:34:in `block (3 levels) in call' from /demo/.cache/frum/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/cli-8b48ea139f46/lib/hanami/cli/commands/app/db/structure/dump.rb:25:in `catch' from /demo/.cache/frum/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/cli-8b48ea139f46/lib/hanami/cli/commands/app/db/structure/dump.rb:25:in `block (2 levels) in call' from /demo/.cache/frum/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/cli-8b48ea139f46/lib/hanami/cli/commands/app/command.rb:105:in `measure' from /demo/.cache/frum/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/cli-8b48ea139f46/lib/hanami/cli/commands/app/db/structure/dump.rb:24:in `block in call' from /demo/.cache/frum/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/cli-8b48ea139f46/lib/hanami/cli/commands/app/db/structure/dump.rb:20:in `each' from /demo/.cache/frum/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/cli-8b48ea139f46/lib/hanami/cli/commands/app/db/structure/dump.rb:20:in `call' from /demo/.cache/frum/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/cli-8b48ea139f46/lib/hanami/cli/commands/app/command.rb:40:in `call' from /demo/.cache/frum/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/cli-8b48ea139f46/lib/hanami/cli/commands/app/db/command.rb:37:in `run_command' from /demo/.cache/frum/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/cli-8b48ea139f46/lib/hanami/cli/commands/app/db/migrate.rb:28:in `call' from /demo/.cache/frum/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/cli-8b48ea139f46/lib/hanami/cli/commands/app/command.rb:40:in `call' from /demo/.cache/frum/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/cli-8b48ea139f46/lib/hanami/cli/commands/app/db/command.rb:37:in `run_command' from /demo/.cache/frum/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/cli-8b48ea139f46/lib/hanami/cli/commands/app/db/prepare.rb:52:in `block (2 levels) in call' from /demo/.cache/frum/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/cli-8b48ea139f46/lib/hanami/cli/commands/app/db/prepare.rb:51:in `catch' from /demo/.cache/frum/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/cli-8b48ea139f46/lib/hanami/cli/commands/app/db/prepare.rb:51:in `block in call' from /demo/.cache/frum/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/cli-8b48ea139f46/lib/hanami/cli/commands/app/db/prepare.rb:43:in `each' from /demo/.cache/frum/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/cli-8b48ea139f46/lib/hanami/cli/commands/app/db/prepare.rb:43:in `call' from /demo/.cache/frum/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/cli-8b48ea139f46/lib/hanami/cli/commands/app/command.rb:40:in `call' from /demo/.cache/frum/versions/3.3.5/lib/ruby/gems/3.3.0/gems/dry-cli-1.1.0/lib/dry/cli.rb:116:in `perform_registry' from /demo/.cache/frum/versions/3.3.5/lib/ruby/gems/3.3.0/gems/dry-cli-1.1.0/lib/dry/cli.rb:65:in `call' from /demo/.cache/frum/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/cli-8b48ea139f46/exe/hanami:11:in `' from bin/hanami:6:in `load' from bin/hanami:6:in `
' ```

How

To recreate, build a new Hanami 2.2.0, Beta 2 application with the following structure:

demo/config/db

You only need an empty db folder to cause this issue to trigger.

Notes

To fix, you'd only need to use string interpolation in the Hanami::CLI::Commands::App::DB::Utils::Postgres. Like this:

# No
+"SET search_path TO #{search_path};\n\n" << super

# Yes
"SET search_path TO #{search_path};\n\n#{super}"

This might effect other databases but not sure. I'm only using PostgreSQL at the moment.

timriley commented 3 weeks ago

Thanks @bkuhlmann! This is fixed now, and will be included in the next pre-release, which I'm currently planning to do next week.