This repository was archived by the owner on Mar 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.ts
More file actions
76 lines (70 loc) · 2.34 KB
/
Copy pathschema.ts
File metadata and controls
76 lines (70 loc) · 2.34 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
67
68
69
70
71
72
73
74
75
76
import { createId } from '@paralleldrive/cuid2'
import { relations } from 'drizzle-orm'
import { integer, sqliteTable, text, primaryKey } from 'drizzle-orm/sqlite-core'
import type { AdapterAccount } from 'next-auth/adapters'
export const users = sqliteTable('user', {
id: text('id').notNull().primaryKey().$defaultFn(createId),
name: text('name'),
email: text('email').notNull(),
emailVerified: integer('emailVerified', { mode: 'timestamp_ms' }),
image: text('image'),
})
export const accounts = sqliteTable(
'account',
{
userId: text('userId')
.notNull()
.references(() => users.id, { onDelete: 'cascade' })
.$defaultFn(createId),
type: text('type').$type<AdapterAccount['type']>().notNull(),
provider: text('provider').notNull(),
providerAccountId: text('providerAccountId').notNull(),
refreshToken: text('refreshToken'),
accessToken: text('access_token'),
expiresAt: integer('expiresAt'),
tokenType: text('tokenType'),
scope: text('scope'),
idToken: text('id_token'),
sessionState: text('session_state'),
},
(account) => ({
compoundKey: primaryKey(account.provider, account.providerAccountId),
}),
)
export const sessions = sqliteTable('session', {
sessionToken: text('sessionToken').notNull().primaryKey(),
userId: text('userId')
.notNull()
.references(() => users.id, { onDelete: 'cascade' }),
expires: integer('expires', { mode: 'timestamp_ms' }).notNull(),
})
export const verificationTokens = sqliteTable(
'verification_token',
{
identifier: text('identifier').notNull(),
token: text('token').notNull(),
expires: integer('expires', { mode: 'timestamp_ms' }).notNull(),
},
(vt) => ({
compoundKey: primaryKey(vt.identifier, vt.token),
}),
)
export const posts = sqliteTable('post', {
id: text('id').primaryKey().notNull().$defaultFn(createId),
content: text('content').notNull(),
authorId: text('authorId')
.notNull()
.references(() => users.id, { onDelete: 'restrict', onUpdate: 'cascade' }),
createdAt: integer('createdAt', { mode: 'timestamp_ms' })
.notNull()
.defaultNow(),
updatedAt: integer('updatedAt', { mode: 'timestamp_ms' })
.notNull()
.defaultNow(),
})
export const postsRelations = relations(posts, ({ one }) => ({
author: one(users, {
fields: [posts.authorId],
references: [users.id],
}),
}))