Kevintyj
Kevintyj
Explore posts from servers
DTDrizzle Team
Created by Kevintyj on 4/8/2025 in #help
Fixes for composite PK?
https://github.com/drizzle-team/drizzle-orm/issues/3383 Referencing this issue, using composite primary keys like the author here with errno: 1553 on subsequent pushes, took a look at the migration code that was generated and it seems like its not dropping the foreign key constraints and drop and recreating the primary key. Tried using pnpm patch to patch drizzle with the suggested fix here: https://github.com/drizzle-team/drizzle-orm/issues/1428#issuecomment-1916722940 but it did not fix the issue as I am using named primary keys. Cannot seem for the life of me get this to work. Do I have to manually create migrations and fix such issues or what is the proposed solution? Seems like using composite primary keys is one of the most used SQL features and donno why more people haven't ran into this issue. Would love to see if anybody has fixses for the issue?
2 replies
BABetter Auth
Created by Kevintyj on 3/27/2025 in #help
Infer additional fields for admin?
Is admin not able to infer types for additional fields like so when the types come from a plugin? I have added the InferTypes on the client plugin.
await admin.createUser({
name,
email,
password,
role: 'admin',
status, // causes type error?
});
await admin.createUser({
name,
email,
password,
role: 'admin',
status, // causes type error?
});
type UserStatusPlugin = typeof userStatusPlugin;

export const userStatusClientPlugin = () => {
return {
id: 'userStatusPlugin',
$InferServerPlugin: {} as ReturnType<UserStatusPlugin>,
} satisfies BetterAuthClientPlugin;
};
type UserStatusPlugin = typeof userStatusPlugin;

export const userStatusClientPlugin = () => {
return {
id: 'userStatusPlugin',
$InferServerPlugin: {} as ReturnType<UserStatusPlugin>,
} satisfies BetterAuthClientPlugin;
};
export const {
signIn,
signUp,
signOut,
useSession,
emailOtp,
admin,
} = createAuthClient({
plugins: [
usernameClient(),
adminClient({
ac,
roles: {
user: userRole,
doctor: doctorRole,
nurse: nurseRole,
admin: adminRole,
},
}),
emailOTPClient(),
userStatusClientPlugin(),
inferAdditionalFields<typeof auth>(),
],
});
export const {
signIn,
signUp,
signOut,
useSession,
emailOtp,
admin,
} = createAuthClient({
plugins: [
usernameClient(),
adminClient({
ac,
roles: {
user: userRole,
doctor: doctorRole,
nurse: nurseRole,
admin: adminRole,
},
}),
emailOTPClient(),
userStatusClientPlugin(),
inferAdditionalFields<typeof auth>(),
],
});
5 replies
DTDrizzle Team
Created by Kevintyj on 3/25/2025 in #help
Relationships not working? (Simplest one-one relationship)
I can't seem to have Drizzle return the correct query when using the relationship syntax. I have the following relationship defined: user-schema.ts
export const manager = mysqlTable('manager', {
userId: varchar('user_id', { length: 36 }).notNull().references(() => user.id, { onDelete: 'cascade' }),
});
export const manager = mysqlTable('manager', {
userId: varchar('user_id', { length: 36 }).notNull().references(() => user.id, { onDelete: 'cascade' }),
});
auth-schema.ts
export const user = mysqlTable('user', {
id: varchar('id', { length: 36 }).primaryKey(),
export const user = mysqlTable('user', {
id: varchar('id', { length: 36 }).primaryKey(),
relationship-schema.ts
export const userRelations = relations(user, ({ one }) => ({
manager: one(manager, {
fields: [user.id],
references: [manager.userId],
}),
}));
export const userRelations = relations(user, ({ one }) => ({
manager: one(manager, {
fields: [user.id],
references: [manager.userId],
}),
}));
but however when I query:
await db.query.user.findMany({
with: {
manager: true,
},
});
await db.query.user.findMany({
with: {
manager: true,
},
});
It returns users with no managers associated. Am I doing something wrong here? First time using drizzle! Tysm ❤️
1 replies