Skip to content

Conversation

oscartbeaumont
Copy link
Member

@oscartbeaumont oscartbeaumont commented Oct 6, 2025

This will be merged once the backfill has been run to make orgId required. This should be merged after the backfill and Planetscale PR have been merged.

https://app.planetscale.com/cap/cap-production/deploy-requests/39

Summary by CodeRabbit

  • Bug Fixes

    • Prevents orphaned videos by requiring every video to be linked to an organization, reducing listing and permission issues.
  • Chores

    • Database and backend now enforce and propagate a required organization ID for videos, tightening validation and surfacing clearer errors during creation or import.

Copy link
Contributor

coderabbitai bot commented Oct 6, 2025

Walkthrough

Made orgId required across the stack: added a nanoIdRequired helper and changed the videos table, domain Video type, repo storage, and import flow to use a non-optional orgId (removed Option wrapping).

Changes

Cohort / File(s) Summary of Changes
Database schema
packages/database/schema.ts
Added nanoIdRequired(name) helper; changed videos.orgId from nullable to non-null (nanoIdNullable("orgId")nanoIdRequired("orgId")); added TODO about future replacement.
Domain model
packages/web-domain/src/Video.ts
Video.orgId changed from optional (OptionFromNullOr(String)) to required String.
Backend import flow
packages/web-backend/src/Loom/ImportVideo.ts
Stopped wrapping payload.cap.orgId with Option.some; now passes payload.cap.orgId directly when creating videos.
Repository / persistence
packages/web-backend/src/Videos/VideosRepo.ts
Store orgId as data.orgId (direct string) instead of extracting from Option; removed condition that required Option.isSome(data.orgId) for importedVideos insert.

Sequence Diagram(s)

sequenceDiagram
    participant Import as ImportVideo
    participant Repo as VideosRepo
    participant DB as Database

    rect rgba(135,206,250,0.12)
    Note over Import,Repo: New flow passes required orgId (string)
    Import->>Repo: createVideo({ ..., orgId: payload.cap.orgId })
    Repo->>DB: insert videos (orgId: data.orgId)
    DB-->>Repo: inserted row
    Repo-->>Import: created video
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

Poem

I hop and nibble on a line,
Tightening threads of schema fine.
No optional gaps in orgId's root,
A tidy field, a steady route.
Hooray — a carrot-coded suit! 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title clearly and concisely conveys the main change, namely the cleanup tasks performed after making the orgId field on the videos table required through a backfill. It references the specific context of the backfill without overloading with implementation details, making it easy to understand at a glance. This phrasing aligns well with the summarized code modifications and the overall PR objective.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ 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 post-orgid-backfill

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
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)
packages/database/schema.ts (1)

503-514: Consider adding a relation for orgId.

The videosRelations define relations for owner (ownerId) and folder (folderId), but not for the newly required orgId field. If videos belong to organizations, adding this relation would improve type safety and enable easier joins.

Add the following relation:

 export const videosRelations = relations(videos, ({ one, many }) => ({
 	owner: one(users, {
 		fields: [videos.ownerId],
 		references: [users.id],
 	}),
+	organization: one(organizations, {
+		fields: [videos.orgId],
+		references: [organizations.id],
+	}),
 	sharedVideos: many(sharedVideos),
 	spaceVideos: many(spaceVideos),
 	folder: one(folders, {
 		fields: [videos.folderId],
 		references: [folders.id],
 	}),
 }));
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c9be241 and 4ab7441.

📒 Files selected for processing (1)
  • packages/database/schema.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx,js,jsx,rs}

📄 CodeRabbit inference engine (CLAUDE.md)

Do not add inline, block, or docstring comments in any language; code must be self-explanatory

Files:

  • packages/database/schema.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Use strict TypeScript and avoid any; leverage shared types from packages

