mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-25 08:31:37 -05:00
fix(drizzle): it should use text for id fields other than mysql (#719)
This commit is contained in:
@@ -55,8 +55,12 @@ export const generateDrizzleSchema: SchemaGenerator = async ({
|
||||
} as const;
|
||||
return typeMap[type as "boolean"][(databaseType as "sqlite") || "sqlite"];
|
||||
}
|
||||
const id =
|
||||
databaseType === "mysql"
|
||||
? `varchar("id", { length: 36 }).primaryKey()`
|
||||
: `text("id").primaryKey()`;
|
||||
const schema = `export const ${modelName} = ${databaseType}Table("${modelName}", {
|
||||
id: varchar("id", { length: 36 }).primaryKey(),
|
||||
id: ${id},
|
||||
${Object.keys(fields)
|
||||
.map((field) => {
|
||||
const attr = fields[field];
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { pgTable, text, integer, timestamp, boolean } from "drizzle-orm/pg-core";
|
||||
|
||||
export const user = pgTable("user", {
|
||||
id: varchar("id", { length: 36 }).primaryKey(),
|
||||
id: text("id").primaryKey(),
|
||||
name: text('name').notNull(),
|
||||
email: text('email').notNull().unique(),
|
||||
emailVerified: boolean('emailVerified').notNull(),
|
||||
@@ -13,7 +13,7 @@ export const user = pgTable("user", {
|
||||
});
|
||||
|
||||
export const session = pgTable("session", {
|
||||
id: varchar("id", { length: 36 }).primaryKey(),
|
||||
id: text("id").primaryKey(),
|
||||
expiresAt: timestamp('expiresAt').notNull(),
|
||||
token: text('token').notNull().unique(),
|
||||
createdAt: timestamp('createdAt').notNull(),
|
||||
@@ -24,7 +24,7 @@ export const session = pgTable("session", {
|
||||
});
|
||||
|
||||
export const account = pgTable("account", {
|
||||
id: varchar("id", { length: 36 }).primaryKey(),
|
||||
id: text("id").primaryKey(),
|
||||
accountId: text('accountId').notNull(),
|
||||
providerId: text('providerId').notNull(),
|
||||
userId: text('userId').notNull().references(()=> user.id),
|
||||
@@ -40,7 +40,7 @@ export const account = pgTable("account", {
|
||||
});
|
||||
|
||||
export const verification = pgTable("verification", {
|
||||
id: varchar("id", { length: 36 }).primaryKey(),
|
||||
id: text("id").primaryKey(),
|
||||
identifier: text('identifier').notNull(),
|
||||
value: text('value').notNull(),
|
||||
expiresAt: timestamp('expiresAt').notNull(),
|
||||
@@ -49,7 +49,7 @@ export const verification = pgTable("verification", {
|
||||
});
|
||||
|
||||
export const twoFactor = pgTable("twoFactor", {
|
||||
id: varchar("id", { length: 36 }).primaryKey(),
|
||||
id: text("id").primaryKey(),
|
||||
secret: text('secret').notNull(),
|
||||
backupCodes: text('backupCodes').notNull(),
|
||||
userId: text('userId').notNull().references(()=> user.id)
|
||||
|
||||
Reference in New Issue
Block a user