Split dev dummy seeds into independent per-domain files#1576
Conversation
db/seeds/dev/dummy.rb had grown into a 2,100-line catch-all that seeded everything from organizations to analytics in one shared scope, making it hard to find, reason about, or reseed a single domain. Break it into focused files, each behind its own db:seed:* task and orchestrated (in dependency order) by db:seed:dev, matching how users.rb and payments.rb are already organized. Each file is independent: it can run on its own and looks up — rather than requires — data from the other dev seeds, degrading gracefully when that data is absent. Two latent issues surfaced once the code no longer shared one scope: - monthly_reports relied on aisha_user/aisha_org leaking from the workshop-log section; both are now declared locally. - quotes divided by seed_workshops.size when linking, which raised ZeroDivisionError if run with no workshops present; linking is now skipped when none exist. Verified by running db:seed:dev against both the existing dev database and a fresh one (so every guard fires), and by running individual tasks standalone with their dependencies absent. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
| # they are repeated here so this file stands alone. | ||
|
|
||
| aisha_user = User.find_by(email: "aisha.user@example.com") | ||
| aisha_org = aisha_user&.person&.affiliations&.first&.organization || Organization.first |
There was a problem hiding this comment.
🤖 From Claude: These two lookups previously leaked from the workshop-log seed section that ran before this code in the old dummy.rb scope. Re-declared here so the file stands alone.
| # Linking only makes sense once workshops exist (e.g. after db:seed:workshops); | ||
| # when run on its own with no workshops, just seed the quotes above and skip. | ||
| seed_quotes.each_with_index do |quote, i| | ||
| next if seed_workshops.empty? |
There was a problem hiding this comment.
🤖 From Claude: Guard against the i % seed_workshops.size divide-by-zero below — dummy.rb always created workshops first, but an independent quotes run may have none.
There was a problem hiding this comment.
Pull request overview
This PR refactors the dev-only “dummy” seeding setup by replacing the monolithic db/seeds/dev/dummy.rb with independent per-domain seed files and corresponding db:seed:<domain> rake tasks, while preserving db:seed:dev as the orchestrated “seed everything” entrypoint.
Changes:
- Replaced
db:seed:dummywith a set of per-domaindb:seed:<name>tasks and updateddb:seed:devto run them in order. - Split the former
dummy.rbcontent into separatedb/seeds/dev/*.rbfiles (workshops, orgs, quotes, people, events, etc.). - Added/adjusted guard logic in some seeds to better support standalone execution (though a couple of nil-dereference gaps remain to fix).
Reviewed changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/tasks/dev.rake | Defines db:seed:dev dependency order and adds per-domain db:seed:<name> tasks; removes db:seed:dummy. |
| db/seeds/dev/dummy.rb | Removes the former monolithic dev seed file. |
| db/seeds/dev/organizations.rb | Seeds dev organizations. |
| db/seeds/dev/workshops.rb | Seeds workshops, assigns categories/sectors, and creates variations. |
| db/seeds/dev/quotes.rb | Seeds quotes and links them to workshops when present. |
| db/seeds/dev/people_profiles.rb | Seeds people profiles, affiliations, addresses, and sectors for search/disambiguation scenarios. |
| db/seeds/dev/home_page_content.rb | Seeds home page editorial content (news, ideas, stories) and some cross-links. |
| db/seeds/dev/workshop_logs.rb | Seeds workshop logs (primarily for Aisha + a few admin logs). |
| db/seeds/dev/monthly_reports.rb | Seeds monthly reports and related form field answers. |
| db/seeds/dev/events_management.rb | Seeds events, shared forms, registrations, and form submissions. |
| db/seeds/dev/resources.rb | Seeds resources with varying visibility/metadata. |
| db/seeds/dev/faqs.rb | Seeds FAQ entries. |
| db/seeds/dev/video_recordings.rb | Seeds video recordings. |
| db/seeds/dev/notifications.rb | Seeds contact-us and FYI notifications. |
| db/seeds/dev/bookmarks.rb | Seeds bookmarks for key seed users across bookmarkable types. |
| db/seeds/dev/analytics.rb | Seeds Ahoy visits/events to populate analytics dashboards. |
| aisha_org = aisha_user&.person&.affiliations&.first&.organization || Organization.first | ||
| all_workshops = Workshop.all.to_a.shuffle | ||
|
|
||
| if aisha_user && all_workshops.any? && WorkshopLog.where(created_by_id: aisha_user.id).none? |
| create_monthly_report = ->(organization:, created_by:, date:) { | ||
| wt = organization&.windows_type || WindowsType.first | ||
| report = MonthlyReport.create!( | ||
| organization_id: organization.id, |
| } | ||
|
|
||
| if data[:with_user] | ||
| user_email = data[:email] || "#{data[:first_name].downcase.gsub(' ', '')}.#{data[:last_name].downcase.gsub(' ', '')}@example.com" |
| end | ||
|
|
||
| puts " Created #{Notification.where(kind: %w[contact_us contact_us_fyi]).count} contact_us notifications " \ | ||
| "(#{Notification.where(kind: 'contact_us_fyi', responded: true).count} marked responded)" |
| resource_body = Faker::Lorem.paragraph(sentence_count: 8) | ||
| Resource.where(title: Faker::Book.title).first_or_create!( |
| month: 8, | ||
| year: 2008, | ||
| description: "This workshop helps participants access their deepest feelings through the use of writing and Liquid Watercolors to create an Inspirational Scroll.", | ||
| rhino_tips: '<strong>Elvira Barnard </strong>of<strong> Chicana Service Action Center</strong> asked clients to bring their favorite poem to group to use in their art piece. <br /><br /><strong>Wendy Ball </strong>of <strong>Equinox, Inc. </strong>used these Inspirational Quotes as an examples:<br /><u>A Friendship Blessing:</u> <font size="1">(adapted from Anam Cara – a book of celtic wisdom by John O’Donnohue)</font><br />May I be blessed with good friends.<br />May I learn to be a good friend to myself.<br />May I be able to journey to that place in my soul<br />where there is great love, warmth, feeling,<br />and forgiveness.<br />May this change me.<br />May it transfigure that which is negative,<br />distant, or cold in me.<br />May I be brought in to the real passion, kinship,<br />and affinity of belonging.<br />May I treasure my friends.<br />May I be good to them and may I be there for them;<br />May they bring me all the blessings, challenges,<br />truth, and light that I need for my journey.<br />May I never be isolated.<br />May I always be in the gentle nest of belonging<br />with my soul<br /><br /><u>A Blessing of Solitude:</u> <font size="1">(adapted from Anam Cara – a book of celtic wisdom by John O’Donnohue)</font><br />May I recognize in my life the presence, power, and light of my soul.<br />May I realize that I am never alone,<br />that my soul in its brightness and belonging connects me intimately <br />with the rhythm of the universe.<br />May I have respect for my own<br />Individuality and difference.<br />May I realize that the shape of my soul is unique,<br />that I have a special destiny here,<br />that behind the façade of my life there is something beautiful, good and eternal happening.<br />May I learn to see myself with the same delight, pride, and expectation with which God sees me in every moment.<br /><br /><u>DV Affirmations:</u> (<font size="1">some affirmations from Melody Beattie)</font><br />I’m no longer willing to lose my self esteem, self respect, my children’s well-being, my job, home, possessions, safety, credit, my sanity or myself to preserve a relationship.<br /><br />I don’t have to be willing to lose everything for love.<br /><br />I can learn to make appropriate choices concerning what I’m willing to give in my relationships of myself, time, talents, and money<br /><br />As I develop healthy boundaries I am learning to respect others and myself. I am learning not to use or abuse others or allow them to use or abuse me. I no longer abuse myself! I am learning not to control others or let them control me. I am learning to stop taking responsibility for other people and stop letting them take responsibility for me. I am learning to take full responsibility for myself.<br /><br />I am proud of myself for accepting to take care of myself no matter what happens, where I go, or who I’m with.<br /><br />I am proud of myself for believing that I deserve a better life and for acting on this belief.<br /><br />I have the right to take care of myself and to be myself.<br /><br />I am learning to value, trust and listen to myself.<br /><br />I am able to choose and to alter the direction of my life.<br /><br />I own and treasure my life!<br /><br />I am not stuck or trapped in a relationship. I have choices. I may not be able to see them clearly right now, but I do have choices. I am responsible for my choices.', |
| month: 9, | ||
| year: 2009, | ||
| description: "This workshop will assist older children and teens to look inside and discover more about their inner-self. We are used to looking at our outer selves, our looks, our clothes, our appearance, the image we try to portray. This workshop gives us an opportunity to go to a deeper level and get more in touch with our inner-self.", | ||
| rhino_tips: '<span class="EmailHeader">Note About Introducing Embodied Art<br /></span>Consider sharing with the youth the benefits of moving their bodies in playful and safe ways. By sharing this information with them, you empower them to feel a sense of ownership over their bodies and their expression. For more about embodied art workshops and how to introduce them in your groups, see <a href="/awbw/workshop.php?workshopid=3018&dosearch=1&windowstypeid=2&searchtext=introduction&submit.x=0&submit.y=0" target="_blank">Introduction to Embodied Art Workshops</a>.', |
| month: 4, | ||
| year: 2014, | ||
| description: "This workshop provides an opportunity for participants to notice their personal needs by creating a flower where each petal represents one need. They will begin to see the many layers of needs\u2014physical, emotional and spiritual\u2014and to honor all these layers.", | ||
| rhino_tips: '<span class="TextHeader2"><span class="EmailHeader">Note About Conflicting Needs</span><br /></span>Sometimes a person might notice that their different needs seem to be in conflict with each other. (For example, the need to have more quiet alone time and the need to spend more playful, fun time with her children). This is okay. The purpose of this workshop is to reveal the many needs that can be seen as part of our entire makeup. It is okay not to be problem-solving at this time, but rather supporting participants as they reveal and learn to accept themselves at this creative stage, seeing not only the needs that can be fulfilled, but also those that seem far from resolution. By putting all the needs around a single circle, we allow our conscious mind to see how they all can coexist and we can begin to find safer and more creative ways to embrace and move through any conflicts.<span class="TextHeader2"></span><br /><br /><span class="EmailHeader">Note About Introducing Embodied Art<br /></span>Consider sharing with your participants the benefits of moving their bodies in playful and safe ways. Understanding what’s meaningful about movement and body awareness can help participants feel at ease expanding their comfort zones. For more about embodied art workshops and how to introduce them in your groups, see <a href="/awbw/workshop.php?workshopid=3017&dosearch=1&windowstypeid=1&searchtext=introduction&submit.x=0&submit.y=0" target="_blank">Introduction to Embodied Art Workshops</a>.', |
| { | ||
| id: 12, question: "How do I get a scholarship for Leadership Training?", | ||
| answer: %( | ||
| We award all scholarships based on need and avaishability of funds to agencies serving domestic violence clients. We ask those interested in applying for scholarship funding to submit a <a href="/awbw/programs-leadership_training-scholarships_application.php">Scholarship Request</a> 4 weeks in advance of the chosen training. <a href="/awbw/programs-leadership_training-scholarships.php">Click here</a> to see the guidelines. |
| { | ||
| id: 13, question: "I need more art supplies to hold my Windows Workshops. How can AWBW help?", | ||
| answer: %( | ||
| AWBW awards Art Supply Scholarships to active reporting programs. All scholarship grants are based on need, avaishability of funds and strength of monthly reporting. Programs must report for a minimum of three months to be eligible to receive an art supply scholarship and must continue to hold weekly workshops and report monthly for a period of one year.<br /><br />AWBW programs that have been awarded art supply scholarships will be reimbursed for art supplies bought at any purveyor of their choosing as long as they submit receipts attached to AWBW's reimbursement form.<br /><br />Visit our <a href="/awbw/programs-women_windows-art_supplies.php">recommended supply resource list</a> for information on where you can order art supplies.<br /><br />AWBW also offers some free art supplies from our donated goods shopping area. Programs in good standing can make an appointment to "free shop" at our Venice location. |
What is the goal of this PR and why is this important?
db/seeds/dev/dummy.rbhad grown into a ~2,100-line catch-all seeding everything from organizations to analytics in one shared local scope — hard to find anything in, hard to reason about, and impossible to reseed a single domain without rerunning the whole thing.db:seed:*task, continuing the existing effort that already movedusersandpaymentsout of the monolith.How did you approach the change?
db/seeds/dev/*.rbfile:organizations,workshops,quotes,people_profiles,home_page_content,workshop_logs,monthly_reports,events_management,resources,faqs,video_recordings,notifications,bookmarks,analytics.db:seed:<name>task per file indev.rake;db:seed:devruns them in dependency order after the basedb:seed+db:seed:users, ending withdb:seed:payments. Removeddb:seed:dummy.payments.rb/users.rbpattern.monthly_reportsrelied onaisha_user/aisha_orgleaking from the workshop-log section — now declared locally.quotesdivided byseed_workshops.sizewhen linking, raisingZeroDivisionErrorif run with no workshops present — linking is now skipped when none exist.Anything else to add?
db:seed:devagainst both the existing dev database and a freshly migrated throwaway database (so every previously-skipped guard — workshop logs, monthly reports, analytics — actually fires), and by running several downstream tasks standalone with their dependencies absent.db:seed.🤖 Generated with Claude Code