aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRune Schjellerup Philosof <rp@centic.dk>2017-04-06 14:05:49 +0200
committerRune Schjellerup Philosof <rp@centic.dk>2017-04-20 10:14:07 +0200
commit2d699e24ff10158c0831cf6b7f5e5b12ac41903a (patch)
treeb45ebf13161a312298b019da50ff467e3909abab /activerecord
parentfd097cff79c62fedabffae4e9f0fb53c2ec8bcbe (diff)
downloadrails-2d699e24ff10158c0831cf6b7f5e5b12ac41903a.tar.gz
rails-2d699e24ff10158c0831cf6b7f5e5b12ac41903a.tar.bz2
rails-2d699e24ff10158c0831cf6b7f5e5b12ac41903a.zip
Fix quoting in db:create grant all statement.
The database name used in the test would have actually shown this if it had tried to execute on a real Mysql instead of being stubbed out (dashes in database names needs quotes).
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG.md4
-rw-r--r--activerecord/lib/active_record/tasks/mysql_database_tasks.rb2
-rw-r--r--activerecord/test/cases/tasks/mysql_rake_test.rb2
3 files changed, 6 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index 30d580b9e3..d4a68a39f9 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1 +1,5 @@
+* Quote database name in db:create grant statement (when database_user does not have access to create the database).
+
+ *Rune Philosof*
+
Please check [5-1-stable](https://github.com/rails/rails/blob/5-1-stable/activerecord/CHANGELOG.md) for previous changes.
diff --git a/activerecord/lib/active_record/tasks/mysql_database_tasks.rb b/activerecord/lib/active_record/tasks/mysql_database_tasks.rb
index 920830b9cf..c05f0a8fbb 100644
--- a/activerecord/lib/active_record/tasks/mysql_database_tasks.rb
+++ b/activerecord/lib/active_record/tasks/mysql_database_tasks.rb
@@ -104,7 +104,7 @@ module ActiveRecord
def grant_statement
<<-SQL
-GRANT ALL PRIVILEGES ON #{configuration['database']}.*
+GRANT ALL PRIVILEGES ON `#{configuration['database']}`.*
TO '#{configuration['username']}'@'localhost'
IDENTIFIED BY '#{configuration['password']}' WITH GRANT OPTION;
SQL
diff --git a/activerecord/test/cases/tasks/mysql_rake_test.rb b/activerecord/test/cases/tasks/mysql_rake_test.rb
index f30e0958c3..b85d303a91 100644
--- a/activerecord/test/cases/tasks/mysql_rake_test.rb
+++ b/activerecord/test/cases/tasks/mysql_rake_test.rb
@@ -167,7 +167,7 @@ if current_adapter?(:Mysql2Adapter)
def assert_permissions_granted_for(db_user)
db_name = @configuration["database"]
db_password = @configuration["password"]
- @connection.expects(:execute).with("GRANT ALL PRIVILEGES ON #{db_name}.* TO '#{db_user}'@'localhost' IDENTIFIED BY '#{db_password}' WITH GRANT OPTION;")
+ @connection.expects(:execute).with("GRANT ALL PRIVILEGES ON `#{db_name}`.* TO '#{db_user}'@'localhost' IDENTIFIED BY '#{db_password}' WITH GRANT OPTION;")
end
end