Created
May 7, 2012 09:24
-
-
Save e1senh0rn/2626880 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake | |
| index f26e18b..d925d29 100644 | |
| --- a/activerecord/lib/active_record/railties/databases.rake | |
| +++ b/activerecord/lib/active_record/railties/databases.rake | |
| @@ -399,9 +399,11 @@ db_namespace = namespace :db do | |
| abcs = ActiveRecord::Base.configurations | |
| filename = ENV['DB_STRUCTURE'] || File.join(Rails.root, "db", "structure.sql") | |
| case abcs[Rails.env]['adapter'] | |
| - when /mysql/, 'oci', 'oracle' | |
| + when 'oci', 'oracle' | |
| ActiveRecord::Base.establish_connection(abcs[Rails.env]) | |
| File.open(filename, "w:utf-8") { |f| f << ActiveRecord::Base.connection.structure_dump } | |
| + when /mysql/ | |
| + `mysqldump --host=#{abcs[Rails.env]['host']} -u #{abcs[Rails.env]['username']} --password=#{abcs[Rails.env]['password']} --no-data #{abcs[Rails.env]['database']} > #{filename}` | |
| when /postgresql/ | |
| set_psql_env(abcs[Rails.env]) | |
| search_path = abcs[Rails.env]['schema_search_path'] | |
| @@ -437,11 +439,7 @@ db_namespace = namespace :db do | |
| filename = ENV['DB_STRUCTURE'] || File.join(Rails.root, "db", "structure.sql") | |
| case abcs[env]['adapter'] | |
| when /mysql/ | |
| - ActiveRecord::Base.establish_connection(abcs[env]) | |
| - ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0') | |
| - IO.read(filename).split("\n\n").each do |table| | |
| - ActiveRecord::Base.connection.execute(table) | |
| - end | |
| + `mysql --host=#{abcs[Rails.env]['host']} -u #{abcs[Rails.env]['username']} --password=#{abcs[Rails.env]['password']} #{abcs[Rails.env]['database']} < #{filename}` | |
| when /postgresql/ | |
| set_psql_env(abcs[env]) | |
| `psql -f "#{filename}" #{abcs[env]['database']}` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment