Skip to content

Instantly share code, notes, and snippets.

@greendog
Forked from seyhunak/seeds.rb
Created June 11, 2014 09:56
Show Gist options
  • Save greendog/2f63a6d1d1ea6a2e3ebc to your computer and use it in GitHub Desktop.
Save greendog/2f63a6d1d1ea6a2e3ebc to your computer and use it in GitHub Desktop.

Revisions

  1. @seyhunak seyhunak created this gist Dec 7, 2013.
    16 changes: 16 additions & 0 deletions seeds.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    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