I know this is an old question, but I thought it might help someone. This is a very quick way to clear all data from a database.
tables = [] ActiveRecord::Base.connection.execute("show tables").each { |r| tables << r[0] } tables = tables - ["schema_migrations"] tables.each do |table| ActiveRecord::Base.connection.execute("DELETE FROM #{table} WHERE 1 = 1") end
I use this technique in certain specifications in the after(:all) block. This is much faster and more effective than any of the Rake Rake tasks for cleaning, migrating, reselling the database.
BTW: I am sure this will most likely fail if you apply foreign key constraints on the database side.
Sean McCleary Jun 10 2018-10-10T00: 10Z
source share