Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughAdds 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
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
Greptile Summary
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
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"
|
There was a problem hiding this comment.
2 files reviewed, no comments
Edit Code Review Agent Settings | Greptile
React with 👍 or 👎 to share your feedback on this new summary format
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
apps/backend/prisma/seed.ts (1)
791-923: Consider tightening types forpaymentsProducts
paymentsProductsis currently typed asRecord<string, unknown>, then funneled throughresolveProductandcloneJsonand cast toPrisma.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
📒 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 isolatedThe added imports (CRUD handlers, tenancy helpers, Prisma enums, email theme, CRUD types) plus
DUMMY_PROJECT_IDandEXPLORATORY_TEAM_DISPLAY_NAMEcleanly 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‑scopedGating
seedDummyProjectbehindSTACK_SEED_ENABLE_DUMMY_PROJECTand reusing the existinginternalTeamIdasownerTeamIdkeeps 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, andPaymentsSetupgive 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 invariantsThe
seedDummyTeams/seedDummyUsershelpers correctly:
- Look up existing records (by
tenancyId+displayNameor contact email) before creating, and- Use
teamsCrudHandlers.adminCreate,usersCrudHandlers.adminCreate, andteamMembershipsCrudHandlers.adminCreateso 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
seedDummyProjectcleanly handles both create and update paths viacreateOrUpdateProjectWithLegacyConfig, usesgetSoleTenancyFromProjectBranch+getPrismaClientForTenancyfor 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 idempotentThe
SubscriptionSeed,ItemQuantityChangeSeed, andOneTimePurchaseSeedtypes plusDUMMY_SEED_IDSgive stable identifiers, andseedDummyTransactionsusesupserton(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 viathrowErron misconfiguration.
1439-1574: Email seeding correctly associates optional users and is repeatable
seedDummyEmails’ use ofresolveOptionalUserIdplussentEmail.upsertkeyed 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.
There was a problem hiding this comment.
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 forpaymentsProductsandpaymentsOverrideprovide 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 anyto bypass type checking forpaymentsOverride, 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
📒 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
displayNameassumes 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
cloneJsonutility appropriately handles deep-copying JSON-serializable objects for Prisma'sInputJsonValuetype. 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.JsonNullfor 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 inseedDummyUsers.The function hardcodes OAuth provider IDs (
github,microsoft,spotify) that may not be included in theSTACK_SEED_INTERNAL_PROJECT_OAUTH_PROVIDERSenvironment variable. The dummy project is configured at line 946-949 with only providers from that environment variable, butseedDummyUsersunconditionally 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.oauthProviderIdsinseedDummyUsers, or ensure all four providers are documented as required in environment setup.
https://www.loom.com/share/b3216a8f83bb4260a3be4cfca4988cb4
Summary by CodeRabbit
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.apps/backend/prisma/seed.ts):DUMMY_PROJECT_IDwith config (email theme, OAuth providers, localhost, API key options) and setsstripeAccountId.starter,growth,regression-addon) and installs all apps.apps/backend/.env.development):STACK_SEED_ENABLE_DUMMY_PROJECT=trueto enable dummy project seeding.Written by Cursor Bugbot for commit 98fa655. This will update automatically on new commits. Configure here.