Skip to content

seed script dummy project#1018

Merged
BilalG1 merged 6 commits intodevfrom
seed-script-dummy-project
Nov 19, 2025
Merged

seed script dummy project#1018
BilalG1 merged 6 commits intodevfrom
seed-script-dummy-project

Conversation

@BilalG1
Copy link
Copy Markdown
Collaborator

@BilalG1 BilalG1 commented Nov 17, 2025

https://www.loom.com/share/b3216a8f83bb4260a3be4cfca4988cb4

Summary by CodeRabbit

  • New Features
    • Added an opt-in sample-project population (toggle via environment) to explore the app.
    • Sample dataset expanded with teams, users, memberships, subscriptions, transactions/purchases, payment setup, emails, and many richer demo records.
  • Chores
    • Introduced an environment toggle to enable/disable the dummy sample project.

Note

Adds an optional dummy project seeding flow (toggled by STACK_SEED_ENABLE_DUMMY_PROJECT) that populates teams, users, memberships, payments config, transactions, and emails.

  • Backend Seed (apps/backend/prisma/seed.ts):
    • Dummy Project: Creates/updates DUMMY_PROJECT_ID with config (email theme, OAuth providers, localhost, API key options) and sets stripeAccountId.
    • Sample Data: Seeds teams, users, and team memberships via CRUD handlers.
    • Payments: Applies payments override (catalogs, items, products incl. starter, growth, regression-addon) and installs all apps.
    • Transactions: Seeds subscriptions, item quantity changes, and one-time purchases with fixed IDs.
    • Emails: Seeds sent emails with sample senders, content, and errors.
  • Env (apps/backend/.env.development):
    • Adds toggle STACK_SEED_ENABLE_DUMMY_PROJECT=true to enable dummy project seeding.

Written by Cursor Bugbot for commit 98fa655. This will update automatically on new commits. Configure here.

@vercel
Copy link
Copy Markdown

vercel bot commented Nov 17, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
stack-backend Ready Ready Preview Comment Nov 19, 2025 11:40am
stack-dashboard Ready Ready Preview Comment Nov 19, 2025 11:40am
stack-demo Ready Ready Preview Comment Nov 19, 2025 11:40am
stack-docs Ready Ready Preview Comment Nov 19, 2025 11:40am

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Nov 17, 2025

Walkthrough

Adds an env flag to enable seeding a dedicated dummy project in development and implements a gated seeding flow that creates/updates a dummy project, teams, users, subscriptions, transactions, one‑time purchases, item quantity changes, emails, and applies related environment overrides.

Changes

Cohort / File(s) Summary
Environment Configuration
apps/backend/.env.development
Added STACK_SEED_ENABLE_DUMMY_PROJECT=true to toggle dummy project seeding.
Dummy Project Seeding
apps/backend/prisma/seed.ts
Adds gated dummy-project seeding controlled by the new flag; introduces constants (DUMMY_PROJECT_ID, EXPLORATORY_TEAM_DISPLAY_NAME), new imports (team/membership CRUD, Prisma types), many seed helpers (seedDummyTeams, seedDummyUsers, seedDummyProjects, seedDummyTransactions, seedDummyEmails), payments/installations builders, upsert persistence for subscriptions/itemQuantityChanges/oneTimePurchases/emails, cloneJson utility, and several seed-related type definitions.

Sequence Diagram(s)

sequenceDiagram
    participant Env as Environment
    participant Seed as seed()
    participant DB as Database

    Env->>Seed: Read STACK_SEED_ENABLE_DUMMY_PROJECT
    alt Enabled
        Note over Seed: Create or update dummy project and related data
        Seed->>DB: upsert Project (DUMMY_PROJECT_ID)
        Seed->>DB: seedDummyTeams()
        Seed->>DB: seedDummyUsers()
        Seed->>DB: seedDummyTransactions()  -- subscriptions, itemQuantityChanges, oneTimePurchases
        Seed->>DB: seedDummyEmails()
        DB-->>Seed: Persisted records
        Seed->>Env: apply env overrides for dummy payments/apps
    else Disabled
        Seed->>DB: run standard seed flow
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Focus review on:
    • The gating check for STACK_SEED_ENABLE_DUMMY_PROJECT.
    • Idempotency and upsert logic for subscriptions, itemQuantityChanges, oneTimePurchases, and emails.
    • Referential integrity between projects, teams, users, and memberships.
    • Correctness of JSON cloning (cloneJson) and construction of nested payloads.
    • Any environment overrides that alter payments or installed app configurations.

Poem

