-
-
Notifications
You must be signed in to change notification settings - Fork 439
⚡️ 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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThis 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
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
Poem
✨ Finishing Touches🧪 Generate Unit Tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
📒 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 yourprovider
inschema.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 onuserId
andspaceId
.
The field-level@unique
onuserId
andspaceId
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 onspaceId
anduserId
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 theguestId
index to hash and added hash indexes forspaceId
anduserId
onPoll
, while removingguestId
indexes fromParticipant
andComment
. Confirm that the Prisma schema, migrationDROP INDEX
/CREATE INDEX
names (e.g.,polls_guest_id_idx
), and actual database state remain synchronized.
Summary by CodeRabbit