Skip to content

⚡️ Add and update database indexes #1778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 15, 2025
Merged

⚡️ Add and update database indexes #1778

merged 1 commit into from
Jun 15, 2025

Conversation

lukevella
Copy link
Owner

@lukevella lukevella commented Jun 15, 2025

Summary by CodeRabbit

  • Chores
    • Updated database indexing strategies to use hash indexes on several fields, potentially improving lookup performance for polls, scheduled events, spaces, and subscriptions.
    • Removed some existing indexes and added new hash-based indexes on relevant columns for better query efficiency.

Copy link

vercel bot commented Jun 15, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 15, 2025 11:55am
landing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 15, 2025 11:55am

Copy link
Contributor

coderabbitai bot commented Jun 15, 2025

Walkthrough

This update modifies the Prisma schema and corresponding SQL migration to add or change hash-based indexes on several tables and fields, including polls, scheduled events, spaces, and subscriptions. It also removes certain guest ID indexes from participant and comment models, focusing on optimizing lookup performance for key reference columns.

Changes

Files/Paths Change Summary
.../prisma/migrations/20250615114214_update_indexes/migration.sql Drops old indexes; adds hash indexes to polls, scheduled_events, spaces, subscriptions tables.
.../prisma/models/billing.prisma Adds hash indexes on userId and spaceId fields in Subscription model.
.../prisma/models/event.prisma Adds hash indexes on spaceId and userId fields in ScheduledEvent model.
.../prisma/models/poll.prisma Changes guestId index to hash, adds hash indexes on spaceId and userId in Poll; removes guestId hash indexes from Participant and Comment.
.../prisma/models/user.prisma Adds hash index on ownerId field in Space model.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant PrismaLayer
    participant Database

    Client->>PrismaLayer: Query by userId/spaceId/ownerId
    PrismaLayer->>Database: Use HASH index for lookup
    Database-->>PrismaLayer: Return optimized results
    PrismaLayer-->>Client: Return queried data
Loading

Poem

In the warren of data, swift and bright,
Hashy tunnels now speed up the night.
Indexes pruned, some new ones in bloom,
Queries now zip with much less room.
A hop, a skip—oh, what a delight!
The database dances, the rabbits write.
🐇✨

✨ Finishing Touches
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch add-indexes
  • Post Copyable Unit Tests in Comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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/prisma/migrations/20250615114214_update_indexes/migration.sql (1)

1-33: Enhance migration safety and minimize downtime.

  • Use DROP INDEX IF EXISTS to avoid errors on re-runs.
  • Consider wrapping operations in a transaction or using CREATE INDEX CONCURRENTLY to reduce lock contention during index creation.
BEGIN;
DROP INDEX IF EXISTS "comments_guest_id_idx";
--
CREATE INDEX CONCURRENTLY "polls_guest_id_idx" ON "polls" USING HASH ("guest_id");
--
COMMIT;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 04fcc03 and c33599e.

📒 Files selected for processing (5)
  • packages/database/prisma/migrations/20250615114214_update_indexes/migration.sql (1 hunks)
  • packages/database/prisma/models/billing.prisma (1 hunks)
  • packages/database/prisma/models/event.prisma (1 hunks)
  • packages/database/prisma/models/poll.prisma (1 hunks)
  • packages/database/prisma/models/user.prisma (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Integration tests
🔇 Additional comments (4)
packages/database/prisma/models/user.prisma (1)

82-82: Confirm index compatibility with your database provider.
Prisma’s @@index([ownerId], type: Hash) is only supported on PostgreSQL. Ensure your provider in schema.prisma is set to Postgres and that the generated migration SQL aligns with this new hash index.

packages/database/prisma/models/billing.prisma (1)

13-20: Avoid duplicate indexing on userId and spaceId.
The field-level @unique on userId and spaceId creates B-tree unique indexes, and the added @@index(..., type: Hash) definitions introduce separate hash indexes on the same columns. If you intend unique hash indexes, switch to model-level @@unique([userId], type: Hash) / @@unique([spaceId], type: Hash) and remove the field-level @unique. Otherwise, drop the extra hash indexes to prevent redundant index maintenance.

packages/database/prisma/models/event.prisma (1)

40-41: Appropriate addition of hash indexes for ScheduledEvent.
Adding hash indexes on spaceId and userId aligns with expected lookup patterns on these foreign keys. Ensure the migration SQL uses matching index names (scheduled_events_space_id_idx, scheduled_events_user_id_idx).

packages/database/prisma/models/poll.prisma (1)

52-54: Verify index updates on Poll and related models.
You’ve converted the guestId index to hash and added hash indexes for spaceId and userId on Poll, while removing guestId indexes from Participant and Comment. Confirm that the Prisma schema, migration DROP INDEX/CREATE INDEX names (e.g., polls_guest_id_idx), and actual database state remain synchronized.

@lukevella lukevella merged commit 87ab118 into main Jun 15, 2025
15 of 16 checks passed
@lukevella lukevella deleted the add-indexes branch June 15, 2025 11:58
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