🐇 I hop and plant a tiny seed,
Teams form rows and users feed,
Payments hum and emails sing,
A dev project sprouts and springs —
Soft code fields wake, alive with speed.

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Description check ⚠️ Warning PR description lacks direct text explanation and relies primarily on a Loom video link and auto-generated cursor summary. Provide a clear text summary of changes in the PR description body. While the cursor summary is helpful, the primary description should explain the purpose, implementation details, and any testing performed in plain text.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'seed script dummy project' directly aligns with the main changes: adding comprehensive dummy project seeding to the seed.ts file and enabling it via environment variable.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch seed-script-dummy-project

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.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Nov 17, 2025

Greptile Summary

  • Added environment flag STACK_SEED_ENABLE_DUMMY_PROJECT to control dummy project seeding
  • Implemented comprehensive seeding functions for dummy project with 8 teams, 16 users, subscriptions, payments, and email data

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk.
  • The changes are well-structured seed script additions that only run in development when explicitly enabled. The code properly uses Maps to avoid prototype pollution, includes comprehensive error handling with upsert operations, and uses fixed UUIDs for idempotency.
  • No files require special attention.

Important Files Changed

Filename Overview
apps/backend/prisma/seed.ts Added comprehensive dummy project seeding with ~1000 lines creating teams, users, subscriptions, payments, and email data for testing.

Sequence Diagram

sequenceDiagram
    participant Seed as "seed()"
    participant Env as "Environment"
    participant DB as "Database"
    participant SeedDummy as "seedDummyProject()"
    
    Seed->>Env: "Check STACK_SEED_ENABLE_DUMMY_PROJECT"
    Env-->>Seed: "true"
    Seed->>SeedDummy: "Call with ownerTeamId, oauthProviderIds"
    SeedDummy->>DB: "Create/update dummy project"
    SeedDummy->>DB: "Seed 8 teams via seedDummyTeams()"
    SeedDummy->>DB: "Seed 16 users via seedDummyUsers()"
    SeedDummy->>DB: "Configure payments setup"
    SeedDummy->>DB: "Seed subscriptions and transactions"
    SeedDummy->>DB: "Seed email records"
    SeedDummy-->>Seed: "Complete"
Loading

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile
React with 👍 or 👎 to share your feedback on this new summary format

Copy link
Copy Markdown
Contributor

@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

🧹 Nitpick comments (1)
apps/backend/prisma/seed.ts (1)

791-923: Consider tightening types for paymentsProducts

paymentsProducts is currently typed as Record<string, unknown>, then funneled through resolveProduct and cloneJson and cast to Prisma.InputJsonValue. This works but loses type‑safety on the product structure and IDs.

Consider introducing a dedicated type (or as const + keyof typeof paymentsProducts) so product shapes and IDs are checked at compile time, reducing the risk of silent typos (e.g. catalog/item IDs) in future edits.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bc57d0d and 92e3dda.

📒 Files selected for processing (2)
  • apps/backend/.env.development (1 hunks)
  • apps/backend/prisma/seed.ts (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/backend/prisma/seed.ts (8)
apps/backend/src/lib/tenancies.tsx (3)
  • Tenancy (53-53)
  • DEFAULT_BRANCH_ID (19-19)
  • getSoleTenancyFromProjectBranch (65-72)
packages/stack-shared/src/utils/errors.tsx (1)
  • throwErr (10-19)
packages/stack-shared/src/utils/dates.tsx (1)
  • DayInterval (146-146)
packages/stack-shared/src/helpers/emails.ts (1)
  • DEFAULT_EMAIL_THEME_ID (105-105)
apps/backend/src/prisma-client.tsx (1)
  • getPrismaClientForTenancy (68-70)
apps/backend/src/lib/config.tsx (1)
  • overrideEnvironmentConfigOverride (242-283)
packages/stack-shared/src/utils/objects.tsx (2)
  • typedFromEntries (281-283)
  • typedEntries (263-265)
packages/stack-shared/src/apps/apps-config.ts (1)
  • ALL_APPS (50-141)
🪛 Gitleaks (8.29.0)
apps/backend/prisma/seed.ts

[high] 1115-1115: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

⏰ 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). (11)
  • GitHub Check: Vercel Agent Review
  • GitHub Check: restart-dev-and-test-with-custom-base-port
  • GitHub Check: build (22.x)
  • GitHub Check: build (22.x)
  • GitHub Check: lint_and_build (latest)
  • GitHub Check: docker
  • GitHub Check: setup-tests
  • GitHub Check: all-good
  • GitHub Check: build (22.x)
  • GitHub Check: restart-dev-and-test
  • GitHub Check: check_prisma_migrations (22.x)
