Last active
December 14, 2015 09:39
-
-
Save samuelpismel/5066468 to your computer and use it in GitHub Desktop.
Truncates all tables in your rails database except the schema_migrations table. how to use:
rake db:truncate
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
# how to use: | |
# rake db:truncate | |
# | |
# Truncates all tables in your rails database except the schema_migrations table. | |
# This is a destructive rake task, it will delete all records in your database, | |
# so don't use it if you don't know what you are doing and be careful when using it. | |
# I recommend use it just when you have a really good seed.rb in your project | |
# as a easy way to clean the database and then seed the database with rake db:seed command. | |
# Como usar: | |
# rake db:truncate | |
# | |
# Trunca todas as tabelas do banco de dados de sua aplicação rails exceto a tabela schema_migrations | |
# Essa é uma tarefa destrutiva, ela vai apagar todos os registros do seu banco de dados, | |
# então não use se você não souber o que está fazendo e seja cuidadoso quando usá-la. | |
# Eu recomendo usá-la apenas quando você tiver um arquivo seed.rb realmente bom em seu projeto | |
# como uma maneira fácil de limpar o banco e semear o banco usando o comando rake db:seed | |
namespace :db do | |
desc "Truncates all tables in database except the 'schema_migrations'" | |
task :truncate => :environment do | |
ActiveRecord::Base.connection.tables.select{|table| table != 'schema_migrations'}.each do |table| | |
ActiveRecord::Base.connection.execute("TRUNCATE TABLE #{table}") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment