Purge or recreate a Ruby on Rails database

前端 未结 19 1259
清酒与你
清酒与你 2020-11-28 17:01

I have a dev Ruby on Rails database full of data. I want to delete everything and rebuild the database. I\'m thinking of using something like:

rake db:recrea         


        
19条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 17:45

    Update: In Rails 5, this command will be accessible through this command:

    rails db:purge db:create db:migrate RAILS_ENV=test


    As of the newest rails 4.2 release you can now run:

    rake db:purge 
    

    Source: commit

    # desc "Empty the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:drop:all to drop all databases in the config). Without RAILS_ENV it defaults to purging the development and test databases."
      task :purge => [:load_config] do
        ActiveRecord::Tasks::DatabaseTasks.purge_current
      end
    

    It can be used together like mentioned above:

    rake db:purge db:create db:migrate RAILS_ENV=test
    

提交回复
热议问题