Permalink
Browse files

Merge pull request #7525 from seamusabshere/use-mysql-binary-for-rake…

…-db-structure-load

Use the 'mysql' binary for 'rake db:structure:load'
  • Loading branch information...
2 parents 1c8539d + ece23b5 commit fdcbc560ab155f82898e8894db4e566b78abfa37 @rafaelfranca rafaelfranca committed Sep 5, 2012
@@ -54,11 +54,15 @@ def structure_dump(filename)
end
def structure_load(filename)
- establish_connection(configuration)
- connection.execute('SET foreign_key_checks = 0')
- IO.read(filename).split("\n\n").each do |table|
- connection.execute(table)
+ 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.concat(['--execute', %{SET FOREIGN_KEY_CHECKS = 0; SOURCE #{filename}; SET FOREIGN_KEY_CHECKS = 1}])
+ Kernel.system(*args)
end
private
@@ -251,17 +251,14 @@ def setup
ActiveRecord::Base.stubs(:connection).returns(@connection)
ActiveRecord::Base.stubs(:establish_connection).returns(true)
+ Kernel.stubs(:system)
end
def test_structure_load
filename = "awesome-file.sql"
- ActiveRecord::Base.expects(:establish_connection).with(@configuration)
- @connection.expects(:execute).twice
+ Kernel.expects(:system).with('mysql', '--database', 'test-db', '--execute', %{SET FOREIGN_KEY_CHECKS = 0; SOURCE #{filename}; SET FOREIGN_KEY_CHECKS = 1})
- open(filename, 'w') { |f| f.puts("SELECT CURDATE();") }
ActiveRecord::Tasks::DatabaseTasks.structure_load(@configuration, filename)
- ensure
- FileUtils.rm(filename)
end
end

0 comments on commit fdcbc56

Please sign in to comment.