diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-09-11 10:59:50 -0700 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-09-11 10:59:50 -0700 |
commit | f2a44ade14f995d0574bedf79c8d1bee520f0306 (patch) | |
tree | d662aaa76fe2e64fcb4f34b7496465df66d033c1 /activerecord/lib/active_record/tasks/mysql_database_tasks.rb | |
parent | 616ba15f2cb89588ae3b0a55452f4059f2c118b1 (diff) | |
parent | df9e135281463f11756ba7bf8f399523dfc1ee3c (diff) | |
download | rails-f2a44ade14f995d0574bedf79c8d1bee520f0306.tar.gz rails-f2a44ade14f995d0574bedf79c8d1bee520f0306.tar.bz2 rails-f2a44ade14f995d0574bedf79c8d1bee520f0306.zip |
Merge pull request #7564 from kennyj/using_mysqldump
Use mysqldump native commands when rake db:structure:dump. Closes #5547
Fixes database tasks config to use encoding instead of charset.
Diffstat (limited to 'activerecord/lib/active_record/tasks/mysql_database_tasks.rb')
-rw-r--r-- | activerecord/lib/active_record/tasks/mysql_database_tasks.rb | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/tasks/mysql_database_tasks.rb b/activerecord/lib/active_record/tasks/mysql_database_tasks.rb index 85d08402f9..2340f949b7 100644 --- a/activerecord/lib/active_record/tasks/mysql_database_tasks.rb +++ b/activerecord/lib/active_record/tasks/mysql_database_tasks.rb @@ -27,7 +27,7 @@ module ActiveRecord rescue error_class => error $stderr.puts error.error $stderr.puts "Couldn't create database for #{configuration.inspect}, #{creation_options.inspect}" - $stderr.puts "(If you set the charset manually, make sure you have a matching collation)" if configuration['charset'] + $stderr.puts "(If you set the charset manually, make sure you have a matching collation)" if configuration['encoding'] end def drop @@ -49,19 +49,17 @@ module ActiveRecord end def structure_dump(filename) - establish_connection configuration - File.open(filename, "w:utf-8") { |f| f << ActiveRecord::Base.connection.structure_dump } + args = prepare_command_options('mysqldump') + args.concat(["--result-file", "#{filename}"]) + args.concat(["--no-data"]) + args.concat(["#{configuration['database']}"]) + Kernel.system(*args) end def structure_load(filename) - args = ['mysql'] - args.concat(['--user', configuration['username']]) if configuration['username'] - args << "--password=#{configuration['password']}" if configuration['password'] - args.concat(['--default-character-set', configuration['charset']]) if configuration['charset'] - configuration.slice('host', 'port', 'socket', 'database').each do |k, v| - args.concat([ "--#{k}", v ]) if v - end + args = prepare_command_options('mysql') args.concat(['--execute', %{SET FOREIGN_KEY_CHECKS = 0; SOURCE #{filename}; SET FOREIGN_KEY_CHECKS = 1}]) + args.concat(["--database", "#{configuration['database']}"]) Kernel.system(*args) end @@ -77,7 +75,7 @@ module ActiveRecord def creation_options { - charset: (configuration['charset'] || DEFAULT_CHARSET), + charset: (configuration['encoding'] || DEFAULT_CHARSET), collation: (configuration['collation'] || DEFAULT_COLLATION) } end @@ -113,6 +111,18 @@ IDENTIFIED BY '#{configuration['password']}' WITH GRANT OPTION; $stdout.print "Please provide the root password for your mysql installation\n>" $stdin.gets.strip 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 ]) if v + end + args + end + end end end |