В rails 4 я пытаюсь написать свой собственный адаптер базы данных, однако, кажется, что database.yml
оценивается перед загрузкой моего адаптера, что приводит к ошибке:
Could not load 'active_record/connection_adapters/proxy_mysql2_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql', 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile.
Мой клиентский адаптер находится в lib/active_record/connection_handling/proxy_mysql2_adapter.rb
моя попытка загрузить его в config/application.rb
с использованием config.eager_load_paths
не работает, так как загружается не раньше config/database.yml
оценки.
Как бы я загрузил свой адаптер БД? так что он готов, когда database.yml
вычисляется?
Выше полная ошибка:
App 25085 output: Error: The application encountered the following error: Could not load 'active_record/connection_adapters/proxy_mysql2_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql', 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile. (LoadError)
App 25085 output: /var/www/backend/shared/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
App 25085 output: /var/www/backend/shared/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `block in require'
App 25085 output: /var/www/backend/shared/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'
App 25085 output: /var/www/backend/shared/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
App 25085 output: /var/www/backend/shared/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/connection_specification.rb:175:in `spec'
App 25085 output: /var/www/backend/shared/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_handling.rb:50:in `establish_connection'
App 25085 output: /var/www/backend/shared/bundle/ruby/2.3.0/gems/activerecord-import-0.13.0/lib/activerecord-import.rb:7:in `establish_connection_with_activerecord_import'
App 25085 output: /var/www/backend/shared/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/railtie.rb:120:in `block (2 levels) in <class:Railtie>'
App 25085 output: /var/www/backend/shared/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
App 25085 output: /var/www/backend/shared/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
App 25085 output: /var/www/backend/shared/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'
App 25085 output: /var/www/backend/shared/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:27:in `each'
App 25085 output: /var/www/backend/shared/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:27:in `on_load'
App 25085 output: /var/www/backend/shared/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/railtie.rb:116:in `block in <class:Railtie>'
App 25085 output: /var/www/backend/shared/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/initializable.rb:30:in `instance_exec'
App 25085 output: /var/www/backend/shared/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/initializable.rb:30:in `run'
App 25085 output: /var/www/backend/shared/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/initializable.rb:55:in `block in run_initializers'
App 25085 output: /home/deploy/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
App 25085 output: /home/deploy/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
App 25085 output: /home/deploy/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
App 25085 output: /home/deploy/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
App 25085 output: /home/deploy/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:347:in `each'
App 25085 output: /home/deploy/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:347:in `call'
App 25085 output: /home/deploy/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
App 25085 output: /home/deploy/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
App 25085 output: /home/deploy/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
App 25085 output: /var/www/backend/shared/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/initializable.rb:54:in `run_initializers'
App 25085 output: /var/www/backend/shared/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/application.rb:352:in `initialize!'
App 25085 output: /var/www/backend/releases/20200310141409/config/environment.rb:5:in `<top (required)>'
App 25085 output: config.ru:3:in `require'
App 25085 output: config.ru:3:in `block in <main>'
App 25085 output: /var/www/backend/shared/bundle/ruby/2.3.0/gems/rack-1.6.13/lib/rack/builder.rb:55:in `instance_eval'
App 25085 output: /var/www/backend/shared/bundle/ruby/2.3.0/gems/rack-1.6.13/lib/rack/builder.rb:55:in `initialize'
App 25085 output: config.ru:1:in `new'
App 25085 output: config.ru:1:in `<main>'
App 25085 output: /usr/share/passenger/helper-scripts/rack-preloader.rb:101:in `eval'
App 25085 output: /usr/share/passenger/helper-scripts/rack-preloader.rb:101:in `preload_app'
App 25085 output: /usr/share/passenger/helper-scripts/rack-preloader.rb:189:in `block in <module:App>'
App 25085 output: /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:380:in `run_block_and_record_step_progress'
App 25085 output: /usr/share/passenger/helper-scripts/rack-preloader.rb:188:in `<module:App>'
App 25085 output: /usr/share/passenger/helper-scripts/rack-preloader.rb:30:in `<module:PhusionPassenger>'
App 25085 output: /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<main>'
[ E 2020-03-10 15:22:10.0768 25063/Tf age/Cor/App/Implementation.cpp:221 ]: Could not spawn process for application /var/www/backend/current: The application encountered the following error: Could not load 'active_record/connection_adapters/proxy_mysql2_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql', 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile. (LoadError)
Error ID: 91fbd9ce
Error details saved to: /tmp/passenger-error-qdkLuQ.html
EDIT2
Я пытался поместить его в Папка инициализаторов, но я получил тот же результат, полный адаптер можно найти здесь: https://gist.github.com/arthurchui/f4d1d74d5e91f5307b5c6c78bdfde365