diff options
author | John Hawthorn <john@hawthorn.email> | 2019-07-25 13:59:15 -0700 |
---|---|---|
committer | John Hawthorn <john@hawthorn.email> | 2019-07-25 14:15:39 -0700 |
commit | 15c81c8ed4930574d9900a6f947d4e0ebaa82a2f (patch) | |
tree | 5181c4435fef10ca4367b786e3a9c6dcc76242b1 /activerecord/lib/active_record/tasks | |
parent | bd5edc29709116104345cf09c17f1db89428753e (diff) | |
download | rails-15c81c8ed4930574d9900a6f947d4e0ebaa82a2f.tar.gz rails-15c81c8ed4930574d9900a6f947d4e0ebaa82a2f.tar.bz2 rails-15c81c8ed4930574d9900a6f947d4e0ebaa82a2f.zip |
Use connection.error_number in MySQLDatabaseTasks
MySQLDatabaseTasks, like AbstractMysqlAdapter, should be able to operate
on any mysql adapter, not just mysql2. Errors having a .error_number
attribute is a mysql2 specific API, which we (Rails) don't control, so
we should instead use connection.error_number(err), which we do.
This also updates tests to better test how this really works, previously
it stubbed create_database to raise Tasks::DatabaseAlreadyExists, which
can never happen.
Diffstat (limited to 'activerecord/lib/active_record/tasks')
-rw-r--r-- | activerecord/lib/active_record/tasks/mysql_database_tasks.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/tasks/mysql_database_tasks.rb b/activerecord/lib/active_record/tasks/mysql_database_tasks.rb index a7e04007a9..e3efeb75b5 100644 --- a/activerecord/lib/active_record/tasks/mysql_database_tasks.rb +++ b/activerecord/lib/active_record/tasks/mysql_database_tasks.rb @@ -16,7 +16,7 @@ module ActiveRecord connection.create_database configuration["database"], creation_options establish_connection configuration rescue ActiveRecord::StatementInvalid => error - if error.cause.error_number == ER_DB_CREATE_EXISTS + if connection.error_number(error.cause) == ER_DB_CREATE_EXISTS raise DatabaseAlreadyExists else raise |