Skip to content

Instantly share code, notes, and snippets.

@gregblake
gregblake / truncate_rails_tables.rb
Created December 10, 2019 13:28 — forked from romanlehnert/truncate_rails_tables.rb
Truncate all tables in rails
ActiveRecord::Base.establish_connection
ActiveRecord::Base.connection.execute("SET FOREIGN_KEY_CHECKS=0;")
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}")
when :sqlite