feat(run-ops): activation — drop cross-DB FKs, provision run-ops DB, enable split#4124
feat(run-ops): activation — drop cross-DB FKs, provision run-ops DB, enable split#4124d-cs wants to merge 4 commits into
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughChangesThis PR removes cross-database foreign key constraints between control-plane and run-ops tables to support a database split, replacing Prisma relation fields with scalar-only identifier columns in the schema. New SQL migrations drop the Sequence Diagram(s)Diagrams included above within the hidden review stack for migration flow and cascade cleanup flow. Related PRs: None identified. Suggested labels: database, migration, testing Suggested reviewers: none identified 🐰 hop hop, the tables split apart, 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
76dabfd to
dffb0d2
Compare
|
There was a problem hiding this comment.
Actionable comments posted: 4
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal-packages/database/prisma/schema.prisma (1)
1567-1581: 🗄️ Data Integrity & Integration | 🔴 Critical | 🏗️ Heavy lift
TaskRunAttempt/TaskRunTagstill declare full relations whose FKs are being dropped.
TaskRunAttempt.backgroundWorker,.backgroundWorkerTask,.runtimeEnvironment(lines 1639-1646) andTaskRunTag.project(line 1573) still use@relation(...), butinternal-packages/database/prisma/migrations/20260629120000_drop_run_ops_control_plane_foreign_keys/migration.sqldrops exactlyTaskRunAttempt_backgroundWorkerId_fkey,TaskRunAttempt_backgroundWorkerTaskId_fkey,TaskRunAttempt_runtimeEnvironmentId_fkey, andTaskRunTag_projectId_fkey. UnlikeBatchTaskRun.runtimeEnvironmentandProjectAlert.taskRun(Attempt), these relations weren't converted to scalar-only.This is the same drift risk as the sibling models that were correctly fixed: Prisma migrate will detect the constraint as "missing" relative to the schema and try to re-add it, and once these run-subgraph rows physically live on the dedicated run-ops DB, any query using
include: { backgroundWorker: true }/backgroundWorkerTask/runtimeEnvironment/projectwill generate a JOIN against a table that doesn't exist on that connection.🛠️ Proposed fix (mirror the BatchTaskRun/ProjectAlert pattern)
backgroundWorker BackgroundWorker `@relation`(fields: [backgroundWorkerId], references: [id], onDelete: Cascade, onUpdate: Cascade) - backgroundWorkerId String + backgroundWorkerId String - backgroundWorkerTask BackgroundWorkerTask `@relation`(fields: [backgroundWorkerTaskId], references: [id], onDelete: Cascade, onUpdate: Cascade) - backgroundWorkerTaskId String + backgroundWorkerTaskId String - runtimeEnvironment RuntimeEnvironment `@relation`(fields: [runtimeEnvironmentId], references: [id], onDelete: Cascade, onUpdate: Cascade) - runtimeEnvironmentId String + runtimeEnvironmentId String- project Project `@relation`(fields: [projectId], references: [id], onDelete: Cascade, onUpdate: Cascade) - projectId String + projectId String(Note: removing the
backgroundWorkerrelation object also requires removing its reverse field onBackgroundWorker, and similarly forbackgroundWorkerTask/runtimeEnvironment/project, per Prisma's two-sided relation requirement.)Also applies to: 1630-1675
🧹 Nitpick comments (3)
internal-packages/run-store/src/PostgresRunStore.controlPlaneAlertFk.test.ts (2)
1-134: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueFilename doesn't reflect what's under test.
The file is named
PostgresRunStore.controlPlaneAlertFk.test.ts, but it never imports or exercisesPostgresRunStore; it operates directly on the Prisma clients to test the FK/schema contract forProjectAlert. Consider a name likeprojectAlert.controlPlaneAlertFk.test.tsto avoid implying coverage of thePostgresRunStoreclass itself.
54-79: 🗄️ Data Integrity & Integration | 🔵 Trivial | 💤 Low valueRemove the redundant
RunOpsPrismaClientcast.heteroRunOpsPostgresTestalready typesprisma17asRunOpsPrismaClient, so the assertion is unnecessary.apps/webapp/test/v3/runOpsMigration/runOpsCascadeCleanup.server.test.ts (1)
389-460: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDuplicated target/sibling seeding across the env and project "both writers" tests.
The seeding blocks for
target14/target17/sibling14/sibling17and their assertions (lines 395-423 and 432-460) are nearly identical, differing only in whethercleanupEnvironment/cleanupProjectis invoked. Extracting a shared helper (e.g.,seedTargetAndSibling(prisma14, prisma17)) would reduce duplication and keep both tests focused on the cleanup call + assertions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: feb1701f-837b-46db-897e-3bdc55e7e9e3
📒 Files selected for processing (10)
apps/webapp/test/batchTaskRunEnvironmentFkDrop.test.tsapps/webapp/test/dropTaskRunToTaskRunTagJoin.test.tsapps/webapp/test/v3/runOpsMigration/runOpsCascadeCleanup.server.test.tsinternal-packages/database/prisma/migrations/20260626130000_drop_task_run_to_task_run_tag_join/migration.sqlinternal-packages/database/prisma/migrations/20260626140000_drop_bulk_action_item_group_fk/migration.sqlinternal-packages/database/prisma/migrations/20260626150000_drop_batch_task_run_environment_fk/migration.sqlinternal-packages/database/prisma/migrations/20260629120000_drop_run_ops_control_plane_foreign_keys/migration.sqlinternal-packages/database/prisma/migrations/20260630120000_drop_project_alert_run_subgraph_foreign_keys/migration.sqlinternal-packages/database/prisma/schema.prismainternal-packages/run-store/src/PostgresRunStore.controlPlaneAlertFk.test.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (1)
- GitHub Check: internal / 📊 Merge Reports
🧰 Additional context used
📓 Path-based instructions (12)
internal-packages/database/**/prisma/migrations/*/*.sql
📄 CodeRabbit inference engine (internal-packages/database/CLAUDE.md)
internal-packages/database/**/prisma/migrations/*/*.sql: Clean up generated Prisma migrations by removing extraneous lines for junction tables (_BackgroundWorkerToBackgroundWorkerFile,_BackgroundWorkerToTaskQueue,_TaskRunToTaskRunTag,_WaitpointRunConnections,_completedWaitpoints) and indexes (SecretStore_key_idx, variousTaskRunindexes) unless explicitly added
When adding indexes to existing tables, useCREATE INDEX CONCURRENTLY IF NOT EXISTSto avoid table locks in production, and place each concurrent index in its own separate migration file
Indexes on newly created tables can useCREATE INDEXwithout CONCURRENTLY and can be combined in the same migration file as theCREATE TABLEstatement
When adding an index on a new column in an existing table, use two separate migrations: first forALTER TABLE ... ADD COLUMN IF NOT EXISTS ..., then forCREATE INDEX CONCURRENTLY IF NOT EXISTS ...in its own file
Files:
internal-packages/database/prisma/migrations/20260626140000_drop_bulk_action_item_group_fk/migration.sqlinternal-packages/database/prisma/migrations/20260630120000_drop_project_alert_run_subgraph_foreign_keys/migration.sqlinternal-packages/database/prisma/migrations/20260629120000_drop_run_ops_control_plane_foreign_keys/migration.sqlinternal-packages/database/prisma/migrations/20260626130000_drop_task_run_to_task_run_tag_join/migration.sqlinternal-packages/database/prisma/migrations/20260626150000_drop_batch_task_run_environment_fk/migration.sql
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.{ts,tsx}: Use types over interfaces for TypeScript
Avoid using enums; prefer string unions or const objects instead
Files:
apps/webapp/test/dropTaskRunToTaskRunTagJoin.test.tsinternal-packages/run-store/src/PostgresRunStore.controlPlaneAlertFk.test.tsapps/webapp/test/batchTaskRunEnvironmentFkDrop.test.tsapps/webapp/test/v3/runOpsMigration/runOpsCascadeCleanup.server.test.ts
{packages/core,apps/webapp}/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Use zod for validation in packages/core and apps/webapp
Files:
apps/webapp/test/dropTaskRunToTaskRunTagJoin.test.tsapps/webapp/test/batchTaskRunEnvironmentFkDrop.test.tsapps/webapp/test/v3/runOpsMigration/runOpsCascadeCleanup.server.test.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Use function declarations instead of default exports
Files:
apps/webapp/test/dropTaskRunToTaskRunTagJoin.test.tsinternal-packages/run-store/src/PostgresRunStore.controlPlaneAlertFk.test.tsapps/webapp/test/batchTaskRunEnvironmentFkDrop.test.tsapps/webapp/test/v3/runOpsMigration/runOpsCascadeCleanup.server.test.ts
**/*.{test,spec}.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Use vitest for all tests in the Trigger.dev repository
Files:
apps/webapp/test/dropTaskRunToTaskRunTagJoin.test.tsinternal-packages/run-store/src/PostgresRunStore.controlPlaneAlertFk.test.tsapps/webapp/test/batchTaskRunEnvironmentFkDrop.test.tsapps/webapp/test/v3/runOpsMigration/runOpsCascadeCleanup.server.test.ts
**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/otel-metrics.mdc)
**/*.ts: When creating or editing OTEL metrics (counters, histograms, gauges), ensure metric attributes have low cardinality by using only enums, booleans, bounded error codes, or bounded shard IDs
Do not use high-cardinality attributes in OTEL metrics such as UUIDs/IDs (envId, userId, runId, projectId, organizationId), unbounded integers (itemCount, batchSize, retryCount), timestamps (createdAt, startTime), or free-form strings (errorMessage, taskName, queueName)
When exporting OTEL metrics via OTLP to Prometheus, be aware that the exporter automatically adds unit suffixes to metric names (e.g., 'my_duration_ms' becomes 'my_duration_ms_milliseconds', 'my_counter' becomes 'my_counter_total'). Account for these transformations when writing Grafana dashboards or Prometheus queries
Files:
apps/webapp/test/dropTaskRunToTaskRunTagJoin.test.tsinternal-packages/run-store/src/PostgresRunStore.controlPlaneAlertFk.test.tsapps/webapp/test/batchTaskRunEnvironmentFkDrop.test.tsapps/webapp/test/v3/runOpsMigration/runOpsCascadeCleanup.server.test.ts
apps/webapp/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/webapp.mdc)
apps/webapp/**/*.{ts,tsx}: Access environment variables through theenvexport ofenv.server.tsinstead of directly accessingprocess.env
Use subpath exports from@trigger.dev/corepackage instead of importing from the root@trigger.dev/corepathUse named constants for sentinel/placeholder values (e.g.
const UNSET_VALUE = '__unset__') instead of raw string literals scattered across comparisons
Files:
apps/webapp/test/dropTaskRunToTaskRunTagJoin.test.tsapps/webapp/test/batchTaskRunEnvironmentFkDrop.test.tsapps/webapp/test/v3/runOpsMigration/runOpsCascadeCleanup.server.test.ts
apps/webapp/**/*.test.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/webapp.mdc)
Do not import
env.server.tsdirectly or indirectly into test files; instead pass environment-dependent values through options/parameters to make code testableFor testable code, never import
env.server.tsin test files. Pass configuration as options instead (e.g.,realtimeClient.server.tstakes config as constructor arg,realtimeClientGlobal.server.tscreates singleton with env config)
Files:
apps/webapp/test/dropTaskRunToTaskRunTagJoin.test.tsapps/webapp/test/batchTaskRunEnvironmentFkDrop.test.tsapps/webapp/test/v3/runOpsMigration/runOpsCascadeCleanup.server.test.ts
**/*.{ts,tsx,js,jsx,mts,cts,mjs,cjs}
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.{ts,tsx,js,jsx,mts,cts,mjs,cjs}: Usepnpm run typecheckfor changes in apps (apps/*) and internal packages (internal-packages/*), and never usebuildto verify those changes.
Use Vitest for tests, and never mock anything; use testcontainers instead.
Prefer static imports over dynamicimport(), and only use dynamic imports for unresolved circular dependencies, genuine code-splitting needs, or conditional runtime loading.
Files:
apps/webapp/test/dropTaskRunToTaskRunTagJoin.test.tsinternal-packages/run-store/src/PostgresRunStore.controlPlaneAlertFk.test.tsapps/webapp/test/batchTaskRunEnvironmentFkDrop.test.tsapps/webapp/test/v3/runOpsMigration/runOpsCascadeCleanup.server.test.ts
**/*.{test,spec}.{ts,tsx,js,jsx,mts,cts,mjs,cjs}
📄 CodeRabbit inference engine (CLAUDE.md)
Place test files next to the source files they cover (for example,
MyService.ts->MyService.test.ts).
Files:
apps/webapp/test/dropTaskRunToTaskRunTagJoin.test.tsinternal-packages/run-store/src/PostgresRunStore.controlPlaneAlertFk.test.tsapps/webapp/test/batchTaskRunEnvironmentFkDrop.test.tsapps/webapp/test/v3/runOpsMigration/runOpsCascadeCleanup.server.test.ts
**/*.{ts,tsx,js,jsx,mts,cts,mjs,cjs,md,mdx}
📄 CodeRabbit inference engine (CLAUDE.md)
Always import from
@trigger.dev/sdkwhen writing Trigger.dev tasks; never use@trigger.dev/sdk/v3or deprecatedclient.defineJob.
Files:
apps/webapp/test/dropTaskRunToTaskRunTagJoin.test.tsinternal-packages/run-store/src/PostgresRunStore.controlPlaneAlertFk.test.tsapps/webapp/test/batchTaskRunEnvironmentFkDrop.test.tsapps/webapp/test/v3/runOpsMigration/runOpsCascadeCleanup.server.test.ts
**/*.{test,spec}.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{test,spec}.{ts,tsx,js,jsx}: Write unit tests with Vitest, keep test files beside the files under test, and use descriptivedescribeanditblocks.
Avoid mocks or stubs in tests; when Redis or Postgres are needed, use the helpers from@internal/testcontainers.
Files:
apps/webapp/test/dropTaskRunToTaskRunTagJoin.test.tsinternal-packages/run-store/src/PostgresRunStore.controlPlaneAlertFk.test.tsapps/webapp/test/batchTaskRunEnvironmentFkDrop.test.tsapps/webapp/test/v3/runOpsMigration/runOpsCascadeCleanup.server.test.ts
🧠 Learnings (18)
📚 Learning: 2026-02-03T18:48:31.790Z
Learnt from: 0ski
Repo: triggerdotdev/trigger.dev PR: 2994
File: internal-packages/database/prisma/migrations/20260129162810_add_integration_deployment/migration.sql:14-18
Timestamp: 2026-02-03T18:48:31.790Z
Learning: For Prisma migrations targeting PostgreSQL: - When adding indexes to existing tables, create the index in a separate migration file and include CONCURRENTLY to avoid locking the table. - For indexes on newly created tables (in CREATE TABLE statements), you can create the index in the same migration file without CONCURRENTLY. This reduces rollout complexity for new objects while protecting uptime for existing structures.
Applied to files:
internal-packages/database/prisma/migrations/20260626140000_drop_bulk_action_item_group_fk/migration.sqlinternal-packages/database/prisma/migrations/20260630120000_drop_project_alert_run_subgraph_foreign_keys/migration.sqlinternal-packages/database/prisma/migrations/20260629120000_drop_run_ops_control_plane_foreign_keys/migration.sqlinternal-packages/database/prisma/migrations/20260626130000_drop_task_run_to_task_run_tag_join/migration.sqlinternal-packages/database/prisma/migrations/20260626150000_drop_batch_task_run_environment_fk/migration.sql
📚 Learning: 2026-03-22T13:49:20.068Z
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev PR: 3244
File: internal-packages/database/prisma/migrations/20260318114244_add_prompt_friendly_id/migration.sql:5-5
Timestamp: 2026-03-22T13:49:20.068Z
Learning: For Prisma migration SQL files under `internal-packages/database/prisma/migrations/`, it is acceptable to create indexes with `CREATE INDEX` / `CREATE UNIQUE INDEX` (i.e., without `CONCURRENTLY`) when the parent table is introduced in the same PR and has no existing production rows yet. Only require `CREATE INDEX CONCURRENTLY` (or otherwise account for existing production data/locks) when the table already exists in production with data.
Applied to files:
internal-packages/database/prisma/migrations/20260626140000_drop_bulk_action_item_group_fk/migration.sqlinternal-packages/database/prisma/migrations/20260630120000_drop_project_alert_run_subgraph_foreign_keys/migration.sqlinternal-packages/database/prisma/migrations/20260629120000_drop_run_ops_control_plane_foreign_keys/migration.sqlinternal-packages/database/prisma/migrations/20260626130000_drop_task_run_to_task_run_tag_join/migration.sqlinternal-packages/database/prisma/migrations/20260626150000_drop_batch_task_run_environment_fk/migration.sql
📚 Learning: 2026-03-22T13:26:12.060Z
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev PR: 3244
File: apps/webapp/app/components/code/TextEditor.tsx:81-86
Timestamp: 2026-03-22T13:26:12.060Z
Learning: In the triggerdotdev/trigger.dev codebase, do not flag `navigator.clipboard.writeText(...)` calls for `missing-await`/`unhandled-promise` issues. These clipboard writes are intentionally invoked without `await` and without `catch` handlers across the project; keep that behavior consistent when reviewing TypeScript/TSX files (e.g., usages like in `apps/webapp/app/components/code/TextEditor.tsx`).
Applied to files:
apps/webapp/test/dropTaskRunToTaskRunTagJoin.test.tsinternal-packages/run-store/src/PostgresRunStore.controlPlaneAlertFk.test.tsapps/webapp/test/batchTaskRunEnvironmentFkDrop.test.tsapps/webapp/test/v3/runOpsMigration/runOpsCascadeCleanup.server.test.ts
📚 Learning: 2026-03-22T19:24:14.403Z
Learnt from: matt-aitken
Repo: triggerdotdev/trigger.dev PR: 3187
File: apps/webapp/app/v3/services/alerts/deliverErrorGroupAlert.server.ts:200-204
Timestamp: 2026-03-22T19:24:14.403Z
Learning: In the triggerdotdev/trigger.dev codebase, webhook URLs are not expected to contain embedded credentials/secrets (e.g., fields like `ProjectAlertWebhookProperties` should only hold credential-free webhook endpoints). During code review, if you see logging or inclusion of raw webhook URLs in error messages, do not automatically treat it as a credential-leak/secrets-in-logs issue by default—first verify the URL does not contain embedded credentials (for example, no username/password in the URL, no obvious secret/token query params or fragments). If the URL is credential-free per this project’s conventions, allow the logging.
Applied to files:
apps/webapp/test/dropTaskRunToTaskRunTagJoin.test.tsinternal-packages/run-store/src/PostgresRunStore.controlPlaneAlertFk.test.tsapps/webapp/test/batchTaskRunEnvironmentFkDrop.test.tsapps/webapp/test/v3/runOpsMigration/runOpsCascadeCleanup.server.test.ts
📚 Learning: 2026-05-18T08:21:27.694Z
Learnt from: d-cs
Repo: triggerdotdev/trigger.dev PR: 3632
File: apps/webapp/sentry.server.ts:4-21
Timestamp: 2026-05-18T08:21:27.694Z
Learning: When handling Prisma error P1001 ("Can't reach database server") in TypeScript, don’t assume a single error shape. Prisma can surface P1001 via two different error classes/fields: `PrismaClientKnownRequestError` exposes it as `err.code === "P1001"` (common during mid-query connection drops), while `PrismaClientInitializationError` exposes it as `err.errorCode === "P1001"` (common on client startup failure). Therefore, predicates should use `err.code === "P1001" || err.errorCode === "P1001"`. Do not flag `err.code === "P1001"` as “unreachable/never matches,” as it is expected in production.
Applied to files:
apps/webapp/test/dropTaskRunToTaskRunTagJoin.test.tsinternal-packages/run-store/src/PostgresRunStore.controlPlaneAlertFk.test.tsapps/webapp/test/batchTaskRunEnvironmentFkDrop.test.tsapps/webapp/test/v3/runOpsMigration/runOpsCascadeCleanup.server.test.ts
📚 Learning: 2026-05-18T08:21:27.694Z
Learnt from: d-cs
Repo: triggerdotdev/trigger.dev PR: 3632
File: apps/webapp/sentry.server.ts:4-21
Timestamp: 2026-05-18T08:21:27.694Z
Learning: When handling Prisma errors for P1001 ("Can't reach database server"), do not assume it only appears under a single property name. Prisma may surface P1001 via either `PrismaClientKnownRequestError` (`err.code === "P1001"`, e.g., mid-query connection drops) or `PrismaClientInitializationError` (`err.errorCode === "P1001"`, e.g., client startup connection failure). To reliably detect the condition, check `err.code === "P1001" || err.errorCode === "P1001"`, and avoid review rules that would incorrectly flag `err.code === "P1001"` as unreachable/never-matching.
Applied to files:
apps/webapp/test/dropTaskRunToTaskRunTagJoin.test.tsinternal-packages/run-store/src/PostgresRunStore.controlPlaneAlertFk.test.tsapps/webapp/test/batchTaskRunEnvironmentFkDrop.test.tsapps/webapp/test/v3/runOpsMigration/runOpsCascadeCleanup.server.test.ts
📚 Learning: 2026-06-13T19:53:13.759Z
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev PR: 3937
File: packages/trigger-sdk/skills/realtime-and-frontend/SKILL.md:258-260
Timestamp: 2026-06-13T19:53:13.759Z
Learning: When reviewing code that uses `trigger.dev/react-hooks`’s `useRealtimeRun`, preserve the call signature where the first argument is the full realtime handle object (not `handle.id`). This is intentional to maintain type-safety and is consistent with the official docs; do not suggest changing the first argument from the handle object to `handle.id`.
Applied to files:
apps/webapp/test/dropTaskRunToTaskRunTagJoin.test.tsinternal-packages/run-store/src/PostgresRunStore.controlPlaneAlertFk.test.tsapps/webapp/test/batchTaskRunEnvironmentFkDrop.test.tsapps/webapp/test/v3/runOpsMigration/runOpsCascadeCleanup.server.test.ts
📚 Learning: 2026-06-17T17:13:49.929Z
Learnt from: matt-aitken
Repo: triggerdotdev/trigger.dev PR: 3948
File: apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.bulk-actions.$bulkActionParam/route.tsx:48-62
Timestamp: 2026-06-17T17:13:49.929Z
Learning: In triggerdotdev/trigger.dev, within `dashboardLoader`/`dashboardAction` (or similar context resolver code) whenever you resolve an organization ID from an organization slug for RBAC/enterprise authorization scope, always read from the primary Prisma client (`prisma`), not `$replica`. Using `$replica` can hit replica-lag and cause the RBAC lookup/authorization to run without the correct org scope (bypassing intended role enforcement). Implement the slug→org lookup with `prisma.organization.findFirst(...)` (or equivalent primary-client query) and add an inline comment documenting why the primary client is required (replica lag could lead to unscoped RBAC checks).
Applied to files:
apps/webapp/test/dropTaskRunToTaskRunTagJoin.test.tsinternal-packages/run-store/src/PostgresRunStore.controlPlaneAlertFk.test.tsapps/webapp/test/batchTaskRunEnvironmentFkDrop.test.tsapps/webapp/test/v3/runOpsMigration/runOpsCascadeCleanup.server.test.ts
📚 Learning: 2026-06-23T13:04:21.413Z
Learnt from: carderne
Repo: triggerdotdev/trigger.dev PR: 4023
File: apps/webapp/app/services/upsertBranch.server.ts:14-18
Timestamp: 2026-06-23T13:04:21.413Z
Learning: In TypeScript, it’s valid to `import { type X }` and then use `typeof X` in a type-only position, e.g. `type Alias = z.infer<typeof X>`. The `type` modifier suppresses the runtime import, but the type checker still has the full exported type so `z.infer<typeof X>` can resolve correctly. In code reviews, don’t flag this as a TypeScript compile error as long as `typeof X` is used in a type context (e.g., with `z.infer`, `type` aliases, generics), not as a runtime value.
Applied to files:
apps/webapp/test/dropTaskRunToTaskRunTagJoin.test.tsinternal-packages/run-store/src/PostgresRunStore.controlPlaneAlertFk.test.tsapps/webapp/test/batchTaskRunEnvironmentFkDrop.test.tsapps/webapp/test/v3/runOpsMigration/runOpsCascadeCleanup.server.test.ts
📚 Learning: 2026-05-07T12:25:18.271Z
Learnt from: d-cs
Repo: triggerdotdev/trigger.dev PR: 3531
File: apps/webapp/test/sentryTraceContext.server.test.ts:9-47
Timestamp: 2026-05-07T12:25:18.271Z
Learning: In the triggerdotdev/trigger.dev webapp test suite, it is acceptable to leave `createInMemoryTracing()` calls that register a global `NodeTracerProvider` without `afterEach`/`afterAll` teardown. Do not flag this as a test-ordering risk when the code follows the established pattern used across webapp tests (e.g., replication service/benchmark/backfiller tests). This is considered safe because `trace.getActiveSpan()` when called outside a `context.with(...)` block reads `AsyncLocalStorage.getStore()` (undefined when no `run()` scope exists), so it falls back to `ROOT_CONTEXT` with no attached span—regardless of which provider is registered.
Applied to files:
apps/webapp/test/dropTaskRunToTaskRunTagJoin.test.tsapps/webapp/test/batchTaskRunEnvironmentFkDrop.test.tsapps/webapp/test/v3/runOpsMigration/runOpsCascadeCleanup.server.test.ts
📚 Learning: 2026-05-28T20:02:10.647Z
Learnt from: myftija
Repo: triggerdotdev/trigger.dev PR: 3772
File: apps/webapp/test/findOrCreateBackgroundWorker.test.ts:1-1
Timestamp: 2026-05-28T20:02:10.647Z
Learning: In the triggerdotdev/trigger.dev monorepo, for the `apps/webapp` package use the established convention of storing Vitest tests (unit, integration, and e2e) under `apps/webapp/test/` rather than colocating them next to source files. Do not flag files located in `apps/webapp/test/` as violating any rule that says to colocate tests with source.
Applied to files:
apps/webapp/test/dropTaskRunToTaskRunTagJoin.test.tsapps/webapp/test/batchTaskRunEnvironmentFkDrop.test.tsapps/webapp/test/v3/runOpsMigration/runOpsCascadeCleanup.server.test.ts
📚 Learning: 2026-05-12T21:04:05.815Z
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev PR: 3542
File: apps/webapp/app/components/sessions/v1/SessionStatus.tsx:1-3
Timestamp: 2026-05-12T21:04:05.815Z
Learning: In this Remix + TypeScript codebase, do not flag a server/client boundary violation when a file imports only types from a module matching `*.server`.
Specifically, it’s safe to import types using `import type { Foo } from "*.server"` or `import { type Foo } from "*.server"` because TypeScript erases type-only imports at compile time and they emit no JavaScript, so they won’t cross the Remix server/client bundle boundary.
Only raise the boundary concern for value imports (e.g., `import { Foo }` without `type`, or `import Foo`), since those produce JavaScript output.
Applied to files:
apps/webapp/test/dropTaskRunToTaskRunTagJoin.test.tsapps/webapp/test/batchTaskRunEnvironmentFkDrop.test.tsapps/webapp/test/v3/runOpsMigration/runOpsCascadeCleanup.server.test.ts
📚 Learning: 2026-06-25T18:21:51.905Z
Learnt from: carderne
Repo: triggerdotdev/trigger.dev PR: 4039
File: apps/webapp/app/routes/invite-revoke.tsx:0-0
Timestamp: 2026-06-25T18:21:51.905Z
Learning: During the Zod v4 migration in the triggerdotdev/trigger.dev webapp, ensure any imports from `conform-to/zod` use the Zod-4 subpath: `conform-to/zod/v4` (e.g., `import { parseWithZod } from "conform-to/zod/v4"`). Do not import from the package root `conform-to/zod`, because it is the Zod 3 implementation and may load Zod-3-only symbols (e.g., `ZodBranded`, `ZodEffects`), which can throw at module load (notably with `zod4.4.3`). This should be enforced across `apps/webapp/**/*` where helpers like `parseWithZod` and `conformZodMessage` are used.
Applied to files:
apps/webapp/test/dropTaskRunToTaskRunTagJoin.test.tsapps/webapp/test/batchTaskRunEnvironmentFkDrop.test.tsapps/webapp/test/v3/runOpsMigration/runOpsCascadeCleanup.server.test.ts
📚 Learning: 2026-05-18T14:40:02.173Z
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev PR: 3658
File: packages/core/src/v3/realtimeStreams/manager.test.ts:1-147
Timestamp: 2026-05-18T14:40:02.173Z
Learning: In the triggerdotdev/trigger.dev repo, the policy “Never mock anything — use testcontainers instead” should only be enforced for integration tests that interact with real external services (e.g., Redis, Postgres) via actual infrastructure. For unit tests that exercise pure in-memory logic (e.g., cache semantics) it is OK to stub collaborators such as `ApiClient` using Vitest (`vi.fn()`) to assert call counts or control behavior. Do not flag `vi.fn()`-based `ApiClient` stubs in unit tests as violations of the testcontainers policy.
Applied to files:
apps/webapp/test/dropTaskRunToTaskRunTagJoin.test.tsinternal-packages/run-store/src/PostgresRunStore.controlPlaneAlertFk.test.tsapps/webapp/test/batchTaskRunEnvironmentFkDrop.test.tsapps/webapp/test/v3/runOpsMigration/runOpsCascadeCleanup.server.test.ts
📚 Learning: 2026-06-04T18:16:35.386Z
Learnt from: nicktrn
Repo: triggerdotdev/trigger.dev PR: 3836
File: apps/supervisor/src/backpressure/backpressureMonitor.ts:3-5
Timestamp: 2026-06-04T18:16:35.386Z
Learning: When reviewing TypeScript in this repo, apply the rule “prefer type aliases over interfaces” only to data/object shapes and union/intersection type modeling. If an interface is being used as a behavioral contract for collaborators to implement (e.g., method-shape interfaces that define required behavior, such as `BackpressureLogger` / `BackpressureSignalSource` in `apps/supervisor/src/backpressure/backpressureMonitor.ts`), keep it as an `interface` and do not flag it as a type-alias-vs-interface violation.
Applied to files:
apps/webapp/test/dropTaskRunToTaskRunTagJoin.test.tsinternal-packages/run-store/src/PostgresRunStore.controlPlaneAlertFk.test.tsapps/webapp/test/batchTaskRunEnvironmentFkDrop.test.tsapps/webapp/test/v3/runOpsMigration/runOpsCascadeCleanup.server.test.ts
📚 Learning: 2026-06-09T17:58:04.699Z
Learnt from: 0ski
Repo: triggerdotdev/trigger.dev PR: 3879
File: apps/webapp/app/models/vercelIntegration.server.ts:619-630
Timestamp: 2026-06-09T17:58:04.699Z
Learning: In this codebase, outbound raw `fetch` calls should typically rely on Node/undici’s default request timeout (about ~300s) rather than adding a per-call `AbortController` + `setTimeout` wrapper inside individual functions (e.g. in files like `apps/webapp/app/models/vercelIntegration.server.ts`). During code review, do not flag the absence of a per-call timeout on a single `fetch` as an issue; if per-call timeouts are needed, they should be implemented via a codebase-wide convention (e.g., a shared fetch wrapper or documented pattern) rather than ad-hoc per-function changes.
Applied to files:
apps/webapp/test/dropTaskRunToTaskRunTagJoin.test.tsinternal-packages/run-store/src/PostgresRunStore.controlPlaneAlertFk.test.tsapps/webapp/test/batchTaskRunEnvironmentFkDrop.test.tsapps/webapp/test/v3/runOpsMigration/runOpsCascadeCleanup.server.test.ts
📚 Learning: 2026-06-16T09:19:47.637Z
Learnt from: d-cs
Repo: triggerdotdev/trigger.dev PR: 3960
File: apps/webapp/test/prismaInfrastructureErrorCapture.test.ts:0-0
Timestamp: 2026-06-16T09:19:47.637Z
Learning: In this repo’s Vitest setup, `vitest.config.ts` uses `globals: true`, so identifiers like `vi`, `describe`, `it`, and `expect` are available as globals in Vitest test files. During code review, do not flag missing `vi`/`describe`/`it`/`expect` imports as a runtime error or correctness issue when they’re used in `*.test.ts/tsx` or `*.spec.ts/tsx` files. Explicit imports are still preferred for consistency, but they’re not required for runtime behavior.
Applied to files:
apps/webapp/test/dropTaskRunToTaskRunTagJoin.test.tsinternal-packages/run-store/src/PostgresRunStore.controlPlaneAlertFk.test.tsapps/webapp/test/batchTaskRunEnvironmentFkDrop.test.tsapps/webapp/test/v3/runOpsMigration/runOpsCascadeCleanup.server.test.ts
📚 Learning: 2026-04-30T21:28:35.705Z
Learnt from: samejr
Repo: triggerdotdev/trigger.dev PR: 3473
File: internal-packages/database/prisma/schema.prisma:59-60
Timestamp: 2026-04-30T21:28:35.705Z
Learning: When reviewing Prisma schema files in this repository, do not suggest using Prisma’s `@check` model/table-level attribute or any native Prisma schema syntax for CHECK constraints. Prisma does not implement CHECK constraints (see prisma/prisma#3388). If a CHECK constraint is required, add it only via raw SQL in a handwritten migration (e.g., `ALTER TABLE ... ADD CONSTRAINT ... CHECK (...)`).
Applied to files:
internal-packages/database/prisma/schema.prisma
🔇 Additional comments (12)
apps/webapp/test/batchTaskRunEnvironmentFkDrop.test.ts (1)
1-169: LGTM!apps/webapp/test/dropTaskRunToTaskRunTagJoin.test.ts (1)
8-66: LGTM!internal-packages/run-store/src/PostgresRunStore.controlPlaneAlertFk.test.ts (2)
15-49: LGTM!
105-133: LGTM!internal-packages/database/prisma/schema.prisma (1)
315-402: LGTM!Also applies to: 879-1102, 1863-1936, 2351-2379, 2470-2524, 2544-2569
internal-packages/database/prisma/migrations/20260626130000_drop_task_run_to_task_run_tag_join/migration.sql (1)
1-9: LGTM!internal-packages/database/prisma/migrations/20260626140000_drop_bulk_action_item_group_fk/migration.sql (1)
1-2: 🩺 Stability & Availability | ⚡ Quick winMissing
IF EXISTSbreaks idempotent multi-database rollout.This drop lacks
IF EXISTS, unlike the sibling migrations in this same PR. The later migration explicitly calls out that it mirrors this pattern and addsIF EXISTS"so it's idempotent across both databases," implying this constraint won't exist on one side of the split (or on repeated application) and the statement will error out.🛠️ Proposed fix
-- DropForeignKey -ALTER TABLE "BulkActionItem" DROP CONSTRAINT "BulkActionItem_groupId_fkey"; +ALTER TABLE "BulkActionItem" DROP CONSTRAINT IF EXISTS "BulkActionItem_groupId_fkey";internal-packages/database/prisma/migrations/20260626150000_drop_batch_task_run_environment_fk/migration.sql (1)
1-2: 🩺 Stability & Availability | ⚡ Quick winMissing
IF EXISTSbreaks idempotent multi-database rollout.Same concern as
20260626140000_drop_bulk_action_item_group_fk: this is the exact migration that20260629120000_drop_run_ops_control_plane_foreign_keys's own comment calls out ("Mirrors the earlier TaskRun/BatchTaskRun drops; IF EXISTS so it's idempotent across both databases"), confirming it should have usedIF EXISTStoo.🛠️ Proposed fix
-- DropForeignKey -ALTER TABLE "BatchTaskRun" DROP CONSTRAINT "BatchTaskRun_runtimeEnvironmentId_fkey"; +ALTER TABLE "BatchTaskRun" DROP CONSTRAINT IF EXISTS "BatchTaskRun_runtimeEnvironmentId_fkey";internal-packages/database/prisma/migrations/20260630120000_drop_project_alert_run_subgraph_foreign_keys/migration.sql (1)
1-8: LGTM!apps/webapp/test/v3/runOpsMigration/runOpsCascadeCleanup.server.test.ts (3)
1-8: LGTM!Also applies to: 325-330
462-524: LGTM!Also applies to: 526-559, 561-664
78-107: 🗄️ Data Integrity & IntegrationNo issue here The dedicated run-ops schema already defines
BatchTaskRun.runsand the scalarbackgroundWorkerId/backgroundWorkerTaskId/runtimeEnvironmentId/queueIdfields, so this concern doesn’t apply.> Likely an incorrect or invalid review comment.
@trigger.dev/build
trigger.dev
@trigger.dev/core
@trigger.dev/python
@trigger.dev/react-hooks
@trigger.dev/redis-worker
@trigger.dev/rsc
@trigger.dev/schema-to-json
@trigger.dev/sdk
commit: |
|
On the out-of-diff finding that TaskRunAttempt (backgroundWorker/backgroundWorkerTask/runtimeEnvironment) and TaskRunTag (project) still declare @relation for the FKs dropped in 20260629120000: this is intentional and mirrors TaskRun itself, which keeps its project/runtimeEnvironment relations after its cross-DB FKs were dropped earlier in the series. These relations are never JOINed on the dedicated run-ops DB — the run store strips them from Prisma selects and rehydrates from scalar columns. The BatchTaskRun scalarization was a special case (its relation had no consumers). Prisma-migrate won't re-add these in the managed flow: hand-dropped constraints are an accepted drift condition throughout this schema. Also fixed the one genuine consumer regression flagged inline: PerformBulkActionService now uses scalar groupId queries and reads the action kind from BulkActionItem.type instead of the removed group/items relations. Verified with a green webapp typecheck against a freshly regenerated client. |
3aa59bd to
3276836
Compare
3276836 to
25312fc
Compare
25312fc to
8b6bb5a
Compare
8b6bb5a to
806b7bb
Compare
806b7bb to
1a72386
Compare
1a72386 to
d338e32
Compare
…ps DB, enable split Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…11 activation tests Remove Test A–F enumeration prefixes from the run-ops cascade-cleanup comments and the RED/GREEN TDD framing from the ProjectAlert control-plane FK reconciliation test header. Comment-only; no product logic, test behavior, or migration SQL changed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ion drop The activation schema removed the BulkActionGroup.items and BulkActionItem.group Prisma relations, but PerformBulkActionService still queried them via include, which would fail once the client regenerates. Switch to scalar groupId lookups and read the action kind from BulkActionItem.type. Also drop a stale test comment. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
d338e32 to
af028f7
Compare
What
The activation PR for the run-ops database split. This is the behaviour-changing top of the stack: it drops the cross-database Prisma foreign keys, provisions the dedicated run-ops database, and enables the split.
Schema (
schema.prisma): removes the Prisma relations that span what is now a database boundary —RuntimeEnvironment.batchTaskRuns,TaskRun.tags,TaskRun.alerts,TaskRunTag.runs,TaskRunAttempt.alerts,BatchTaskRun.runtimeEnvironment,BulkActionGroup.items,BulkActionItem.group, and theProjectAlert.taskRun/taskRunAttemptrelations. The underlying scalar id columns are kept; the relationships are resolved through the run store instead of a DB-level FK.ProjectAlertgets a comment explaining why those references are now scalar-only.Migrations: five FK-drop migrations —
drop_task_run_to_task_run_tag_joindrop_bulk_action_item_group_fkdrop_batch_task_run_environment_fkdrop_run_ops_control_plane_foreign_keysdrop_project_alert_run_subgraph_foreign_keysThese remove the cross-subgraph foreign key constraints so run-subgraph rows can live on the dedicated run-ops database.
Enables the split at runtime.
Tests cover the FK drops (
batchTaskRunEnvironmentFkDrop,dropTaskRunToTaskRunTagJoin,PostgresRunStore.controlPlaneAlertFk) and the cascade-cleanup behaviour that the store now owns in place of the dropped DB cascades (runOpsCascadeCleanup).Why
Part of the run-ops database split. This is PR10 of the series (PR8/9/10) and is the one that actually changes behaviour: it flips the split on. It depends on all prior PRs in the series being merged first — the read presenters (PR8) and the route wiring (PR9) must be in place before the split is enabled, or reads and token resolution across the boundary will break.
Note that the FK-drop migrations run regardless of the runtime split flag: dropping the constraints is a schema fact, and the migrations apply on deploy whether or not the split is switched on at runtime. This is intentional — the constraints cannot hold once run-subgraph rows may live on a separate database.
Tests
pnpm run test --filter @internal/database/--filter webappfor the FK-drop and cascade-cleanup suites. The cascade-cleanup suite verifies the store-side deletes that replace the dropped DB-level cascades.Notes
Draft, stacked on #4123 (
runops/pr09-routes). Review that first; this diff is against it.Server-change / changeset note to be added at stack-assembly time.
🤖 Generated with Claude Code