Skip to content

Instantly share code, notes, and snippets.

@HGebhardt
Created May 28, 2013 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HGebhardt/5662645 to your computer and use it in GitHub Desktop.
Save HGebhardt/5662645 to your computer and use it in GitHub Desktop.
rake db:truncate (PostgreSQL)
namespace :db do
desc 'Truncate all tables of the database'
task :truncate => :environment do
ActiveRecord::Base.establish_connection
tables = ActiveRecord::Base.connection.tables-["schema_migrations"]
ActiveRecord::Base.connection.execute("TRUNCATE #{tables.join(', ')} RESTART IDENTITY")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment