Created
September 14, 2018 07:18
-
-
Save penguinwokrs/b41cbd50f64eda6e18c4880fdf0ffb59 to your computer and use it in GitHub Desktop.
easy db truncate task
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
namespace :db do | |
namespace :reset do | |
desc 'db record reset' | |
task timeleap: :environment do | |
Rake::Task['db:reset:truncates'].invoke | |
Rake::Task['db:seed'].invoke | |
end | |
desc 'db record truncate' | |
task truncates: :environment do | |
tables = Settings.database.truncate.tables | |
tables.each do |table| | |
ApplicationRecord.connection.execute('SET FOREIGN_KEY_CHECKS=0;') | |
ApplicationRecord.connection.execute("TRUNCATE TABLE #{table};") | |
ApplicationRecord.connection.execute('SET FOREIGN_KEY_CHECKS=1;') | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment