DT
Drizzle Teamโ€ข3d ago
Noita

unique constraint does not seem to be applying as intended.

export const PlayerDiscordCacheTable = pgTable(
`tal_player_discord_cache_table`,
{
id: uuid().defaultRandom().primaryKey(),

playerRef: uuid("player_ref"),

discordRoleIds: text("discord_role_ids").array().default([]),

discordUserName: text("discord_user_name").notNull(),
discordUserId: text("discord_user_id").notNull(),
discordServerId: text("discord_server_id").notNull(),
},
(table) => ({
uniqueServerAndUser: unique("unique_server_and_user").on(
table.discordServerId,
table.discordUserId
)
})
);
export const PlayerDiscordCacheTable = pgTable(
`tal_player_discord_cache_table`,
{
id: uuid().defaultRandom().primaryKey(),

playerRef: uuid("player_ref"),

discordRoleIds: text("discord_role_ids").array().default([]),

discordUserName: text("discord_user_name").notNull(),
discordUserId: text("discord_user_id").notNull(),
discordServerId: text("discord_server_id").notNull(),
},
(table) => ({
uniqueServerAndUser: unique("unique_server_and_user").on(
table.discordServerId,
table.discordUserId
)
})
);
PostgresError: could not create unique index "unique_server_and_user" code: "23505" I also tried with
unique("unique_server_and_user").on(
PlayerDiscordCacheTable.discordServerId,
PlayerDiscordCacheTable.discordUserId
);
unique("unique_server_and_user").on(
PlayerDiscordCacheTable.discordServerId,
PlayerDiscordCacheTable.discordUserId
);
and generate does not seem to see it at all, reporting No schema changes, nothing to migrate :sleeping:. Please let me know if there is any more information I can provide to assist with assitance ๐Ÿ™‚ Thanks!
3 Replies
elitenoire
elitenoireโ€ข3d ago
Follow the way the release notes suggest in https://github.com/drizzle-team/drizzle-orm/releases/tag/0.36.0
GitHub
Release 0.36.0 ยท drizzle-team/drizzle-orm
This version of drizzle-orm requires [email protected] to enable all new features New Features The third parameter in Drizzle ORM becomes an array The object API is still available but deprecate...
elitenoire
elitenoireโ€ข3d ago
No need for object notation and just pass the unique function in the array
Noita
NoitaOPโ€ข2d ago
Hello and thank you for your assistance. I resolved the issue (and forgot to post about it, oops) by regenerating my migrations. I hadn't used drizzle in a while and forgot about the push command workflow for local development as opposed to migrating each change, so I'll likely start over with that approach as well as the one you've sent over. Thanks again!!

Did you find this page helpful?