I have this testingdatabase which, by now, is stuffed with junk. Now I\'ve done a few Table.destroy_all commands in the rails console which deletes all records and dependencies
I used below code to truncate all tables
ActiveRecord::Base.establish_connection
ActiveRecord::Base.connection.tables.each do |table|
next if table == 'schema_migrations'
case ActiveRecord::Base.connection.adapter_name.downcase.to_sym
when :mysql2 , :postgresql
ActiveRecord::Base.connection.execute("TRUNCATE #{table}")
ActiveRecord::Base.connection.execute("TRUNCATE #{table} RESTART IDENTITY")
when :sqlite
ActiveRecord::Base.connection.execute("DELETE FROM #{table}")
end
end