Last active
June 28, 2018 04:57
-
-
Save isuke/6d7b9e096c2303c1708ecfe887147866 to your computer and use it in GitHub Desktop.
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
Bundler.require(:development, :test, :qa) | |
namespace :db do | |
namespace :sample do | |
desc "Fill database with sample data" | |
task populate: :environment do | |
ActiveRecord::Base.transaction do | |
%w(projects attrs tasks).each { |table| populate(table) } | |
end | |
end | |
private | |
def populate(table) | |
return unless ENV['all'].present? || ENV[table].present? | |
if ENV[table].present? | |
num = ENV[table]&.to_i | |
if num.zero? | |
puts "skip #{table}" | |
else | |
puts "populate #{num} #{table}" | |
send("populate_#{table}", num) | |
end | |
elsif ENV['all'].present? | |
puts "populate #{table}" | |
send("populate_#{table}") | |
end | |
end | |
def populate_projects(num = 2) | |
Project.destroy_all | |
FactoryGirl.create_list(:project, num) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment