Actions
Refactor #18551
closedtable_exists? in initializer should ignore missing database
Description
Under Rails 5, initializing the Foreman app with a missing MySQL or PostgreSQL database fails in the config/initializers/foreman.rb file which calls table_exists?
:
Mysql2::Error: Unknown database 'test_develop_pr_core-0-dev' gems/mysql2-0.4.4/lib/mysql2/client.rb:87:in `connect' gems/mysql2-0.4.4/lib/mysql2/client.rb:87:in `initialize' gems/activerecord-5.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:25:in `new' gems/activerecord-5.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:25:in `mysql2_connection' gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:721:in `new_connection' gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:765:in `checkout_new_connection' gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:744:in `try_to_checkout_new_connection' gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:705:in `acquire_connection' gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:501:in `checkout' gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:364:in `connection' gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:875:in `retrieve_connection' gems/activerecord-5.0.0/lib/active_record/connection_handling.rb:128:in `retrieve_connection' gems/activerecord-5.0.0/lib/active_record/connection_handling.rb:91:in `connection' gems/activerecord-5.0.0/lib/active_record/model_schema.rb:248:in `table_exists?' config/initializers/foreman.rb:36:in `<top (required)>'
The initializer should ignore any connection failures here, as with nearby table_exists? calls as the database may not exist (initialising the app is a pre-requisite to DB setup tasks).
Rails 5 differs from 4.2 as it no longer uses a schema cache to answer the table_exists? method call.
Actions