Skip to content

Improve the Seeding of sofia accounts#1201

Merged
lodewiges merged 5 commits intostagingfrom
feature/improve-seeding
Jan 14, 2026
Merged

Improve the Seeding of sofia accounts#1201
lodewiges merged 5 commits intostagingfrom
feature/improve-seeding

Conversation

@lodewiges
Copy link
Copy Markdown
Contributor

@lodewiges lodewiges commented Jan 13, 2026

Improve the Seeding of sofia accounts and some other small parts
Fixes #1170

Summary by CodeRabbit

  • Chores
    • Added color attributes to products across beverage, food, tobacco, and merchandise categories.
    • Expanded database seeding with diverse user profiles (including named accounts and birthdays), realistic credit mutation records, recent and historical activities with calculated timestamps, and orders linked to activities/users.
    • Added dedicated account seeding for specific regional accounts with associated roles and credentials.

✏️ Tip: You can customize this high-level summary in your review settings.

Copilot AI review requested due to automatic review settings January 13, 2026 00:17
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 13, 2026

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

Seed data updated: users replaced with explicit Dutch names (one with birthday); recent and historical activities added (with computed timestamps); credit mutations diversified and linked; Sofia accounts and roles created; orders seeded after activities; product seeds now include category-based color attributes.

Changes

Cohort / File(s) Summary
User, Activity & Order Seeding
db/seeds.rb
Replaced generic user/activity generation with explicit dutch_names and activity_names; added one user with a birthday. Added recent activities and historical (locked) activities computed from days_ago. Adjusted seeding order to seed historical activities prior to orders and to include activities in the main collection used by later seeds.
Credit Mutation Seeding
db/seeds.rb
Introduced realistic mutation descriptions and ranges; now generates three mutations per user with user, description, amount, and optional activity linkage (possibly nil).
Sofia Accounts & Roles
db/seeds.rb
Added creation of three Sofia users and corresponding SofiaAccount records with fixed credentials and role entries; assigns roles to users.
Product Color Seeding
db/seeds/products.rb
Added category_colors mapping and passed color: category_colors[category] to Product creation across all product categories (beer, low_alcohol_beer, craft_beer, non_alcoholic, distilled, whiskey, wine, food, tobacco, donation).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through seeds at dawn's first light,

gave Dutch names names and colors bright,
stitched old days into activities' thread,
minted Sofia accounts with passwords fed,
tiny mutations danced — now the DB's fed.

🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is minimal and incomplete, missing required template sections like the checklist and detailed summary of changes made. Add the required checklist items, provide a detailed summary of all changes (including product color seeding), and confirm testing procedures were completed.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Improve the Seeding of sofia accounts' is partially related to the changeset, referring to Sofia accounts seeding but not covering the additional product color seeding changes.
Linked Issues check ✅ Passed The PR successfully implements both requirements from issue #1170: product color seeding and Sofia user seeding are present in the changeset.
Out of Scope Changes check ✅ Passed The seeding changes in db/seeds.rb beyond Sofia accounts appear reasonable and related to overall seeding improvements, though the scope extends slightly beyond the explicit issue requirements.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

🧹 Recent nitpick comments
db/seeds.rb (1)

94-118: Duplicate role creation - consider reusing existing roles.

Lines 98-100 create roles without group_uid, then lines 107, 112, 117 create additional roles of the same types. This results in duplicate roles (e.g., 3 treasurer roles total). Consider reusing the roles from lines 98-100 instead of creating new ones.

♻️ Proposed refactor: Reuse existing roles
 p 'Seeding roles...'
 Role.create(role_type: :treasurer, group_uid: 4)
 Role.create(role_type: :renting_manager, group_uid: 5)
 Role.create(role_type: :main_bartender, group_uid: 6)
