|
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" |
| 1 | +import { boolean, timestamp, pgTable, text } from "drizzle-orm/pg-core" |
10 | 2 |
|
11 | 3 | export const waitlist = pgTable("waitlist", (w) => ({ |
12 | 4 | id: w.serial("id").primaryKey(), |
13 | 5 | email: w.varchar("email", { length: 255 }).notNull(), |
14 | 6 | createdAt: w.timestamp("created_at").defaultNow(), |
15 | 7 | })) |
16 | 8 |
|
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" }), |
| 9 | +export const user = pgTable("user", { |
| 10 | + id: text("id").primaryKey(), |
| 11 | + name: text("name").notNull(), |
| 12 | + email: text("email").notNull().unique(), |
| 13 | + emailVerified: boolean("email_verified").default(false).notNull(), |
24 | 14 | image: text("image"), |
| 15 | + createdAt: timestamp("created_at").defaultNow().notNull(), |
| 16 | + updatedAt: timestamp("updated_at") |
| 17 | + .defaultNow() |
| 18 | + .$onUpdate(() => /* @__PURE__ */ new Date()) |
| 19 | + .notNull(), |
25 | 20 | }) |
26 | 21 |
|
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") |
| 22 | +export const session = pgTable("session", { |
| 23 | + id: text("id").primaryKey(), |
| 24 | + expiresAt: timestamp("expires_at").notNull(), |
| 25 | + token: text("token").notNull().unique(), |
| 26 | + createdAt: timestamp("created_at").defaultNow().notNull(), |
| 27 | + updatedAt: timestamp("updated_at") |
| 28 | + .$onUpdate(() => /* @__PURE__ */ new Date()) |
| 29 | + .notNull(), |
| 30 | + ipAddress: text("ip_address"), |
| 31 | + userAgent: text("user_agent"), |
| 32 | + userId: text("user_id") |
56 | 33 | .notNull() |
57 | | - .references(() => users.id, { onDelete: "cascade" }), |
58 | | - expires: timestamp("expires", { mode: "date" }).notNull(), |
| 34 | + .references(() => user.id, { onDelete: "cascade" }), |
59 | 35 | }) |
60 | 36 |
|
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 | | -) |
| 37 | +export const account = pgTable("account", { |
| 38 | + id: text("id").primaryKey(), |
| 39 | + accountId: text("account_id").notNull(), |
| 40 | + providerId: text("provider_id").notNull(), |
| 41 | + userId: text("user_id") |
| 42 | + .notNull() |
| 43 | + .references(() => user.id, { onDelete: "cascade" }), |
| 44 | + accessToken: text("access_token"), |
| 45 | + refreshToken: text("refresh_token"), |
| 46 | + idToken: text("id_token"), |
| 47 | + accessTokenExpiresAt: timestamp("access_token_expires_at"), |
| 48 | + refreshTokenExpiresAt: timestamp("refresh_token_expires_at"), |
| 49 | + scope: text("scope"), |
| 50 | + password: text("password"), |
| 51 | + createdAt: timestamp("created_at").defaultNow().notNull(), |
| 52 | + updatedAt: timestamp("updated_at") |
| 53 | + .$onUpdate(() => /* @__PURE__ */ new Date()) |
| 54 | + .notNull(), |
| 55 | +}) |
76 | 56 |
|
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 | | -) |
| 57 | +export const verification = pgTable("verification", { |
| 58 | + id: text("id").primaryKey(), |
| 59 | + identifier: text("identifier").notNull(), |
| 60 | + value: text("value").notNull(), |
| 61 | + expiresAt: timestamp("expires_at").notNull(), |
| 62 | + createdAt: timestamp("created_at").defaultNow().notNull(), |
| 63 | + updatedAt: timestamp("updated_at") |
| 64 | + .defaultNow() |
| 65 | + .$onUpdate(() => /* @__PURE__ */ new Date()) |
| 66 | + .notNull(), |
| 67 | +}) |
0 commit comments