From 73ff7f2829af6687dcce58d7ea62b25ec063d41e Mon Sep 17 00:00:00 2001 From: Matthias Marschall Date: Mon, 25 May 2009 09:41:01 +0200 Subject: [PATCH] added rake tasks to make structure.sql handling similar to schema.rb handling (db:test:load_structure and db:structure:load) --- railties/lib/tasks/databases.rake | 40 ++++++++++++++++++++++-------------- 1 files changed, 24 insertions(+), 16 deletions(-) diff --git a/railties/lib/tasks/databases.rake b/railties/lib/tasks/databases.rake index cdab5d8..7c034fb 100644 --- a/railties/lib/tasks/databases.rake +++ b/railties/lib/tasks/databases.rake @@ -303,21 +303,9 @@ namespace :db do File.open("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information } end end - end - - namespace :test do - desc "Recreate the test database from the current schema.rb" - task :load => 'db:test:purge' do - ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test']) - ActiveRecord::Schema.verbose = false - Rake::Task["db:schema:load"].invoke - end - - desc "Recreate the test database from the current environment's database schema" - task :clone => %w(db:schema:dump db:test:load) - - desc "Recreate the test databases from the development structure" - task :clone_structure => [ "db:structure:dump", "db:test:purge" ] do + + desc "Load the database structure from a SQL file into the test database" + task :load => :environment do abcs = ActiveRecord::Base.configurations case abcs["test"]["adapter"] when "mysql" @@ -349,6 +337,26 @@ namespace :db do raise "Task not supported by '#{abcs["test"]["adapter"]}'" end end + + end + + namespace :test do + desc "Recreate the test database from the current schema.rb" + task :load => 'db:test:purge' do + ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test']) + ActiveRecord::Schema.verbose = false + Rake::Task["db:schema:load"].invoke + end + + desc "Recreate the test database from the current development_structure.sql" + task :load_structure => %w(db:test:purge db:structure:load) + + desc "Recreate the test database from the current environment's database schema" + task :clone => %w(db:schema:dump db:test:load) + + desc "Recreate the test databases from the current environment's database structure" + task :clone_structure => %w(db:structure:dump db:test:purge db:structure:load) + desc "Empty the test database" task :purge => :environment do @@ -384,7 +392,7 @@ namespace :db do desc 'Check for pending migrations and load the test schema' task :prepare => 'db:abort_if_pending_migrations' do if defined?(ActiveRecord) && !ActiveRecord::Base.configurations.blank? - Rake::Task[{ :sql => "db:test:clone_structure", :ruby => "db:test:load" }[ActiveRecord::Base.schema_format]].invoke + Rake::Task[{ :sql => "db:test:load_structure", :ruby => "db:test:load" }[ActiveRecord::Base.schema_format]].invoke end end end -- 1.6.1