-Role.create(role_type: :treasurer)
-Role.create(role_type: :renting_manager)
-Role.create(role_type: :main_bartender)
+treasurer_role = Role.create(role_type: :treasurer)
+renting_manager_role = Role.create(role_type: :renting_manager)
+main_bartender_role = Role.create(role_type: :main_bartender)
 
 p 'Seeding Sofia accounts...'
 # Use environment variable for password or fallback to default for development
+seed_password = ENV.fetch('SEED_PASSWORD', 'password1234')
 
 treasurer_user = FactoryBot.create(:user, :sofia_account, name: 'Penningmeester Test')
-SofiaAccount.create!(username: 'penningmeester', password: 'password1234', user: treasurer_user)
-treasurer_role = Role.create(role_type: :treasurer)
+SofiaAccount.create!(username: 'penningmeester', password: seed_password, user: treasurer_user)
 treasurer_user.roles << treasurer_role
 
 main_bartender_user = FactoryBot.create(:user, :sofia_account, name: 'Hoofdtapper Test')
-SofiaAccount.create!(username: 'hoofdtapper', password: 'password1234', user: main_bartender_user)
-main_bartender_role = Role.create(role_type: :main_bartender)
+SofiaAccount.create!(username: 'hoofdtapper', password: seed_password, user: main_bartender_user)
 main_bartender_user.roles << main_bartender_role
 
 renting_manager_user = FactoryBot.create(:user, :sofia_account, name: 'Verhuur Test')
-SofiaAccount.create!(username: 'verhuur', password: 'password1234', user: renting_manager_user)
-renting_manager_role = Role.create(role_type: :renting_manager)
+SofiaAccount.create!(username: 'verhuur', password: seed_password, user: renting_manager_user)
 renting_manager_user.roles << renting_manager_role
📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ed3ec8c and 4e6c1cf.

📒 Files selected for processing (2)
  • db/seeds.rb
  • db/seeds/products.rb
🧰 Additional context used
🧬 Code graph analysis (1)
db/seeds.rb (1)
app/models/role.rb (1)
  • name (8-16)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build
🔇 Additional comments (5)
db/seeds/products.rb (2)

28-66: LGTM!

Color attributes are consistently applied across all product categories using the category_colors lookup. The implementation is correct.


2-14: Well-structured category color mapping.

The local category_colors hash with .freeze is a clean approach that avoids polluting the global namespace. Dutch comments now use correct compound nouns. The Product model properly supports the color attribute with database migration, validation for valid hexcode format, and presence checks. All colors in the mapping are valid hex codes and all product categories are correctly defined in the model.

db/seeds.rb (3)

14-29: LGTM!

Clean implementation with realistic Dutch test names and a minor user for age-related testing scenarios.


68-89: LGTM!

Good variety of realistic credit mutation types with varied amount ranges. The (activities + [nil]).sample pattern is a clean way to optionally associate mutations with activities.


38-57: The comment is accurate — activities are locked automatically via time-locking.

The Activity model has an automatic time-locking mechanism. The locked? method checks both explicit locked_by assignment and automatic time_locked? status. Historical activities with end_time older than approximately 2 months are automatically considered locked. The comment "(locked)" correctly reflects this behavior, even though no explicit locking code appears in the seed file. No action needed.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request improves the seeding of Sofia accounts and other database seed data to provide more realistic test/development data. The changes add color coding to product categories, replace generic test data with Dutch names and activities, add historical activities, improve credit mutation variety, and introduce seeding for Sofia account users with specific roles.

Changes:

  • Added color codes for product categories to visually distinguish different product types
  • Replaced generic test data with realistic Dutch names, activity titles, and credit mutation descriptions
  • Added seeding for Sofia accounts with specific roles (treasurer, main bartender, renting manager)

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 9 comments.

File Description
db/seeds/products.rb Added CATEGORY_COLORS constant and updated Product.create calls to include color assignments for better visual categorization
db/seeds.rb Enhanced seed data with Dutch names, realistic activities (including historical ones), varied credit mutations, and Sofia account seeding for role-specific test users

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread db/seeds.rb Outdated
Comment thread db/seeds.rb
activities << FactoryBot.create(:activity, title:, price_list: price_lists.sample, created_by: users.sample)
end

