Module: Conjoin::Seeds

Defined in:
lib/conjoin/seeds.rb

Class Method Summary collapse

Class Method Details

.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

.rootObject



4
5
6
# File 'lib/conjoin/seeds.rb', line 4

def root
  File.expand_path(File.dirname(__FILE__))
end

.runObject



8
9
10
# File 'lib/conjoin/seeds.rb', line 8

def run
  Dir["#{root}/seeds/**/*.rb"].each  { |rb| require rb  }
end