Skip to content

Instantly share code, notes, and snippets.

View albandum's full-sized avatar

Alban Dumouilla albandum

View GitHub Profile
@berpj
berpj / db_clean.rake
Last active February 20, 2019 16:16
# lib/tasks/db_clean.rake
# Homemade rake task to clean DB for Rails 5
namespace :db do
desc "Reset and seed DB"
task :clean => :environment do
# Empty tables and reset primary id autoincrement
ApplicationRecord.connection.tables.each do |table|
next if table.match(/\Aschema_migrations\Z/) || table.match(/\Aar_internal_metadata\Z/)
ApplicationRecord.connection.execute("TRUNCATE TABLE #{table} RESTART IDENTITY CASCADE")