67 lines
1.9 KiB
TypeScript
67 lines
1.9 KiB
TypeScript
import {
|
|
pgSchema,
|
|
text,
|
|
timestamp,
|
|
integer,
|
|
primaryKey,
|
|
uniqueIndex,
|
|
} from "drizzle-orm/pg-core";
|
|
import type { AdapterAccount } from "next-auth/adapters";
|
|
|
|
export const accountSchema = pgSchema("account");
|
|
|
|
export const users = accountSchema.table(
|
|
"user",
|
|
{
|
|
id: text("id")
|
|
.primaryKey()
|
|
.$defaultFn(() => crypto.randomUUID()),
|
|
name: text("name"),
|
|
email: text("email").unique(),
|
|
emailVerified: timestamp("emailVerified", { mode: "date" }),
|
|
image: text("image"),
|
|
discordId: text("discord_id"),
|
|
},
|
|
(user) => [uniqueIndex("user_discord_id_unique").on(user.discordId)]
|
|
);
|
|
|
|
export const accounts = accountSchema.table(
|
|
"account",
|
|
{
|
|
userId: text("userId")
|
|
.notNull()
|
|
.references(() => users.id, { onDelete: "cascade" }),
|
|
type: text("type").$type<AdapterAccount["type"]>().notNull(),
|
|
provider: text("provider").notNull(),
|
|
providerAccountId: text("providerAccountId").notNull(),
|
|
refresh_token: text("refresh_token"),
|
|
access_token: text("access_token"),
|
|
expires_at: integer("expires_at"),
|
|
token_type: text("token_type"),
|
|
scope: text("scope"),
|
|
id_token: text("id_token"),
|
|
session_state: text("session_state"),
|
|
},
|
|
(account) => [
|
|
primaryKey({ columns: [account.provider, account.providerAccountId] }),
|
|
]
|
|
);
|
|
|
|
export const sessions = accountSchema.table("session", {
|
|
sessionToken: text("sessionToken").primaryKey(),
|
|
userId: text("userId")
|
|
.notNull()
|
|
.references(() => users.id, { onDelete: "cascade" }),
|
|
expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
});
|
|
|
|
export const verificationTokens = accountSchema.table(
|
|
"verificationToken",
|
|
{
|
|
identifier: text("identifier").notNull(),
|
|
token: text("token").notNull(),
|
|
expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
},
|
|
(vt) => [primaryKey({ columns: [vt.identifier, vt.token] })]
|
|
);
|