# Historische activiteiten (locked)
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says 'Historische activiteiten (locked)' but the code doesn't actually lock the activities. If locking is intended, you should add code to lock these activities after creation.

Copilot uses AI. Check for mistakes.
Comment thread db/seeds.rb
Comment thread db/seeds/products.rb Outdated
Comment thread db/seeds/products.rb Outdated
Comment thread db/seeds.rb
Comment thread db/seeds.rb
Comment thread db/seeds/products.rb Outdated
Comment thread db/seeds/products.rb Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.68%. Comparing base (4a331ed) to head (4e6c1cf).
⚠️ Report is 1 commits behind head on staging.

Additional details and impacted files
@@           Coverage Diff            @@
##           staging    #1201   +/-   ##
========================================
  Coverage    77.68%   77.68%           
========================================
  Files           54       54           
  Lines         1340     1340           
========================================
  Hits          1041     1041           
  Misses         299      299           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @db/seeds.rb:
- Around line 104-121: The seeded password variable seed_password is fetched but
not used; replace the hardcoded 'password1234' literals passed to
SofiaAccount.create! for the users (treasurer_user, main_bartender_user,
renting_manager_user) with the seed_password variable so
SofiaAccount.create!(username: ..., password: seed_password, user: ...) is used
for each account; keep the ENV.fetch fallback as-is so devs can override via
SEED_PASSWORD.
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4a331ed and ed3ec8c.

📒 Files selected for processing (2)
  • db/seeds.rb
  • db/seeds/products.rb
🧰 Additional context used
🧬 Code graph analysis (1)
db/seeds.rb (11)
app/models/role.rb (1)
  • name (8-16)
app/models/invoice.rb (2)
  • name (15-17)
  • amount (23-25)
app/controllers/credit_mutations_controller.rb (1)
  • create (16-33)
app/controllers/users_controller.rb (2)
  • create (74-85)
  • activities (119-129)
app/controllers/orders_controller.rb (1)
  • create (18-39)
app/controllers/sofia_accounts_controller.rb (1)
  • create (12-30)
app/controllers/payments_controller.rb (1)
  • create (10-23)
app/controllers/products_controller.rb (1)
  • create (7-16)
app/controllers/activities_controller.rb (1)
  • create (47-58)
app/controllers/invoices_controller.rb (1)
  • create (29-41)
app/controllers/price_lists_controller.rb (1)
  • create (23-33)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build
🔇 Additional comments (6)
db/seeds/products.rb (2)

2-14: LGTM! Well-structured color mapping.

The frozen hash with descriptive Dutch comments provides clear category-to-color associations. All product categories are covered.


28-66: Consistent color application across all product categories.

The color: attribute is correctly passed to all Product.create calls using the corresponding category key from category_colors.

db/seeds.rb (4)

14-30: LGTM! Good test data setup.

The explicit Dutch names improve seed data readability. The underage user (16 years) is useful for testing age-restricted product scenarios.


33-59: LGTM! Historical activities with realistic timestamps.

The time calculation correctly creates activities that started days_ago and ended approximately 24 hours later. This provides good test data for historical/locked activities.


70-91: LGTM! Realistic credit mutation data.

Good variation with different descriptions and amount ranges (including corrections that can be negative). The optional nil activity is appropriate for mutations not tied to specific activities.


108-109: No issues found. The :sofia_account trait only sets the provider field on the User model and does not create a SofiaAccount record. Line 109 correctly creates the actual SofiaAccount with specific credentials. The SofiaAccount model validates uniqueness on the user association, preventing duplicates.

Likely an incorrect or invalid review comment.

Comment thread db/seeds.rb
@lodewiges lodewiges merged commit a2f7af6 into staging Jan 14, 2026
6 checks passed
@lodewiges lodewiges deleted the feature/improve-seeding branch January 14, 2026 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

improve seeding

2 participants