-
-
Save nitinstp23/aabb5ad4fb541a9f01da604b3014b7cb to your computer and use it in GitHub Desktop.
Truncate all tables in rails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") | |
when :sqlite | |
ActiveRecord::Base.connection.execute("DELETE FROM #{table}") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment