Skip to content

Instantly share code, notes, and snippets.

@isuke
Last active June 28, 2018 04:57
Show Gist options
  • Save isuke/6d7b9e096c2303c1708ecfe887147866 to your computer and use it in GitHub Desktop.
Save isuke/6d7b9e096c2303c1708ecfe887147866 to your computer and use it in GitHub Desktop.
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