Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8389: rebuild_test_db_from_migrations.diff

File rebuild_test_db_from_migrations.diff, 1.9 kB (added by matthewrudy, 2 years ago)
  • activerecord/lib/active_record/base.rb

    old new  
    354354    # ActiveRecord::Schema file which can be loaded into any database that 
    355355    # supports migrations.  Use :ruby if you want to have different database 
    356356    # adapters for, e.g., your development and test environments. 
     357    # If :migrations, the schema is not dumped and the database is loaded 
     358    # directly from the migrations. 
    357359    cattr_accessor :schema_format , :instance_writer => false 
    358360    @@schema_format = :ruby 
    359361 
  • railties/lib/tasks/databases.rake

    old new  
    111111      end 
    112112    end 
    113113 
     114    desc 'Rebuild the test database from your migrations' 
     115    task :rebuild_from_migrations => ["db:test:purge"] do 
     116      ActiveRecord::Base.establish_connection(:test) 
     117      ActiveRecord::Schema.verbose = false 
     118      Rake::Task["db:migrate"].invoke 
     119    end 
     120 
    114121    desc "Empty the test database" 
    115122    task :purge => :environment do 
    116123      abcs = ActiveRecord::Base.configurations 
     
    150157    desc 'Prepare the test database and load the schema' 
    151158    task :prepare => :environment do 
    152159      if defined?(ActiveRecord::Base) && !ActiveRecord::Base.configurations.blank? 
    153         Rake::Task[{ :sql  => "db:test:clone_structure", :ruby => "db:test:clone" }[ActiveRecord::Base.schema_format]].invoke 
     160        task = case ActiveRecord::Base.schema_format 
     161          when :sql 
     162            "db:test:clone_structure" 
     163          when :ruby 
     164            "db:test:clone" 
     165          when :migrations 
     166            "db:test:rebuild_from_migrations" 
     167        end 
     168        Rake::Task[task].invoke 
    154169      end 
    155170    end 
    156171  end