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

Add full set of MySQL CLI options to support SSL authentication when using db:structure dump and load #20126

Merged
merged 1 commit into from
May 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
24 changes: 15 additions & 9 deletions activerecord/lib/active_record/tasks/mysql_database_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,21 @@ def root_password
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
Expand Down
11 changes: 10 additions & 1 deletion activerecord/test/cases/tasks/mysql_rake_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,21 @@ def test_warn_when_external_structure_dump_fails

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
Expand Down