Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create database via UI when ActiveRecord::NoDatabaseError #39723

Merged
merged 2 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Apply suggestions from code review
Co-authored-by: Zachary Scott <[email protected]>
  • Loading branch information
hahmed and zzak committed May 17, 2021
commit 1b8ceee4a2efeb7b9d02d0a971e0dce343bb090b
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Mysql2Adapter < AbstractMysqlAdapter
ER_BAD_DB_ERROR = 1049
ER_ACCESS_DENIED_ERROR = 1045
ER_CONN_HOST_ERROR = 2003
ER_UNKOWN_HOST_ERROR = 2005
ER_UNKNOWN_HOST_ERROR = 2005

ADAPTER_NAME = "Mysql2"

Expand All @@ -47,7 +47,7 @@ def new_client(config)
raise ActiveRecord::NoDatabaseError.db_error(config[:database])
elsif error.error_number == ConnectionAdapters::Mysql2Adapter::ER_ACCESS_DENIED_ERROR
raise ActiveRecord::DatabaseConnectionError.username_error(config[:username])
elsif [ConnectionAdapters::Mysql2Adapter::ER_CONN_HOST_ERROR, ConnectionAdapters::Mysql2Adapter::ER_UNKOWN_HOST_ERROR].include?(error.error_number)
elsif [ConnectionAdapters::Mysql2Adapter::ER_CONN_HOST_ERROR, ConnectionAdapters::Mysql2Adapter::ER_UNKNOWN_HOST_ERROR].include?(error.error_number)
raise ActiveRecord::DatabaseConnectionError.hostname_error(config[:host])
else
raise ActiveRecord::ConnectionNotEstablished, error.message
Expand Down
10 changes: 5 additions & 5 deletions activerecord/lib/active_record/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ def db_error(db_name)

To resolve this issue:

- Not created a database for this app, or deleted it? You may need to create your database.
- Database name changed? Check your database.yml config has the correct database name.
- Did you create the database for this app, or delete it? You may need to create your database.
- Has the database name changed? Check your database.yml config has the correct database name.

To create your database, run:\n\n bin/rails db:create
MSG
Expand All @@ -246,14 +246,14 @@ def initialize(message = nil)
class << self
def hostname_error(hostname)
DatabaseConnectionError.new(<<~MSG)
We are having an issue connecting with your hostname: #{hostname}.\n
Please check your database configuration or ensure there is a connection open to your hostname.
There is an issue connecting with your hostname: #{hostname}.\n
Please check your database configuration and ensure there is a valid connection to your database.
MSG
end

def username_error(username)
DatabaseConnectionError.new(<<~MSG)
We are having an issue connecting to your database with your username/password, username: #{username}.\n
There is an issue connecting to your database with your username/password, username: #{username}.\n
Please check your database configuration to ensure the username/password are valid.
MSG
end
Expand Down