A photo of Kim Burgestrand

Kim Burgestrand

Heartfelt software development. Sometimes other things.

Clearing your Rails database in development

~ 1 min

You ever been hit with this?

$ rake db:reset
PG::ObjectInUse: ERROR:  database "yolo_development" is being accessed by other users
DETAIL:  There is 1 other session using the database.
: DROP DATABASE IF EXISTS "yolo_development"
$ rake db:drop db:create db:migrate db:seed
PG::ObjectInUse: ERROR:  database "yolo_development" is being accessed by other users
DETAIL:  There is 1 other session using the database.

During development in Ruby on Rails it’s often necessary to wipe the database, seed, and start over.

In my case, I often also do not want to re-migrate the entire thing just because I want a new set of data. Until recently I used to terminate my Rails server, run rake db:reset, and I’d be happy and annoyed at the same time.

Today I just run rake db:prune db:seed and I will have a fresh database, and now you can too! Meet rails_prune, the first gem that I’ve created where the implementation is shorter than its announcement!

PS: It works fine with foreign key constraints.

rss facebook twitter github youtube mail spotify instagram linkedin google pinterest medium rubygems