Last active
February 20, 2019 16:16
-
-
Save berpj/12249ddca673d3e110f4ec1a6f063e7e to your computer and use it in GitHub Desktop.
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") | |
end | |
# Seed | |
sh "rails db:seed" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can just do
rails db:clean
to run it.