Skip to content

Instantly share code, notes, and snippets.

@kplandes
kplandes / seed.rb
Created October 16, 2014 20:41 — forked from changemewtf/seed.rb
# db/seed.rb
# This block will automatically empty the database every time db:seed is run.
ActiveRecord::Base.connection.tables.each do |table|
# Don't clear our migration history! Clear everything else.
if table != 'schema_migrations'
# http://stackoverflow.com/a/7758797
ActiveRecord::Base.connection.execute("TRUNCATE TABLE #{table};")
# http://stackoverflow.com/questions/2097052/rails-way-to-reset-seed-on-id-field
ActiveRecord::Base.connection.reset_pk_sequence! table