Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {
- boolean,
- integer,
- pgTable,
- primaryKey,
- text,
- timestamp,
- } from "drizzle-orm/pg-core";
- import type { AdapterAccountType } from "next-auth/adapters";
- export const users = pgTable("user", {
- id: text("id")
- .primaryKey()
- .$defaultFn(() => crypto.randomUUID()),
- name: text("name"),
- email: text("email").notNull(),
- emailVerified: timestamp("emailVerified", { mode: "date" }),
- image: text("image"),
- });
- export const accounts = pgTable(
- "account",
- {
- userId: text("userId")
- .notNull()
- .references(() => users.id, { onDelete: "cascade" }),
- type: text("type").$type<AdapterAccountType>().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) => ({
- pk: primaryKey({
- columns: [account.provider, account.providerAccountId],
- }),
- }),
- );
- export const sessions = pgTable("session", {
- sessionToken: text("sessionToken").primaryKey(),
- userId: text("userId")
- .notNull()
- .references(() => users.id, { onDelete: "cascade" }),
- expires: timestamp("expires", { mode: "date" }).notNull(),
- });
- export const verificationTokens = pgTable(
- "verificationToken",
- {
- identifier: text("identifier").notNull(),
- token: text("token").notNull(),
- expires: timestamp("expires", { mode: "date" }).notNull(),
- },
- (verificationToken) => ({
- pk: primaryKey({
- columns: [verificationToken.identifier, verificationToken.token],
- }),
- }),
- );
- export const authenticators = pgTable(
- "authenticator",
- {
- credentialID: text("credentialID").notNull().unique(),
- userId: text("userId")
- .notNull()
- .references(() => users.id, { onDelete: "cascade" }),
- providerAccountId: text("providerAccountId").notNull(),
- credentialPublicKey: text("credentialPublicKey").notNull(),
- counter: integer("counter").notNull(),
- credentialDeviceType: text("credentialDeviceType").notNull(),
- credentialBackedUp: boolean("credentialBackedUp").notNull(),
- transports: text("transports"),
- },
- (authenticator) => ({
- pk: primaryKey({
- columns: [authenticator.userId, authenticator.credentialID],
- }),
- }),
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement