Useful Rails CLI database commands

Sep 01, 2020

Here are some useful database-related CLI commands in Rails. Here for my own reference since I seem to forget all the time!

The source code for the different commands can be found here.

db:migrate VERSION=0

Revert all migrations.

db:migrate:reset

Drops the database, recreates it and runs all migrations.

db:truncate_all

Truncate (empties) all tables in database.

db:seed:replant

Truncates database and loads seeds.

db:rollback

Rollback last migration.

db:migrate:redo

Rollback last migration and then run it again.