Paddy
Paddy
Explore posts from servers
DTDrizzle Team
Created by Paddy on 3/6/2024 in #help
Make two columns unique (composite primary key)
Hey everyone, I need to make the provider_id and provider_user_id to be unique together (composite primary key). After migration it returns that it is not allowed to have multiple primary keys. But it does seem to be the way Drizzle ORM want it to work, I think. Anyone in here that encountered this before with TypeScript, Drizzle ORM?
export const oauthAccount = pgTable(
'oath_account',
{
provider_id: text('provider_id').notNull(),
provider_user_id: text('provider_user_id').notNull(),
user_id: text('user_id')
.notNull()
.references(() => users.id),
},
(table) => {
return {
pk: primaryKey({
columns: [table.provider_id, table.provider_user_id],
}),
};
}
);
export const oauthAccount = pgTable(
'oath_account',
{
provider_id: text('provider_id').notNull(),
provider_user_id: text('provider_user_id').notNull(),
user_id: text('user_id')
.notNull()
.references(() => users.id),
},
(table) => {
return {
pk: primaryKey({
columns: [table.provider_id, table.provider_user_id],
}),
};
}
);
Thank you in advance!
2 replies
DTDrizzle Team
Created by Paddy on 3/5/2024 in #help
Drizzle-kit: Uncomment code below and paste pk name manually?
No description
1 replies
DTDrizzle Team
Created by Paddy on 3/4/2024 in #help
Composite primary key, multiple primary keys
I am following the Lucia-auth docs for multiple oauth providers, it's says: PRIMARY KEY (provider_id, provider_user_id) as shown here: https://lucia-auth.com/guides/oauth/multiple-providers I am using Postgres with TypeScript so I made it like this, instead of the SQLite example they use.
export const oauthAccount = pgTable(
'oath_account',
{
provider_id: text('provider_id').notNull(),
provider_user_id: text('provider_user_id').notNull(),
user_id: text('user_id')
.notNull()
.references(() => users.id),
},
(table) => {
return {
pk: primaryKey({
columns: [table.provider_id, table.provider_user_id],
}),
};
}
);
export const oauthAccount = pgTable(
'oath_account',
{
provider_id: text('provider_id').notNull(),
provider_user_id: text('provider_user_id').notNull(),
user_id: text('user_id')
.notNull()
.references(() => users.id),
},
(table) => {
return {
pk: primaryKey({
columns: [table.provider_id, table.provider_user_id],
}),
};
}
);
Its returning in the terminal: multiple primary keys for table "oath_account" are not allowed.. But in the docs it shows I need it, right, what am I doing wrong? Thanks in advance.
4 replies