Skip to content

Instantly share code, notes, and snippets.

@cisolarix
Forked from seyhunak/seeds.rb
Last active August 29, 2015 14:17
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 cisolarix/8315822bc6da42164026 to your computer and use it in GitHub Desktop.
Save cisolarix/8315822bc6da42164026 to your computer and use it in GitHub Desktop.
unless Rails.env.production?
connection = ActiveRecord::Base.connection
connection.tables.each do |table|
connection.execute("TRUNCATE #{table}") unless table == "schema_migrations"
end
sql = File.read('db/import.sql')
statements = sql.split(/;$/)
statements.pop
ActiveRecord::Base.transaction do
statements.each do |statement|
connection.execute(statement)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment