fix(auth): align account schema with Better Auth 1.7.3 (#3488)

This commit is contained in:
Amruth Pillai
2026-09-06 00:08:48 -07:00
committed by GitHub
parent 7fef84078d
commit cea27a97bb
4 changed files with 6475 additions and 5 deletions
@@ -0,0 +1,2 @@
DROP INDEX "account_issuer_account_id_unique_idx";--> statement-breakpoint
ALTER TABLE "account" ALTER COLUMN "issuer" DROP NOT NULL;
File diff suppressed because it is too large Load Diff
+13
View File
@@ -0,0 +1,13 @@
import { describe, expect, it } from "vitest";
import { getTableConfig } from "drizzle-orm/pg-core";
import { account } from "./auth";
describe("Better Auth account schema", () => {
it("does not require the retired issuer identity key", () => {
const config = getTableConfig(account);
const issuer = config.columns.find((column) => column.name === "issuer");
expect(issuer).toMatchObject({ name: "issuer", notNull: false });
expect(config.indexes.map((index) => index.config.name)).not.toContain("account_issuer_account_id_unique_idx");
});
});
+5 -5
View File
@@ -78,10 +78,10 @@ export const account = pg.pgTable(
.$defaultFn(() => generateId()), .$defaultFn(() => generateId()),
accountId: pg.text("account_id").notNull(), accountId: pg.text("account_id").notNull(),
providerId: pg.text("provider_id").notNull().default("credential"), providerId: pg.text("provider_id").notNull().default("credential"),
// Better Auth 1.7 scopes account identity to (issuer, accountId) rather than providerId. // Better Auth 1.7.0–1.7.2 wrote this identity namespace. Version 1.7.3
// Real OIDC issuers are stored verbatim; providers without one get a synthetic // returned to (providerId, accountId), so keep migrated values without
// `local:`/`local:oauth:` namespace. See migrations/*_account_issuer for the backfill. // requiring the field on new account inserts.
issuer: pg.text("issuer").notNull(), issuer: pg.text("issuer"),
userId: pg userId: pg
.text("user_id") .text("user_id")
.notNull() .notNull()
@@ -104,7 +104,7 @@ export const account = pg.pgTable(
.defaultNow() .defaultNow()
.$onUpdate(() => /* @__PURE__ */ new Date()), .$onUpdate(() => /* @__PURE__ */ new Date()),
}, },
(t) => [pg.index().on(t.userId), pg.uniqueIndex("account_issuer_account_id_unique_idx").on(t.issuer, t.accountId)], (t) => [pg.index().on(t.userId)],
); );
export const verification = pg.pgTable( export const verification = pg.pgTable(