|
| 1 | +import { |
| 2 | + boolean, |
| 3 | + timestamp, |
| 4 | + pgTable, |
| 5 | + text, |
| 6 | + primaryKey, |
| 7 | + integer, |
| 8 | +} from "drizzle-orm/pg-core" |
| 9 | +import type { AdapterAccountType } from "next-auth/adapters" |
| 10 | + |
| 11 | +export const waitlist = pgTable("waitlist", (w) => ({ |
| 12 | + id: w.serial("id").primaryKey(), |
| 13 | + email: w.varchar("email", { length: 255 }).notNull(), |
| 14 | + createdAt: w.timestamp("created_at").defaultNow(), |
| 15 | +})) |
| 16 | + |
| 17 | +export const users = pgTable("user", { |
| 18 | + id: text("id") |
| 19 | + .primaryKey() |
| 20 | + .$defaultFn(() => crypto.randomUUID()), |
| 21 | + name: text("name"), |
| 22 | + email: text("email").unique(), |
| 23 | + emailVerified: timestamp("emailVerified", { mode: "date" }), |
| 24 | + image: text("image"), |
| 25 | +}) |
| 26 | + |
| 27 | +export const accounts = pgTable( |
| 28 | + "account", |
| 29 | + { |
| 30 | + userId: text("userId") |
| 31 | + .notNull() |
| 32 | + .references(() => users.id, { onDelete: "cascade" }), |
| 33 | + type: text("type").$type<AdapterAccountType>().notNull(), |
| 34 | + provider: text("provider").notNull(), |
| 35 | + providerAccountId: text("providerAccountId").notNull(), |
| 36 | + refresh_token: text("refresh_token"), |
| 37 | + access_token: text("access_token"), |
| 38 | + expires_at: integer("expires_at"), |
| 39 | + token_type: text("token_type"), |
| 40 | + scope: text("scope"), |
| 41 | + id_token: text("id_token"), |
| 42 | + session_state: text("session_state"), |
| 43 | + }, |
| 44 | + (account) => [ |
| 45 | + { |
| 46 | + compoundKey: primaryKey({ |
| 47 | + columns: [account.provider, account.providerAccountId], |
| 48 | + }), |
| 49 | + }, |
| 50 | + ] |
| 51 | +) |
| 52 | + |
| 53 | +export const sessions = pgTable("session", { |
| 54 | + sessionToken: text("sessionToken").primaryKey(), |
| 55 | + userId: text("userId") |
| 56 | + .notNull() |
| 57 | + .references(() => users.id, { onDelete: "cascade" }), |
| 58 | + expires: timestamp("expires", { mode: "date" }).notNull(), |
| 59 | +}) |
| 60 | + |
| 61 | +export const verificationTokens = pgTable( |
| 62 | + "verificationToken", |
| 63 | + { |
| 64 | + identifier: text("identifier").notNull(), |
| 65 | + token: text("token").notNull(), |
| 66 | + expires: timestamp("expires", { mode: "date" }).notNull(), |
| 67 | + }, |
| 68 | + (verificationToken) => [ |
| 69 | + { |
| 70 | + compositePk: primaryKey({ |
| 71 | + columns: [verificationToken.identifier, verificationToken.token], |
| 72 | + }), |
| 73 | + }, |
| 74 | + ] |
| 75 | +) |
| 76 | + |
| 77 | +export const authenticators = pgTable( |
| 78 | + "authenticator", |
| 79 | + { |
| 80 | + credentialID: text("credentialID").notNull().unique(), |
| 81 | + userId: text("userId") |
| 82 | + .notNull() |
| 83 | + .references(() => users.id, { onDelete: "cascade" }), |
| 84 | + providerAccountId: text("providerAccountId").notNull(), |
| 85 | + credentialPublicKey: text("credentialPublicKey").notNull(), |
| 86 | + counter: integer("counter").notNull(), |
| 87 | + credentialDeviceType: text("credentialDeviceType").notNull(), |
| 88 | + credentialBackedUp: boolean("credentialBackedUp").notNull(), |
| 89 | + transports: text("transports"), |
| 90 | + }, |
| 91 | + (authenticator) => [ |
| 92 | + { |
| 93 | + compositePK: primaryKey({ |
| 94 | + columns: [authenticator.userId, authenticator.credentialID], |
| 95 | + }), |
| 96 | + }, |
| 97 | + ] |
| 98 | +) |
0 commit comments