diff --git a/drizzle/0002_add_accounts_table.sql b/drizzle/0002_add_accounts_table.sql new file mode 100644 index 0000000..4893cb0 --- /dev/null +++ b/drizzle/0002_add_accounts_table.sql @@ -0,0 +1,17 @@ +CREATE TABLE "accounts" ( + "id" text PRIMARY KEY NOT NULL, + "user_id" text NOT NULL, + "account_id" text NOT NULL, + "provider_id" text NOT NULL, + "access_token" text, + "refresh_token" text, + "access_token_expires_at" timestamp, + "refresh_token_expires_at" timestamp, + "scope" text, + "id_token" text, + "password" text, + "created_at" timestamp with time zone DEFAULT now() NOT NULL, + "updated_at" timestamp with time zone DEFAULT now() NOT NULL +); +ALTER TABLE "accounts" ADD CONSTRAINT "accounts_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; +CREATE INDEX "accounts_user_id_idx" ON "accounts" USING btree ("user_id"); diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index 8ea146d..698f71f 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -15,6 +15,13 @@ "when": 1777066300000, "tag": "0001_fix_email_verified", "breakpoints": true + }, + { + "idx": 2, + "version": "7", + "when": 1777066400000, + "tag": "0002_add_accounts_table", + "breakpoints": true } ] } \ No newline at end of file diff --git a/src/lib/auth.ts b/src/lib/auth.ts index d472f83..c1ac1c4 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -1,7 +1,7 @@ import { betterAuth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { db } from "./db"; -import { users, sessions } from "./db/schema"; +import { users, sessions, accounts } from "./db/schema"; export const auth = betterAuth({ database: drizzleAdapter(db, { @@ -9,6 +9,7 @@ export const auth = betterAuth({ schema: { user: users, session: sessions, + account: accounts, }, }), emailAndPassword: { enabled: true }, diff --git a/src/lib/db/schema.ts b/src/lib/db/schema.ts index 1432945..42856d4 100644 --- a/src/lib/db/schema.ts +++ b/src/lib/db/schema.ts @@ -20,6 +20,24 @@ export const users = pgTable("users", { updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().notNull(), }); +export const accounts = pgTable("accounts", { + id: text("id").primaryKey().$defaultFn(() => createId()), + userId: text("user_id") + .notNull() + .references(() => users.id, { onDelete: "cascade" }), + accountId: text("account_id").notNull(), + providerId: text("provider_id").notNull(), + accessToken: text("access_token"), + refreshToken: text("refresh_token"), + accessTokenExpiresAt: timestamp("access_token_expires_at"), + refreshTokenExpiresAt: timestamp("refresh_token_expires_at"), + scope: text("scope"), + idToken: text("id_token"), + password: text("password"), + createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().notNull(), +}); + export const comparisonStatusEnum = pgEnum("comparison_status", [ "researching", "completed",