Skip to content

Commit 19831fc

Browse files
committed
Add index on user.email column
- Add btree index 'users_email_idx' to improve query performance - Query pattern: SELECT * FROM user WHERE email = '[email protected]' - Index will significantly reduce lookup time for email-based queries - Compatible with existing unique constraint on email column
1 parent f441f28 commit 19831fc

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

packages/db/src/drizzle/schema.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,13 @@ export const user = pgTable(
328328
role: role().default('USER').notNull(),
329329
twoFactorEnabled: boolean('two_factor_enabled'),
330330
},
331-
(table) => [unique('users_email_unique').on(table.email)]
331+
(table) => [
332+
unique('users_email_unique').on(table.email),
333+
index('users_email_idx').using(
334+
'btree',
335+
table.email.asc().nullsLast().op('text_ops')
336+
),
337+
]
332338
);
333339

334340
export const userStripeConfig = pgTable(

0 commit comments

Comments
 (0)