Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix db:bootstrap data loading

Sorted the table load order to allow the initial fixture data to be
cleanly loaded when using PostgreSQL 9.0
  • Loading branch information...
commit d511d10177508cdf4fe49a14022c02c36942b842 1 parent 4fa824c
@davec authored
Showing with 15 additions and 2 deletions.
  1. +15 −2 lib/tasks/db.rake
View
17 lib/tasks/db.rake
@@ -5,8 +5,21 @@ namespace :db do
raise "Bootstrapping a non-empty database is not allowed" if CompetitionData.count > 0
announce "Loading data"
time = Benchmark.measure do
- Dir.glob("#{RAILS_ROOT}/db/fixtures/*.yml").sort.each do |file|
- Fixtures.create_fixtures('db/fixtures', File.basename(file, '.*'))
+ fixture_dir = "#{RAILS_ROOT}/db/fixtures"
+ all_fixtures = Dir.glob("#{fixture_dir}/*.yml").map { |f| File.basename(f, ".yml") }
+ special_fixtures = %w(countries regions)
+ mass_load_fixtures = all_fixtures - special_fixtures
+
+ import = Import.new({})
+ import.instance_variable_set(:@tables, mass_load_fixtures)
+ import.instance_variable_set(:@files, mass_load_fixtures.map{|f| "${f}.yml"})
+ fixtures_in_order = import.send(:determine_load_order)
+
+ ActiveRecord::Base.connection.transaction do
+ special_fixtures.each do |fixture|
+ Fixtures.create_fixtures(fixture_dir, fixture)
+ end
+ Fixtures.create_fixtures(fixture_dir, fixtures_in_order)
end
end
announce "Data loaded (%.4fs)" % time.real
Please sign in to comment.
Something went wrong with that request. Please try again.