WIP for seeding accounts

This commit is contained in:
Jorge Manrubia
2025-11-02 00:05:38 +01:00
parent b07345724a
commit e726335833
5 changed files with 96 additions and 2 deletions
+1 -1
View File
@@ -296,7 +296,7 @@ GEM
logger (~> 1.6)
letter_opener (1.10.0)
launchy (>= 2.2, < 4)
lexxy (0.1.13.beta)
lexxy (0.1.14.beta)
rails (>= 8.0.2)
lint_roller (1.1.0)
logger (1.7.0)
+4
View File
@@ -31,6 +31,10 @@ class Account < ApplicationRecord
Collection.create!(name: "Cards", creator: user, all_access: true)
end
def setup_customer_template
Account::Seeder.new(self, User.first).seed
end
private
def create_join_code
Account::JoinCode.create!
+77
View File
@@ -0,0 +1,77 @@
class Account::Seeder
attr_reader :account, :creator
def initialize(account, creator)
@account = account
@creator = creator
puts creator.inspect
end
def seed
Current.set session: session do
populate
end
end
def seed!
raise "You can't run in production environments" unless Rails.env.local?
delete_everything
seed
end
private
def session
creator.identity.sessions.last
end
def populate
# ---------------
# Bugs Collection
# ---------------
bug_tracker = Collection.create!(name: "Bugs", creator: creator, all_access: true)
# Columns
triage_column = bug_tracker.columns.create!(name: "Triage", color: "#ef4444")
in_progress_column = bug_tracker.columns.create!(name: "In Progress", color: "#f97316")
resolved_column = bug_tracker.columns.create!(name: "Resolved", color: "#22c55e")
# Cards
bug_tracker.cards.create!(creator: creator, column: triage_column, title: "Login button not responding on mobile", status: "published")
bug_tracker.cards.create!(creator: creator, column: triage_column, title: "Search results showing duplicates", status: "published")
profile_crash_card = bug_tracker.cards.create!(creator: creator, column: in_progress_column, title: "Profile page crashes when uploading large images", status: "published")
bug_tracker.cards.create!(creator: creator, column: in_progress_column, title: "Email notifications not being sent", status: "published")
bug_tracker.cards.create!(creator: creator, column: resolved_column, title: "Fix broken links in footer", status: "published")
# Comments
profile_crash_card.comments.create!(creator: creator, body: "I can reproduce this with images over 5MB")
profile_crash_card.comments.create!(creator: creator, body: "Looking into adding client-side image compression before upload")
# ----------------------------
# Feature Requests Collection
# ----------------------------
feature_requests = Collection.create!(name: "Feature Requests", creator: creator, all_access: true)
# Columns
backlog_column = feature_requests.columns.create!(name: "Backlog", color: "#6366f1")
planning_column = feature_requests.columns.create!(name: "Planning", color: "#8b5cf6")
# Cards
feature_requests.cards.create!(creator: creator, column: backlog_column, title: "Add dark mode support", status: "published")
feature_requests.cards.create!(creator: creator, column: backlog_column, title: "Export data to CSV", status: "published")
feature_requests.cards.create!(creator: creator, column: backlog_column, title: "Add keyboard shortcuts for navigation", status: "published")
two_factor_card = feature_requests.cards.create!(creator: creator, column: planning_column, title: "Implement two-factor authentication", status: "published")
feature_requests.cards.create!(creator: creator, column: planning_column, title: "Add bulk actions for managing items", status: "published")
# Comments
two_factor_card.comments.create!(creator: creator, body: "Should we support SMS and authenticator apps?")
two_factor_card.comments.create!(creator: creator, body: "Let's start with authenticator apps only to keep it simple")
end
def delete_everything
Current.set session: session do
Collection.destroy_all
end
end
end
+1 -1
View File
@@ -116,7 +116,7 @@ class Signup
}
)
@user = User.find_by!(role: :admin)
@account.setup_basic_template
@account.setup_customer_template
end
end
+13
View File
@@ -0,0 +1,13 @@
namespace :seed do
desc "Seed customer data for a specific account (e.g., rails seed:customer 1234)"
task :customer, [:tenant_id] => :environment do |t, args|
raise "Please provide a tenant ID: rails seed:customer[1234]" unless args[:tenant_id]
tenant_id = args[:tenant_id].to_i
ApplicationRecord.current_tenant = tenant_id
account = Account.sole
Account::Seeder.new(account, User.first).seed!
puts "✓ Seeded account #{account.name} (tenant: #{tenant_id})"
end
end