AR ホームベーカリー

オイラのアウトプット用ホームベーカリー!

NullDB not configured. Require a framework, ex 'nulldb/rails'

huh?

なにこれ

GithubActions で Docker ビルドする際、表題の通り assets:precompile でコケるようになった。 ので、ローカルで再現を試みた。

RAILS_ENV=production DATABASE_ADAPTER=nulldb SECRET_KEY_BASE=dummy bundle exec rails assets:precompile

... snip ...

rails aborted!
NullDB not configured. Require a framework, ex 'nulldb/rails'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/activerecord-nulldb-adapter-1.0.1/lib/nulldb/core.rb:15:in `configuration'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/activerecord-nulldb-adapter-1.0.1/lib/active_record/connection_adapters/nulldb_adapter/core.rb:141:in `columns'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.6/lib/active_record/connection_adapters/schema_cache.rb:112:in `block in columns'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.6/lib/active_record/connection_adapters/schema_cache.rb:111:in `fetch'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.6/lib/active_record/connection_adapters/schema_cache.rb:111:in `columns'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.6/lib/active_record/connection_adapters/schema_cache.rb:120:in `block in columns_hash'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.6/lib/active_record/connection_adapters/schema_cache.rb:119:in `fetch'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.6/lib/active_record/connection_adapters/schema_cache.rb:119:in `columns_hash'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.6/lib/active_record/model_schema.rb:553:in `load_schema!'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.6/lib/active_record/attributes.rb:250:in `load_schema!'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.6/lib/active_record/model_schema.rb:539:in `block in load_schema'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.6/lib/active_record/model_schema.rb:536:in `synchronize'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.6/lib/active_record/model_schema.rb:536:in `load_schema'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.6/lib/active_record/model_schema.rb:392:in `columns_hash'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.6/lib/active_record/model_schema.rb:447:in `column_for_attribute'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/flipper-active_record-1.2.2/lib/flipper/adapters/active_record.rb:280:in `value_not_text?'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/flipper-active_record-1.2.2/lib/flipper/adapters/active_record.rb:57:in `initialize'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/flipper-active_record-1.2.2/lib/flipper/adapters/active_record.rb:294:in `new'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/flipper-active_record-1.2.2/lib/flipper/adapters/active_record.rb:294:in `block (2 levels) in <main>'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/flipper-1.2.2/lib/flipper/adapter_builder.rb:41:in `to_adapter'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/flipper-1.2.2/lib/flipper/configuration.rb:29:in `adapter'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/flipper-1.2.2/lib/flipper/engine.rb:54:in `block (3 levels) in <class:Engine>'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/flipper-1.2.2/lib/flipper/configuration.rb:65:in `default'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/flipper-1.2.2/lib/flipper.rb:46:in `instance'
/Users/donbulinux/Workspace/example/config/initializers/feature_switch.rb:4:in `block in <main>'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/lazy_load_hooks.rb:68:in `block in execute_hook'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/lazy_load_hooks.rb:61:in `with_execution_control'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/lazy_load_hooks.rb:66:in `execute_hook'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/lazy_load_hooks.rb:51:in `each'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/railties-6.1.7.6/lib/rails/application/finisher.rb:140:in `block in <module:Finisher>'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/railties-6.1.7.6/lib/rails/initializable.rb:32:in `instance_exec'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/railties-6.1.7.6/lib/rails/initializable.rb:32:in `run'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/railties-6.1.7.6/lib/rails/initializable.rb:61:in `block in run_initializers'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/railties-6.1.7.6/lib/rails/initializable.rb:60:in `run_initializers'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/railties-6.1.7.6/lib/rails/application.rb:391:in `initialize!'
/Users/donbulinux/Workspace/example/config/environment.rb:7:in `<main>'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.13/lib/zeitwerk/kernel.rb:34:in `require'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/dependencies.rb:332:in `block in require'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/dependencies.rb:299:in `load_dependency'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/dependencies.rb:332:in `require'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/railties-6.1.7.6/lib/rails/application.rb:367:in `require_environment!'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/railties-6.1.7.6/lib/rails/application.rb:533:in `block in run_tasks_blocks'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:281:in `block in execute'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:281:in `each'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:281:in `execute'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/airbrake-13.0.4/lib/airbrake/rake.rb:17:in `execute'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `synchronize'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `invoke_with_call_chain'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:188:in `invoke'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/sprockets-rails-3.4.2/lib/sprockets/rails/task.rb:61:in `block (2 levels) in define'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:281:in `block in execute'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:281:in `each'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:281:in `execute'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/airbrake-13.0.4/lib/airbrake/rake.rb:17:in `execute'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `synchronize'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `invoke_with_call_chain'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:243:in `block in invoke_prerequisites'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:241:in `each'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:241:in `invoke_prerequisites'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `synchronize'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `invoke_with_call_chain'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:188:in `invoke'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/application.rb:182:in `invoke_task'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/application.rb:138:in `block (2 levels) in top_level'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/application.rb:138:in `each'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/application.rb:138:in `block in top_level'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/application.rb:147:in `run_with_threads'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/application.rb:132:in `top_level'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/railties-6.1.7.6/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/application.rb:208:in `standard_exception_handling'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/railties-6.1.7.6/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/rake_module.rb:59:in `with_application'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/railties-6.1.7.6/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/railties-6.1.7.6/lib/rails/command.rb:50:in `invoke'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/railties-6.1.7.6/lib/rails/commands.rb:18:in `<main>'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/Users/donbulinux/Workspace/example/bin/rails:9:in `<top (required)>'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/spring-4.1.3/lib/spring/client/rails.rb:28:in `load'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/spring-4.1.3/lib/spring/client/rails.rb:28:in `call'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/spring-4.1.3/lib/spring/client/command.rb:7:in `call'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/spring-4.1.3/lib/spring/client.rb:30:in `run'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/spring-4.1.3/bin/spring:49:in `<top (required)>'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/spring-4.1.3/lib/spring/binstub.rb:11:in `load'
/Users/donbulinux/Workspace/example/vendor/bundle/ruby/3.1.0/gems/spring-4.1.3/lib/spring/binstub.rb:11:in `<top (required)>'
/Users/donbulinux/Workspace/example/bin/spring:15:in `require'
/Users/donbulinux/Workspace/example/bin/spring:15:in `<top (required)>'
Tasks: TOP => environment
(See full trace by running task with --trace)

えー?

NullDB not configured. Require a framework, ex 'nulldb/rails'

どうも NullDB が存在しないらしい。

Gemfile.lock にはちゃんと存在している。

    activerecord-nulldb-adapter (0.9.0)
      activerecord (>= 5.2.0, < 7.1)

雑に解決する

とりあえず require すれば解決するので application.rb に雑に書いてしまう。

# frozen_string_literal: true

require_relative 'boot'

require 'rails'
# Pick the frameworks you want:

... snip ...

require 'nulldb/rails' # このように雑に追加しておく

Bundler.require(*Rails.groups)

module App
  class Application < Rails::Application

... snip ...

再度 assets:precompile を流す

❯ RAILS_ENV=production DATABASE_ADAPTER=nulldb SECRET_KEY_BASE=dummy bundle exec rails assets:precompile

やったぜ。

原因?

どこかで暗黙的に require していた? とも考えたのだけど、該当の build がコケはじめた前後でプロジェクト全体を確認しても、 require を変更した部分が見つからなかったので、本当に謎。

このタイミングで バージョンが 0.9.0 -> 1.0.1 に上がっていたのでその関係かな、と思っていたが、 Changelog を見る限りなにか破壊的な変更が行われたわけではなさそう。

github.com

実際、前述の通り application.rb へ明示的に require 書いたら 0.9.0 でも 1.0.1 でも DATABASE_ADAPTER=nulldb 指定でちゃんと動いたので……。

いかがだったでしょうか

いかがもクソもないんじゃ、という感じですが。

実は対応したこのプロジェクト、コーディングではなくインフラの担当なので、結合で出た不具合への対応って感じで、うーん……という気持ちになっている。 雑に、と本文中に書いたのはそういうトコがあったのでした。

最近こういう責務を超えた対応、全部投げられてしまう傾向にあってかなりだいぶ辛い。 (担当のチームにリプライ送っても「そちらで対応してください (知らんわからん!)」と言われてしまうのだった。