mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-10 04:19:32 +00:00
feat: add onUpdate field on db schema generation (#4241)
Fixes: https://github.com/better-auth/better-auth/issues/4187
This commit is contained in:
169
packages/cli/test/generate-all-db.test.ts
Normal file
169
packages/cli/test/generate-all-db.test.ts
Normal file
@@ -0,0 +1,169 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { generateDrizzleSchema } from "../src/generators/drizzle";
|
||||
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
||||
import { twoFactor, username } from "better-auth/plugins";
|
||||
import type { BetterAuthOptions } from "better-auth";
|
||||
|
||||
describe("generate drizzle schema for all databases", async () => {
|
||||
it("should generate drizzle schema for MySQL", async () => {
|
||||
const schema = await generateDrizzleSchema({
|
||||
file: "test.drizzle",
|
||||
adapter: drizzleAdapter(
|
||||
{},
|
||||
{
|
||||
provider: "mysql",
|
||||
schema: {},
|
||||
},
|
||||
)({} as BetterAuthOptions),
|
||||
options: {
|
||||
database: drizzleAdapter(
|
||||
{},
|
||||
{
|
||||
provider: "mysql",
|
||||
schema: {},
|
||||
},
|
||||
),
|
||||
plugins: [twoFactor(), username()],
|
||||
user: {
|
||||
modelName: "custom_user",
|
||||
},
|
||||
account: {
|
||||
modelName: "custom_account",
|
||||
},
|
||||
session: {
|
||||
modelName: "custom_session",
|
||||
},
|
||||
verification: {
|
||||
modelName: "custom_verification",
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(schema.code).toMatchFileSnapshot(
|
||||
"./__snapshots__/auth-schema-mysql.txt",
|
||||
);
|
||||
});
|
||||
|
||||
it("should generate drizzle schema for SQLite", async () => {
|
||||
const schema = await generateDrizzleSchema({
|
||||
file: "test.drizzle",
|
||||
adapter: drizzleAdapter(
|
||||
{},
|
||||
{
|
||||
provider: "sqlite",
|
||||
schema: {},
|
||||
},
|
||||
)({} as BetterAuthOptions),
|
||||
options: {
|
||||
database: drizzleAdapter(
|
||||
{},
|
||||
{
|
||||
provider: "sqlite",
|
||||
schema: {},
|
||||
},
|
||||
),
|
||||
plugins: [twoFactor(), username()],
|
||||
user: {
|
||||
modelName: "custom_user",
|
||||
},
|
||||
account: {
|
||||
modelName: "custom_account",
|
||||
},
|
||||
session: {
|
||||
modelName: "custom_session",
|
||||
},
|
||||
verification: {
|
||||
modelName: "custom_verification",
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(schema.code).toMatchFileSnapshot(
|
||||
"./__snapshots__/auth-schema-sqlite.txt",
|
||||
);
|
||||
});
|
||||
|
||||
it("should generate drizzle schema for MySQL with number id", async () => {
|
||||
const schema = await generateDrizzleSchema({
|
||||
file: "test.drizzle",
|
||||
adapter: drizzleAdapter(
|
||||
{},
|
||||
{
|
||||
provider: "mysql",
|
||||
schema: {},
|
||||
},
|
||||
)({} as BetterAuthOptions),
|
||||
options: {
|
||||
database: drizzleAdapter(
|
||||
{},
|
||||
{
|
||||
provider: "mysql",
|
||||
schema: {},
|
||||
},
|
||||
),
|
||||
plugins: [twoFactor(), username()],
|
||||
advanced: {
|
||||
database: {
|
||||
useNumberId: true,
|
||||
},
|
||||
},
|
||||
user: {
|
||||
modelName: "custom_user",
|
||||
},
|
||||
account: {
|
||||
modelName: "custom_account",
|
||||
},
|
||||
session: {
|
||||
modelName: "custom_session",
|
||||
},
|
||||
verification: {
|
||||
modelName: "custom_verification",
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(schema.code).toMatchFileSnapshot(
|
||||
"./__snapshots__/auth-schema-mysql-number-id.txt",
|
||||
);
|
||||
});
|
||||
|
||||
it("should generate drizzle schema for SQLite with number id", async () => {
|
||||
const schema = await generateDrizzleSchema({
|
||||
file: "test.drizzle",
|
||||
adapter: drizzleAdapter(
|
||||
{},
|
||||
{
|
||||
provider: "sqlite",
|
||||
schema: {},
|
||||
},
|
||||
)({} as BetterAuthOptions),
|
||||
options: {
|
||||
database: drizzleAdapter(
|
||||
{},
|
||||
{
|
||||
provider: "sqlite",
|
||||
schema: {},
|
||||
},
|
||||
),
|
||||
plugins: [twoFactor(), username()],
|
||||
advanced: {
|
||||
database: {
|
||||
useNumberId: true,
|
||||
},
|
||||
},
|
||||
user: {
|
||||
modelName: "custom_user",
|
||||
},
|
||||
account: {
|
||||
modelName: "custom_account",
|
||||
},
|
||||
session: {
|
||||
modelName: "custom_session",
|
||||
},
|
||||
verification: {
|
||||
modelName: "custom_verification",
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(schema.code).toMatchFileSnapshot(
|
||||
"./__snapshots__/auth-schema-sqlite-number-id.txt",
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user