**/*.{ts,tsx}: Use a 2-space indent for TypeScript code.
Use Biome for formatting and linting TypeScript/JavaScript files by running pnpm format.

Files:

  • packages/database/schema.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx,js,jsx}: Use kebab-case for filenames for TypeScript/JavaScript modules (e.g., user-menu.tsx).
Use PascalCase for React/Solid components.

Files:

  • packages/database/schema.ts
🧬 Code graph analysis (1)
packages/database/schema.ts (1)
packages/database/helpers.ts (1)
  • nanoId (6-9)
⏰ 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). (3)
  • GitHub Check: Build Desktop (aarch64-apple-darwin, macos-latest)
  • GitHub Check: Build Desktop (x86_64-pc-windows-msvc, windows-latest)
  • GitHub Check: Analyze (rust)
🔇 Additional comments (1)
packages/database/schema.ts (1)

250-250: Ensure orgId backfill completed before merging
The schema now enforces videos.orgId as non-null. Before deploying, run:

SELECT COUNT(*) FROM videos WHERE orgId IS NULL;

and confirm it returns 0 to avoid runtime errors.

Copy link
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: 0

🧹 Nitpick comments (1)
packages/database/schema.ts (1)

670-670: Replace nanoIdNullable("orgId").notNull() with nanoIdRequired("orgId") in imported_videos schema for consistency

-       orgId: nanoIdNullable("orgId").notNull(),
+       orgId: nanoIdRequired("orgId"),
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4ab7441 and 5da51ae.

📒 Files selected for processing (4)
  • packages/database/schema.ts (2 hunks)
  • packages/web-backend/src/Loom/ImportVideo.ts (1 hunks)
  • packages/web-backend/src/Videos/VideosRepo.ts (2 hunks)
  • packages/web-domain/src/Video.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx,js,jsx,rs}

📄 CodeRabbit inference engine (CLAUDE.md)

Do not add inline, block, or docstring comments in any language; code must be self-explanatory

Files:

  • packages/web-domain/src/Video.ts
  • packages/web-backend/src/Videos/VideosRepo.ts
  • packages/web-backend/src/Loom/ImportVideo.ts
  • packages/database/schema.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Use strict TypeScript and avoid any; leverage shared types from packages

**/*.{ts,tsx}: Use a 2-space indent for TypeScript code.
Use Biome for formatting and linting TypeScript/JavaScript files by running pnpm format.

Files:

  • packages/web-domain/src/Video.ts
  • packages/web-backend/src/Videos/VideosRepo.ts
  • packages/web-backend/src/Loom/ImportVideo.ts
  • packages/database/schema.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx,js,jsx}: Use kebab-case for filenames for TypeScript/JavaScript modules (e.g., user-menu.tsx).
Use PascalCase for React/Solid components.

Files:

  • packages/web-domain/src/Video.ts
  • packages/web-backend/src/Videos/VideosRepo.ts
  • packages/web-backend/src/Loom/ImportVideo.ts
  • packages/database/schema.ts
🧬 Code graph analysis (1)
packages/database/schema.ts (1)
packages/database/helpers.ts (1)
  • nanoIdLength (3-3)
⏰ 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). (3)
  • GitHub Check: Build Desktop (x86_64-pc-windows-msvc, windows-latest)
  • GitHub Check: Build Desktop (aarch64-apple-darwin, macos-latest)
  • GitHub Check: Analyze (rust)
🔇 Additional comments (5)
packages/web-backend/src/Videos/VideosRepo.ts (1)

61-61: LGTM! Clean removal of Option wrapping.

The changes correctly reflect the now-required orgId field by using direct value access instead of Option unwrapping. The simplified import condition at line 75 (removing the Option.isSome(data.orgId) check) is appropriate since orgId is now guaranteed to be present.

Also applies to: 75-80

packages/web-domain/src/Video.ts (1)

17-17: LGTM! Domain model correctly reflects required orgId.

Changing from optional to required string aligns with the database schema change and ensures type safety across the stack.

packages/web-backend/src/Loom/ImportVideo.ts (1)

73-73: LGTM! Correctly passes direct orgId value.

The removal of the Option wrapper is consistent with the required orgId field in the domain model and repository layer.

packages/database/schema.ts (2)

27-29: Well-designed helper for required nanoId fields.

The nanoIdRequired helper explicitly chains .notNull(), ensuring the database constraint is properly enforced. This is clearer and more maintainable than relying on the type-level notNull: true in the nanoId definition.


253-253: LGTM! Consistent use of nanoIdRequired.

The change from nullable to required aligns with the backfill and domain model updates. Using the new nanoIdRequired helper ensures the NOT NULL constraint is properly set.

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.

1 participant