mirror of
https://github.com/better-auth/better-auth.git
synced 2026-06-01 03:46:39 -05:00
cli(fix): add bigint type to generators (#1217)
This commit is contained in:
@@ -18,8 +18,14 @@ export const generateDrizzleSchema: SchemaGenerator = async ({
|
||||
const timestampAndBoolean =
|
||||
databaseType !== "sqlite" ? "timestamp, boolean" : "";
|
||||
const int = databaseType === "mysql" ? "int" : "integer";
|
||||
const hasBigint = Object.values(tables).some((table) =>
|
||||
Object.values(table.fields).some((field) => field.bigint),
|
||||
);
|
||||
const bigint = databaseType !== "sqlite" ? "bigint" : "";
|
||||
const text = databaseType === "mysql" ? "varchar, text" : "text";
|
||||
let code = `import { ${databaseType}Table, ${text}, ${int}, ${timestampAndBoolean} } from "drizzle-orm/${databaseType}-core";
|
||||
let code = `import { ${databaseType}Table, ${text}, ${int}${hasBigint ?
|
||||
`, ${bigint}` : ""
|
||||
}, ${timestampAndBoolean} } from "drizzle-orm/${databaseType}-core";
|
||||
`;
|
||||
|
||||
const fileExist = existsSync(filePath);
|
||||
@@ -49,8 +55,8 @@ export const generateDrizzleSchema: SchemaGenerator = async ({
|
||||
},
|
||||
number: {
|
||||
sqlite: `integer('${name}')`,
|
||||
pg: `integer('${name}')`,
|
||||
mysql: `int('${name}')`,
|
||||
pg: field.bigint ? `bigint('${name}', { mode: 'number' })` : `integer('${name}')`,
|
||||
mysql: field.bigint ? `bigint('${name}', { mode: 'number' })` : `int('${name}')`,
|
||||
},
|
||||
date: {
|
||||
sqlite: `integer('${name}', { mode: 'timestamp' })`,
|
||||
|
||||
@@ -51,10 +51,13 @@ export const generatePrismaSchema: SchemaGenerator = async ({
|
||||
const originalTable = tables[table]?.modelName;
|
||||
const modelName = capitalizeFirstLetter(originalTable || "");
|
||||
|
||||
function getType(type: FieldType, isOptional: boolean) {
|
||||
function getType(type: FieldType, isOptional: boolean, isBigint: boolean) {
|
||||
if (type === "string") {
|
||||
return isOptional ? "String?" : "String";
|
||||
}
|
||||
if (type === "number" && isBigint) {
|
||||
return isOptional ? "BigInt?" : "BigInt";
|
||||
}
|
||||
if (type === "number") {
|
||||
return isOptional ? "Int?" : "Int";
|
||||
}
|
||||
@@ -103,7 +106,7 @@ export const generatePrismaSchema: SchemaGenerator = async ({
|
||||
|
||||
builder
|
||||
.model(modelName)
|
||||
.field(field, getType(attr.type, !attr?.required));
|
||||
.field(field, getType(attr.type, !attr?.required, attr?.bigint || false));
|
||||
if (attr.unique) {
|
||||
builder.model(modelName).blockAttribute(`unique([${field}])`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user