aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2015-05-13 00:06:36 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2015-05-13 00:06:36 -0300
commitb0a19903ed236c695ceb1939d1d07af23f5060c8 (patch)
tree23df188bfe4978cd4877492b44d1efb9ac3e21b1 /activerecord
parentf91cbb068f7364eea9f902ff7851e498c5b66092 (diff)
parent01f7d14494f2a82d87386dd105075c2ae5bd6ef3 (diff)
downloadrails-b0a19903ed236c695ceb1939d1d07af23f5060c8.tar.gz
rails-b0a19903ed236c695ceb1939d1d07af23f5060c8.tar.bz2
rails-b0a19903ed236c695ceb1939d1d07af23f5060c8.zip
Merge pull request #20126 from drcapulet/master
Add full set of MySQL CLI options to support SSL authentication when using db:structure dump and load
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG.md6
-rw-r--r--activerecord/lib/active_record/tasks/mysql_database_tasks.rb24
-rw-r--r--activerecord/test/cases/tasks/mysql_rake_test.rb11
3 files changed, 31 insertions, 10 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index 09045087d9..4c67aac0d1 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,3 +1,9 @@
+* Correctly pass MySQL options when using structure_dump or structure_load
+
+ Specifically, it fixes an issue when using SSL authentication.
+
+ *Alex Coomans*
+
* Dump indexes in `create_table` instead of `add_index`.
If the adapter supports indexes in create table, generated SQL is
diff --git a/activerecord/lib/active_record/tasks/mysql_database_tasks.rb b/activerecord/lib/active_record/tasks/mysql_database_tasks.rb
index eafbb2c249..bc80275a88 100644
--- a/activerecord/lib/active_record/tasks/mysql_database_tasks.rb
+++ b/activerecord/lib/active_record/tasks/mysql_database_tasks.rb
@@ -130,15 +130,21 @@ IDENTIFIED BY '#{configuration['password']}' WITH GRANT OPTION;
end
def prepare_command_options(command)
- args = [command]
- args.concat(['--user', configuration['username']]) if configuration['username']
- args << "--password=#{configuration['password']}" if configuration['password']
- args.concat(['--default-character-set', configuration['encoding']]) if configuration['encoding']
- configuration.slice('host', 'port', 'socket').each do |k, v|
- args.concat([ "--#{k}", v.to_s ]) if v
- end
-
- args
+ args = {
+ 'host' => '--host',
+ 'port' => '--port',
+ 'socket' => '--socket',
+ 'username' => '--user',
+ 'password' => '--password',
+ 'encoding' => '--default-character-set',
+ 'sslca' => '--ssl-ca',
+ 'sslcert' => '--ssl-cert',
+ 'sslcapath' => '--ssl-capath',
+ 'sslcipher' => '--ssh-cipher',
+ 'sslkey' => '--ssl-key'
+ }.map { |opt, arg| "#{arg}=#{configuration[opt]}" if configuration[opt] }.compact
+
+ [command, *args]
end
end
end
diff --git a/activerecord/test/cases/tasks/mysql_rake_test.rb b/activerecord/test/cases/tasks/mysql_rake_test.rb
index f58535f044..8d69741a4a 100644
--- a/activerecord/test/cases/tasks/mysql_rake_test.rb
+++ b/activerecord/test/cases/tasks/mysql_rake_test.rb
@@ -283,12 +283,21 @@ module ActiveRecord
def test_structure_dump_with_port_number
filename = "awesome-file.sql"
- Kernel.expects(:system).with("mysqldump", "--port", "10000", "--result-file", filename, "--no-data", "test-db").returns(true)
+ Kernel.expects(:system).with("mysqldump", "--port=10000", "--result-file", filename, "--no-data", "test-db").returns(true)
ActiveRecord::Tasks::DatabaseTasks.structure_dump(
@configuration.merge('port' => 10000),
filename)
end
+
+ def test_structure_dump_with_ssl
+ filename = "awesome-file.sql"
+ Kernel.expects(:system).with("mysqldump", "--ssl-ca=ca.crt", "--result-file", filename, "--no-data", "test-db").returns(true)
+
+ ActiveRecord::Tasks::DatabaseTasks.structure_dump(
+ @configuration.merge("sslca" => "ca.crt"),
+ filename)
+ end
end
class MySQLStructureLoadTest < ActiveRecord::TestCase