-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.ts
More file actions
66 lines (58 loc) · 2.21 KB
/
Copy pathschema.ts
File metadata and controls
66 lines (58 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { uniqueIndex, index, varchar, text, integer, timestamp } from "drizzle-orm/pg-core";
import { createTable, fk, lower } from "./utils";
// Edit the type to add user roles for RBAC
export const USER_ROLES = ["user", "admin"] as const;
// *****_____*****_____*****_____*****_____*****_____*****_____
// DO NOT REMOVE OR RENAME, ONLY ADD TO THESE TABLES IF REQUIRED
// NEXT AUTH IS DEPENDENT ON THESE HAVING THESE GIVEN COLUMNS
// MAKE ALL EXTRA FIELDS OPTIONAL - OR HAVE DEFAULTS
// *****_____*****_____*****_____*****_____*****_____*****_____
export const user = createTable(
"user",
{
name: varchar({ length: 255 }),
email: varchar({ length: 255 }).notNull(),
emailVerified: timestamp({ mode: "date", withTimezone: true }),
image: varchar({ length: 255 }),
userRole: varchar({ enum: USER_ROLES }).default("user"),
},
(t) => [
uniqueIndex("user_email_idx").on(lower(t.email))
]
);
export type User = typeof user.$inferSelect;
export type NewUser = typeof user.$inferInsert;
export const account = createTable(
"account",
{
userId: fk("user_id", () => user, { onDelete: "cascade" }).notNull(),
type: varchar({ length: 255 })
.$type<"email" | "oauth" | "oidc" | "webauthn">()
.notNull(),
provider: varchar({ length: 255 }).notNull(),
providerAccountId: varchar({ length: 255 }).notNull(),
refresh_token: varchar({ length: 255 }),
access_token: text(),
expires_at: integer(),
token_type: varchar({ length: 255 }),
scope: varchar({ length: 255 }),
id_token: text(),
session_state: varchar({ length: 255 }),
},
(t) => [
index("account_user_id_idx").on(t.userId)
],
);
export type Account = typeof account.$inferSelect;
export type NewAccount = typeof account.$inferInsert;
export const session = createTable("session", {
sessionToken: varchar({ length: 255 }).notNull(),
userId: fk("user_id", () => user, { onDelete: "cascade" }).notNull(),
expires: timestamp({ mode: "date", withTimezone: true }).notNull(),
},
(t) => [
index("session_token_idx").on(t.sessionToken)
]);
export type Session = typeof session.$inferSelect;
export type NewSession = typeof session.$inferInsert;
// *****_____*****_____*****_____*****_____*****_____*****_____