Project

General

Profile

Refactor #18551

table_exists? in initializer should ignore missing database

Added by Dominic Cleal over 5 years ago. Updated almost 4 years ago.

Status:
Closed
Priority:
Low
Assignee:
Category:
Rails
Target version:
Difficulty:
Triaged:
Bugzilla link:
Fixed in Releases:
Found in Releases:

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.

Associated revisions

Revision acf54d7e (diff)
Added by Dominic Cleal over 5 years ago

fixes #18551 - skip table_exists? error when the DB doesn't exist

MySQL and PostgreSQL DB adapters now throw a connection error under
Rails 5 if the the DB doesn't already exist, as the schema cache is no
longer used to answer the method call.

History

#1 Updated by The Foreman Bot over 5 years ago

  • Status changed from Assigned to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/4298 added

#2 Updated by Dominic Cleal over 5 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

#3 Updated by Dominic Cleal over 5 years ago

  • Legacy Backlogs Release (now unused) set to 209

Also available in: Atom PDF