Method: Conjoin::Seeds.load_sql_dump_for

Defined in:
lib/conjoin/seeds.rb

.load_sql_dump_for(dump) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/conjoin/seeds.rb', line 12

def load_sql_dump_for dump
  connection = ActiveRecord::Base.connection

  connection.execute("TRUNCATE #{dump};")

  # - IMPORTANT: SEED DATA ONLY
  # - DO NOT EXPORT TABLE STRUCTURES
  # - DO NOT EXPORT DATA FROM `schema_migrations`
  sql = File.read("db/dumps/#{dump}.sql")
  statements = sql.split(/;$/)
  statements.pop  # the last empty statement

  ActiveRecord::Base.transaction do
    statements.each do |statement|
      connection.execute(statement)
    end
  end
end