fix(drizzle): it should use text for id fields other than mysql (#719)

This commit is contained in:
Bereket Engida
2024-12-02 12:26:43 +03:00
committed by GitHub
parent 894f65a00d
commit 0aaa573a32
2 changed files with 10 additions and 6 deletions

View File

@@ -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];

View File

@@ -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)