Skip to content

Commit

Permalink
Rename STRUCTURE to DB_STRUCTURE, update dump task description and ad…
Browse files Browse the repository at this point in the history
…d simple testcase.
  • Loading branch information
kommen committed Dec 18, 2011
1 parent aa92d37 commit a2249ee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions activerecord/lib/active_record/railties/databases.rake
Expand Up @@ -371,10 +371,10 @@ db_namespace = namespace :db do
end

namespace :structure do
desc 'Dump the database structure to an SQL file'
desc 'Dump the database structure to db/structure.sql. Specify an alternative file (eg. db/my_strcuture.sql) using DB_STRUCTURE=db/my_strcuture.sql'
task :dump => :environment do
abcs = ActiveRecord::Base.configurations
filename = ENV['STRUCTURE'] || File.join(Rails.root, "db", "structure.sql")
filename = ENV['DB_STRUCTURE'] || File.join(Rails.root, "db", "structure.sql")
case abcs[Rails.env]['adapter']
when /mysql/, 'oci', 'oracle'
ActiveRecord::Base.establish_connection(abcs[Rails.env])
Expand Down Expand Up @@ -410,7 +410,7 @@ db_namespace = namespace :db do
env = ENV['RAILS_ENV'] || 'test'

abcs = ActiveRecord::Base.configurations
filename = ENV['STRUCTURE'] || File.join(Rails.root, "db", "structure.sql")
filename = ENV['DB_STRUCTURE'] || File.join(Rails.root, "db", "structure.sql")
case abcs[env]['adapter']
when /mysql/
ActiveRecord::Base.establish_connection(abcs[env])
Expand Down
8 changes: 8 additions & 0 deletions railties/test/application/rake_test.rb
Expand Up @@ -133,5 +133,13 @@ def test_scaffold_tests_pass_by_default

assert_match(/7 tests, 10 assertions, 0 failures, 0 errors/, content)
end

def test_rake_dump_structure_should_respect_db_structure_env_variable
Dir.chdir(app_path) do
`bundle exec rake db:migrate` # ensure we have a schema_migrations table to dump
`bundle exec rake db:structure:dump DB_STRUCTURE=db/my_structure.sql`
end
assert File.exists?(File.join(app_path, 'db', 'my_structure.sql'))
end
end
end

0 comments on commit a2249ee

Please sign in to comment.