From d49c7f45ebd11d5d0b70dd7a0d3794269304602a Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 31 Oct 2025 21:19:31 +0100 Subject: [PATCH] Use a single populate script with faker data --- Gemfile | 1 + Gemfile.lock | 3 +++ script/populate.rb | 22 ++++++++++++++++++++++ script/populate/cards_for_pagination.rb | 13 ------------- script/populate/collections_and_cards.rb | 17 ----------------- 5 files changed, 26 insertions(+), 30 deletions(-) create mode 100644 script/populate.rb delete mode 100644 script/populate/cards_for_pagination.rb delete mode 100644 script/populate/collections_and_cards.rb diff --git a/Gemfile b/Gemfile index d2676e4ea..b2af37ec7 100644 --- a/Gemfile +++ b/Gemfile @@ -64,6 +64,7 @@ group :development, :test do gem "brakeman", require: false gem "rubocop-rails-omakase", require: false gem "letter_opener" + gem "faker" end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index c30020fcf..60c6d91f1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -240,6 +240,8 @@ GEM erubi (1.13.1) et-orbi (1.4.0) tzinfo + faker (3.5.2) + i18n (>= 1.8.11, < 2) ffi (1.17.2) ffi (1.17.2-arm64-darwin) ffi (1.17.2-x86_64-darwin) @@ -609,6 +611,7 @@ DEPENDENCIES bundler-audit capybara debug + faker fizzy-saas! geared_pagination (~> 1.2) image_processing (~> 1.14) diff --git a/script/populate.rb b/script/populate.rb new file mode 100644 index 000000000..680e34e34 --- /dev/null +++ b/script/populate.rb @@ -0,0 +1,22 @@ +require_relative "../../config/environment" +require "faker" + +CARDS_COUNT = ARGV.first&.to_i || 10_000 +COLLECTIONS_COUNT = ARGV.second&.to_i || 1 + +ApplicationRecord.current_tenant = ApplicationRecord.tenants.first +Current.session = Session.first + +puts "Creating #{CARDS_COUNT} cards across #{COLLECTIONS_COUNT} collection(s)" + +COLLECTIONS_COUNT.times do + Collection.create! name: Faker::Company.buzzword, all_access: true + print "." +end + +CARDS_COUNT.times do + card = Collection.take.cards.create! \ + title: Faker::Company.bs, description: Faker::Hacker.say_something_smart, status: :published + + print "." +end diff --git a/script/populate/cards_for_pagination.rb b/script/populate/cards_for_pagination.rb deleted file mode 100644 index 4ed436e8c..000000000 --- a/script/populate/cards_for_pagination.rb +++ /dev/null @@ -1,13 +0,0 @@ -require_relative "../../config/environment" - -CARDS_COUNT = 10_000 - -# 37signals seed -ApplicationRecord.current_tenant = "897362094" -Current.session = Session.first -collection = Collection.first - -CARDS_COUNT.times do |index| - card = collection.cards.create!(title: "Card #{index}", status: :published) - print "." -end diff --git a/script/populate/collections_and_cards.rb b/script/populate/collections_and_cards.rb deleted file mode 100644 index 7f355a1e7..000000000 --- a/script/populate/collections_and_cards.rb +++ /dev/null @@ -1,17 +0,0 @@ -require_relative "../../config/environment" - -COLLECTIONS_COUNT = 100 -CARDS_PER_COLLECTION = 50 - -ApplicationRecord.current_tenant = "development-tenant" -account = Account.sole -user = account.users.first -Current.session = user.sessions.last -workflow = account.workflows.first - -COLLECTIONS_COUNT.times do |collection_index| - collection = Collection.create!(name: "Collection #{collection_index}", creator: user, workflow: workflow) - CARDS_PER_COLLECTION.times do |card_index| - collection.cards.create!(title: "Card #{card_index}", creator: user, status: :published) - end -end