diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-01-11 00:07:35 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-01-11 00:07:35 +0000 |
commit | dbb5341691bf1528a3079e20ea88a521787068ed (patch) | |
tree | 96b3ab78f855a40819e7a3b44d383556ca117f01 /railties/fresh_rakefile | |
parent | 2594f2abe9144d1a50c8c7404627817ebd0386f0 (diff) | |
download | rails-dbb5341691bf1528a3079e20ea88a521787068ed.tar.gz rails-dbb5341691bf1528a3079e20ea88a521787068ed.tar.bz2 rails-dbb5341691bf1528a3079e20ea88a521787068ed.zip |
Added that rake clone_structure_to_test, db_structure_dump, and purge_test_database tasks now pick up the source database to use from RAILS_ENV instead of just forcing development #424 [Tobias Luetke]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@379 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/fresh_rakefile')
-rwxr-xr-x | railties/fresh_rakefile | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/railties/fresh_rakefile b/railties/fresh_rakefile index d46c057194..2a4ca7098b 100755 --- a/railties/fresh_rakefile +++ b/railties/fresh_rakefile @@ -10,7 +10,7 @@ require 'code_statistics' require 'active_record/support/std_ext/test_unit_ext' # temporary fix until test/unit is cured for 1.8.2 desc "Run all the tests on a fresh test database" -task :default => [ :clone_development_structure_to_test, :test_units, :test_functional ] +task :default => [ :clone_structure_to_test, :test_units, :test_functional ] desc "Generate API documentatio, show coding stats" task :doc => [ :appdoc, :stats ] @@ -74,36 +74,36 @@ task :stats do end desc "Recreate the test databases from the development structure" -task :clone_development_structure_to_test => [ :db_structure_dump, :purge_test_database ] do +task :clone_structure_to_test => [ :db_structure_dump, :purge_test_database ] do if ActiveRecord::Base.configurations["test"]["adapter"] == "mysql" ActiveRecord::Base.establish_connection(:test) ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0') - IO.readlines("db/development_structure.sql").join.split("\n\n").each do |table| + IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |table| ActiveRecord::Base.connection.execute(table) end elsif ActiveRecord::Base.configurations["test"]["adapter"] == "postgresql" - `psql -U #{ActiveRecord::Base.configurations["test"]["username"]} -f db/development_structure.sql #{ActiveRecord::Base.configurations["test"]["database"]}` + `psql -U #{ActiveRecord::Base.configurations["test"]["username"]} -f db/#{RAILS_ENV}_structure.sql #{ActiveRecord::Base.configurations["test"]["database"]}` elsif ActiveRecord::Base.configurations["test"]["adapter"] == "sqlite" - `sqlite #{ActiveRecord::Base.configurations["test"]["dbfile"]} < db/development_structure.sql` + `sqlite #{ActiveRecord::Base.configurations["test"]["dbfile"]} < db/#{RAILS_ENV}_structure.sql` end end desc "Dump the database structure to a SQL file" task :db_structure_dump do - if ActiveRecord::Base.configurations["development"]["adapter"] == "mysql" - ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations["development"]) - File.open("db/development_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump } - elsif ActiveRecord::Base.configurations["development"]["adapter"] == "postgresql" - `pg_dump -U #{ActiveRecord::Base.configurations["development"]["username"]} -s -f db/development_structure.sql #{ActiveRecord::Base.configurations["development"]["database"]}` - elsif ActiveRecord::Base.configurations["development"]["adapter"] == "sqlite" - `sqlite #{ActiveRecord::Base.configurations["development"]["dbfile"]} .schema > db/development_structure.sql` + if ActiveRecord::Base.configurations[RAILS_ENV]["adapter"] == "mysql" + ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[RAILS_ENV]) + File.open("db/#{RAILS_ENV}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump } + elsif ActiveRecord::Base.configurations[RAILS_ENV]["adapter"] == "postgresql" + `pg_dump -U #{ActiveRecord::Base.configurations[RAILS_ENV]["username"]} -s -f db/#{RAILS_ENV}_structure.sql #{ActiveRecord::Base.configurations[RAILS_ENV]["database"]}` + elsif ActiveRecord::Base.configurations[RAILS_ENV]["adapter"] == "sqlite" + `sqlite #{ActiveRecord::Base.configurations[RAILS_ENV]["dbfile"]} .schema > db/#{RAILS_ENV}_structure.sql` end end desc "Drop the test database and bring it back again" task :purge_test_database do if ActiveRecord::Base.configurations["test"]["adapter"] == "mysql" - ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations["development"]) + ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[RAILS_ENV]) ActiveRecord::Base.connection.recreate_database(ActiveRecord::Base.configurations["test"]["database"]) elsif ActiveRecord::Base.configurations["test"]["adapter"] == "postgresql" `dropdb -U #{ActiveRecord::Base.configurations["test"]["username"]} #{ActiveRecord::Base.configurations["test"]["database"]}` |