This file contains 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
# 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") |