🔇 Additional comments (7)
apps/backend/prisma/seed.ts (7)

2-21: Wiring for dummy project seeding looks clean and isolated

The added imports (CRUD handlers, tenancy helpers, Prisma enums, email theme, CRUD types) plus DUMMY_PROJECT_ID and EXPLORATORY_TEAM_DISPLAY_NAME cleanly scope all dummy‑project behavior behind explicit constants and existing shared helpers, which should keep the seed logic consistent with the rest of the system.


263-269: Conditional dummy project seeding is well‑scoped

Gating seedDummyProject behind STACK_SEED_ENABLE_DUMMY_PROJECT and reusing the existing internalTeamId as ownerTeamId keeps this dummy data strictly opt‑in and neatly attached to the internal tenancy, while remaining idempotent on re‑runs.


493-533: Type definitions make the dummy seed data self‑documenting

DummyProjectSeedOptions, TeamSeed, UserSeed, SeedDummyTeamsOptions, SeedDummyUsersOptions, and PaymentsSetup give the seed helpers clear contracts and make the data model for the dummy project easy to follow and evolve.


534-789: Team/user seeding is idempotent and reuses CRUD invariants

The seedDummyTeams/seedDummyUsers helpers correctly:

  • Look up existing records (by tenancyId + displayName or contact email) before creating, and
  • Use teamsCrudHandlers.adminCreate, usersCrudHandlers.adminCreate, and teamMembershipsCrudHandlers.adminCreate so all validations, side‑effects, and permission wiring remain consistent with normal flows.

The membership check on the composite key keeps re‑running the seed script safe.


925-1022: Dummy project creation/update and config override are robust

seedDummyProject cleanly handles both create and update paths via createOrUpdateProjectWithLegacyConfig, uses getSoleTenancyFromProjectBranch + getPrismaClientForTenancy for correct multi‑tenancy scoping, and then applies an environment override that enables all apps and test‑mode payments. The flow looks idempotent and safe to re‑run.


1024-1437: Transaction, item‑quantity, and one‑time purchase seeds are consistent and idempotent

The SubscriptionSeed, ItemQuantityChangeSeed, and OneTimePurchaseSeed types plus DUMMY_SEED_IDS give stable identifiers, and seedDummyTransactions uses upsert on (tenancyId, id) to keep seeding repeatable. The helper resolvers (resolveTeamId, resolveUserId, resolveProduct) ensure referential integrity between users/teams, payments config, and the seeded records, failing fast via throwErr on misconfiguration.


1439-1574: Email seeding correctly associates optional users and is repeatable

seedDummyEmails’ use of resolveOptionalUserId plus sentEmail.upsert keyed on (tenancyId, id) makes the email seed data both referentially sound (for emails tied to users) and idempotent. The variety of sender configs and error payloads should give good coverage for UI and reporting paths.

Copy link
Copy Markdown
Contributor

@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

🧹 Nitpick comments (3)
apps/backend/prisma/seed.ts (3)

531-534: Consider stronger typing for payments setup.

The Record<string, unknown> types for paymentsProducts and paymentsOverride provide minimal type safety and make it easy to introduce inconsistencies or errors in payment configurations.

Consider defining more specific types based on the actual payment product structure, or at minimum use a union type to constrain the possible values.


927-1024: Consider error handling for resilient seeding.

The orchestration logic is clear and well-structured. However, the function lacks error handling—if any seeding step fails (team creation, user creation, transaction seeding), the entire process aborts. For a seed script that may be run multiple times, consider wrapping critical sections in try-catch blocks to log failures without halting the entire process.

Additionally, line 993 uses as any to bypass type checking for paymentsOverride, which could mask configuration errors.


1143-1271: Hard-coded dates will become stale.

The subscription seeds use fixed dates from 2024 (e.g., lines 1154-1155, 1170-1171, etc.). As time passes, these dates will be increasingly far in the past, making the dummy data less realistic for development and testing.

Consider using relative dates based on the current date:

const now = new Date();
const oneMonthAgo = new Date(now.getFullYear(), now.getMonth() - 1, now.getDate());
const oneMonthFromNow = new Date(now.getFullYear(), now.getMonth() + 1, now.getDate());

// Then use these in subscription seeds:
currentPeriodStart: oneMonthAgo,
currentPeriodEnd: oneMonthFromNow,

This would keep the dummy data relevant regardless of when the seed script runs.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 661a1e6 and 2439839.

