-
-
Notifications
You must be signed in to change notification settings - Fork 707
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
[DOCS]: Index creation docs unclear #3851
Comments
I agree it is a confusing and the syntax I use and seems to work fine on the latest version of drizzle (0.38.3 & drizzle-kit 0.30.1) is: const userModel = pgTable(
'user',
{
id: uuid('id').primaryKey().defaultRandom().notNull(),
firstName: varchar('first_name').notNull(),
lastName: varchar('last_name').notNull(),
email: varchar('email').unique().notNull(),
hash: varchar('hash').notNull(),
roleId: uuid('role_id')
.references(
() => {
return roleModel.id;
},
{ onDelete: 'no action', onUpdate: 'cascade' },
)
.notNull(),
...timestamps,
},
(table) => {
// The relevant part
return [
uniqueIndex('user_email_unique_index').using('btree', table.email.asc()),
index('user_role_id_index').using('btree', table.roleId.asc()),
uniqueIndex('user_cursor_unique_index').using(
'btree',
table.id.asc(),
table.createdAt.asc(),
),
];
},
); Basically you need to return an array with the relevant indexes. CREATE UNIQUE INDEX "user_email_unique_index" ON "user" USING btree ("email");--> statement-breakpoint
CREATE INDEX "user_role_id_index" ON "user" USING btree ("role_id");--> statement-breakpoint
CREATE UNIQUE INDEX "user_cursor_unique_index" ON "user" USING btree ("id","created_at"); As a side note, I agree it may be beneficial to add an example with the new syntax |
Thank you. I had figured it out for the standard index, but I had it wrong for uniqueIndex for the table below and didn't even realize it (there was no error). Your example helped me fix it. Note: it seems 'return' is no longer necessary. Here's what I ended up with:
|
Glad to here you resolved it, with or without my help. |
Enhancement hasn't been filed before.
Describe the enhancement you want to request
The docs here are unclear. If I use the syntax first described, I get a 'deprecated' warning. The second description below, which it states it the new syntax, does not include what should surround it (obviously these lines should not be on the top level).
I'm going with the deprecated version for now as I don't know how to use the new format based on the current docs. If anyone knows how this should be done I'd greatly appreciate the help.
The text was updated successfully, but these errors were encountered: