Rake database tasks

db:create creates the database for the current env according to config/database.yml
db:create:all creates the databases for all envs
db:schema:load creates tables and columns within the (existing) database following schema.rb
db:seed runs the db/seed.rb
db:setup does db:create, db:schema:load, db:seed
db:migrate:status shows current migration status
db:migrate runs migrations for the current env that have not run yet
db:migrate:up runs one specific migration
db:migrate:down rolls back one specific migration
db:migrate:redo runs (db:migrate:down db:migrate:up) or (db:rollback db:migrate) depending on the specified migration
db:migrate:reset runs db:drop db:create db:migrate
db:rollback rolls back the last migration
db:forward advances the current schema version to the next one
db:schema:dump dumps the current env's schema (does not create test db)
db:purge очистить ДБ текущего ENV
db:drop drops the database for the current env
db:drop:all drops the databases for all envs
db:reset does db:drop, db:setup
db:test:prepare Rebuild it from scratch according to the specs defined in the development database. Check for pending migrations and load the test schema. Does not copy the data.
db:environment:set RAILS_ENV=test ?

PR#35678 if the database exists, it runs any pending migrations. If a database does not exist, it runs the db:setup rake task. Idempotent — can run over and over again until it completes successfully.

db:prepare flow
db:test:clone (deprecated) — db:schema:dump, db:test:prepare — Recreate the test database from the current environment’s database schema. Does not copy the data.


  1. Runs truncate on all tables managed by ActiveRecord in the Rails environment the rake task is being run under. (Note that truncate deletes all of the data in the table, but does not reset the table's auto-increment (ID) counter)
  2. Runs the db:seed Rails rake task to populate seed data

Подготовить DB к тестам

RAILS_ENV=test rake db:create rake db:test:prepare