📒 Files selected for processing (1)
  • apps/backend/prisma/seed.ts (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/backend/prisma/seed.ts (12)
apps/backend/src/lib/tenancies.tsx (3)
  • Tenancy (53-53)
  • DEFAULT_BRANCH_ID (19-19)
  • getSoleTenancyFromProjectBranch (65-72)
apps/backend/src/app/api/latest/teams/crud.tsx (1)
  • teamsCrudHandlers (29-245)
apps/backend/src/app/api/latest/users/crud.tsx (1)
  • usersCrudHandlers (428-1082)
packages/stack-shared/src/utils/errors.tsx (1)
  • throwErr (10-19)
apps/backend/src/app/api/latest/team-memberships/crud.tsx (1)
  • teamMembershipsCrudHandlers (43-160)
packages/stack-shared/src/utils/dates.tsx (1)
  • DayInterval (146-146)
packages/stack-shared/src/helpers/emails.ts (1)
  • DEFAULT_EMAIL_THEME_ID (105-105)
apps/backend/src/lib/projects.tsx (2)
  • getProject (71-74)
  • createOrUpdateProjectWithLegacyConfig (76-271)
apps/backend/src/prisma-client.tsx (1)
  • getPrismaClientForTenancy (68-70)
apps/backend/src/lib/config.tsx (1)
  • overrideEnvironmentConfigOverride (242-283)
packages/stack-shared/src/utils/objects.tsx (2)
  • typedFromEntries (281-283)
  • typedEntries (263-265)
packages/stack-shared/src/apps/apps-config.ts (1)
  • ALL_APPS (50-141)
🪛 Gitleaks (8.29.0)
apps/backend/prisma/seed.ts

[high] 1117-1117: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

⏰ 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). (11)
  • GitHub Check: build (22.x)
  • GitHub Check: build (22.x)
  • GitHub Check: lint_and_build (latest)
  • GitHub Check: build (22.x)
  • GitHub Check: restart-dev-and-test
  • GitHub Check: setup-tests
  • GitHub Check: restart-dev-and-test-with-custom-base-port
  • GitHub Check: docker
  • GitHub Check: check_prisma_migrations (22.x)
  • GitHub Check: all-good
  • GitHub Check: Vercel Agent Review
🔇 Additional comments (6)
apps/backend/prisma/seed.ts (6)

2-20: LGTM!

The new imports and constants are well-organized and appropriately scoped for the dummy project seeding functionality.


263-270: LGTM!

The environment variable check now correctly uses strict string comparison, consistent with other checks in the codebase. The previous review concern has been addressed.


536-574: LGTM with a minor note.

The function correctly uses the CRUD handler to create teams with proper idempotency checks. The implementation follows the established patterns in the codebase.

Note: The lookup by displayName assumes display names are unique within the tenancy. While this is reasonable for seed data, consider documenting this assumption if display name uniqueness isn't enforced at the database level.


1093-1122: LGTM!

The cloneJson utility appropriately handles deep-copying JSON-serializable objects for Prisma's InputJsonValue type. The fixed seed IDs enable idempotent upsert operations, which is essential for a seed script that may run multiple times.


1441-1576: LGTM!

The email seeding implementation correctly handles different email scenarios including successful sends, delivery failures, and template errors. The use of Prisma.JsonNull for null JSON fields is appropriate.

Note: The static analysis tool flagged line 1117 as a potential API key exposure, but this is a false positive—it's just a UUID used as a seed data identifier.


576-791: Fix OAuth provider configuration mismatch in seedDummyUsers.

The function hardcodes OAuth provider IDs (github, google, microsoft, spotify) that may not be included in the STACK_SEED_INTERNAL_PROJECT_OAUTH_PROVIDERS environment variable. The dummy project is configured at line 946-949 with only providers from that environment variable, but seedDummyUsers unconditionally creates users with the hardcoded providers at line 755-759 without validating they exist in the project configuration.

This will cause failures or incorrect behavior if the environment variable is empty or missing any of the four hardcoded providers. Either validate provider IDs against options.oauthProviderIds in seedDummyUsers, or ensure all four providers are documented as required in environment setup.

@BilalG1 BilalG1 requested a review from N2D4 November 17, 2025 23:08
Copy link
Copy Markdown
Contributor

@N2D4 N2D4 left a comment

Choose a reason for hiding this comment

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

amazing!

@BilalG1 BilalG1 merged commit 0335e04 into dev Nov 19, 2025
20 checks passed
@BilalG1 BilalG1 deleted the seed-script-dummy-project branch November 19, 2025 17:08
@coderabbitai coderabbitai bot mentioned this pull request Nov 26, 2025
@coderabbitai coderabbitai bot mentioned this pull request Dec 26, 2025
@coderabbitai coderabbitai bot mentioned this pull request Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants