mirror of
https://github.com/better-auth/better-auth.git
synced 2026-08-01 10:50:40 -05:00
fix(cli): clean up unused pg and mysql import in drizzle schema generator (#3974)
* fix(cli): clean up unused pg import in schema generator * sql clean up * clean up
This commit is contained in:
@@ -211,7 +211,43 @@ function generateImport({
|
||||
);
|
||||
imports.push(hasBigint ? (databaseType !== "sqlite" ? "bigint" : "") : "");
|
||||
imports.push(databaseType !== "sqlite" ? "timestamp, boolean" : "");
|
||||
imports.push(databaseType === "mysql" ? "int" : "integer");
|
||||
if (databaseType === "mysql") {
|
||||
// Only include int for MySQL if actually needed
|
||||
const hasNonBigintNumber = Object.values(tables).some((table) =>
|
||||
Object.values(table.fields).some(
|
||||
(field) =>
|
||||
(field.type === "number" || field.type === "number[]") &&
|
||||
!field.bigint,
|
||||
),
|
||||
);
|
||||
const needsInt = !!useNumberId || hasNonBigintNumber;
|
||||
if (needsInt) {
|
||||
imports.push("int");
|
||||
}
|
||||
} else if (databaseType === "pg") {
|
||||
// Only include integer for PG if actually needed
|
||||
const hasNonBigintNumber = Object.values(tables).some((table) =>
|
||||
Object.values(table.fields).some(
|
||||
(field) =>
|
||||
(field.type === "number" || field.type === "number[]") &&
|
||||
!field.bigint,
|
||||
),
|
||||
);
|
||||
const hasFkToId = Object.values(tables).some((table) =>
|
||||
Object.values(table.fields).some(
|
||||
(field) => field.references?.field === "id",
|
||||
),
|
||||
);
|
||||
// handles the references field with useNumberId
|
||||
const needsInteger =
|
||||
hasNonBigintNumber ||
|
||||
(options.advanced?.database?.useNumberId && hasFkToId);
|
||||
if (needsInteger) {
|
||||
imports.push("integer");
|
||||
}
|
||||
} else {
|
||||
imports.push("integer");
|
||||
}
|
||||
imports.push(useNumberId ? (databaseType === "pg" ? "serial" : "") : "");
|
||||
|
||||
return `import { ${imports
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
import {
|
||||
pgTable,
|
||||
text,
|
||||
timestamp,
|
||||
boolean,
|
||||
integer,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { pgTable, text, timestamp, boolean } from "drizzle-orm/pg-core";
|
||||
|
||||
export const user = pgTable("user", {
|
||||
id: text("id").primaryKey(),
|
||||
|
||||
@@ -166,7 +166,6 @@ describe("generate", async () => {
|
||||
plugins: [twoFactor(), username()],
|
||||
},
|
||||
});
|
||||
console.log(schema.code);
|
||||
expect(schema.code).toMatchFileSnapshot("./__snapshots__/auth-schema.txt");
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user