Created
October 16, 2014 20:40
-
-
Save changemewtf/ec3d7aaf0378938e27db to your computer and use it in GitHub Desktop.
Auto-clear database on rake db:seed
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
# 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 | |
end | |
end | |
# Actual seed data creation goes here... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment