aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/tasks/mysql_database_tasks.rb
diff options
context:
space:
mode:
authorSeamus Abshere <seamus@abshere.net>2012-09-04 18:46:05 -0500
committerSeamus Abshere <seamus@abshere.net>2012-09-05 11:10:15 -0500
commitece23b5fa01301ec006aa42f8b59ec938c35427b (patch)
treefa9a82de517e103481ab5133eaef1be5cb25298d /activerecord/lib/active_record/tasks/mysql_database_tasks.rb
parenta497bed1130427b3bcf717c29ca3b6edf07a5c04 (diff)
downloadrails-ece23b5fa01301ec006aa42f8b59ec938c35427b.tar.gz
rails-ece23b5fa01301ec006aa42f8b59ec938c35427b.tar.bz2
rails-ece23b5fa01301ec006aa42f8b59ec938c35427b.zip
Use the 'mysql' binary for 'rake db:structure:load'.
The previous implementation had the strange requirement that db/structure.sql contain only CREATE TABLE sql statements, one per table, separated by double newlines. SQLite3 and PostgreSQL database tasks, on the other hand, simply spawn 'sqlite3' and 'psql' binaries to load the file directly. The new implementation follows this and attempts to respect all current MySQL configuration settings.
Diffstat (limited to 'activerecord/lib/active_record/tasks/mysql_database_tasks.rb')
-rw-r--r--activerecord/lib/active_record/tasks/mysql_database_tasks.rb12
1 files changed, 8 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/tasks/mysql_database_tasks.rb b/activerecord/lib/active_record/tasks/mysql_database_tasks.rb
index bf62dfd5b5..85d08402f9 100644
--- a/activerecord/lib/active_record/tasks/mysql_database_tasks.rb
+++ b/activerecord/lib/active_record/tasks/mysql_database_tasks.rb
@@ -54,11 +54,15 @@ module ActiveRecord
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