Created
May 26, 2011 17:22
-
-
Save apeiros/993547 to your computer and use it in GitHub Desktop.
A beefed up seeds file for rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pp' | |
puts "Seeding for env '#{Rails.env}'" | |
# disable AR logger | |
old_logger = ActiveRecord::Base.logger | |
ActiveRecord::Base.logger = nil unless $VERBOSE | |
env_seed_file = "#{Rails.root}/db/data/seed/#{Rails.env.downcase}/seeds.rb" | |
# first load yaml files that is "base" loading | |
seed_data_files = Dir.glob("#{Rails.root}/db/data/seed/all/**/*.yaml")+Dir.glob("#{Rails.root}/db/data/seed/#{Rails.env.downcase}/**/*.yaml") | |
seed_data_files.each { |seed_data_file| | |
puts "Seeding #{seed_data_file}" unless Rails.env == 'cucumber' | |
YamlDb.load seed_data_file | |
} | |
# then load rb files that depend on yamls and have some logic (sequence currently ignored) | |
seed_rb_files = Dir.glob("#{Rails.root}/db/data/seed/all/**/*.rb")+Dir.glob("#{Rails.root}/db/data/seed/#{Rails.env.downcase}/**/*.rb") | |
seed_rb_files.each { |seed_rb_file| | |
puts "Seeding #{seed_rb_file}" unless Rails.env == 'cucumber' | |
load(seed_rb_file) | |
} | |
load(env_seed_file) if File.exist?(env_seed_file) | |
# reenable logger | |
ActiveRecord::Base.logger = old_logger |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment