@auth/drizzle-adapter 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +62 -72
- package/index.d.ts.map +1 -1
- package/index.js +62 -72
- package/lib/mysql.d.ts +230 -70
- package/lib/mysql.d.ts.map +1 -1
- package/lib/mysql.js +17 -21
- package/lib/pg.d.ts +229 -70
- package/lib/pg.d.ts.map +1 -1
- package/lib/pg.js +9 -17
- package/lib/sqlite.d.ts +229 -70
- package/lib/sqlite.d.ts.map +1 -1
- package/lib/sqlite.js +14 -16
- package/lib/utils.d.ts +6 -6
- package/lib/utils.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/index.ts +62 -88
- package/src/lib/mysql.ts +221 -57
- package/src/lib/pg.ts +213 -51
- package/src/lib/sqlite.ts +215 -47
- package/src/lib/utils.ts +14 -13
package/index.d.ts
CHANGED
|
@@ -17,17 +17,14 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import { DefaultSchema, SqlFlavorOptions } from "./lib/utils.js";
|
|
19
19
|
import type { Adapter } from "@auth/core/adapters";
|
|
20
|
-
export { postgresUsersTable, postgresAccountsTable, postgresSessionsTable, postgresVerificationTokensTable, } from "./lib/pg.js";
|
|
21
|
-
export { sqliteUsersTable, sqliteAccountsTable, sqliteSessionsTable, sqliteVerificationTokensTable, } from "./lib/sqlite.js";
|
|
22
|
-
export { mysqlUsersTable, mysqlAccountsTable, mysqlSessionsTable, mysqlVerificationTokensTable, } from "./lib/mysql.js";
|
|
23
20
|
/**
|
|
24
|
-
* Add this adapter to your `auth.ts` Auth.js configuration object:
|
|
21
|
+
* Create db instance and pass it to adapter. Add this adapter to your `auth.ts` Auth.js configuration object:
|
|
25
22
|
*
|
|
26
23
|
* ```ts title="auth.ts"
|
|
27
24
|
* import NextAuth from "next-auth"
|
|
28
25
|
* import Google from "next-auth/providers/google"
|
|
29
26
|
* import { DrizzleAdapter } from "@auth/drizzle-adapter"
|
|
30
|
-
* import { db } from "./
|
|
27
|
+
* import { db } from "./db.ts"
|
|
31
28
|
*
|
|
32
29
|
* export const { handlers, auth } = NextAuth({
|
|
33
30
|
* adapter: DrizzleAdapter(db),
|
|
@@ -37,15 +34,18 @@ export { mysqlUsersTable, mysqlAccountsTable, mysqlSessionsTable, mysqlVerificat
|
|
|
37
34
|
* })
|
|
38
35
|
* ```
|
|
39
36
|
*
|
|
37
|
+
* Follow the Drizzle documentation for [PostgreSQL setup](https://orm.drizzle.team/docs/get-started-postgresql), [MySQL setup](https://orm.drizzle.team/docs/get-started-mysql) and [SQLite setup](https://orm.drizzle.team/docs/get-started-sqlite).
|
|
38
|
+
*
|
|
40
39
|
* :::info
|
|
41
|
-
* If you want to use your own tables, you can pass them as a second argument
|
|
40
|
+
* If you want to use your own tables, you can pass them as a second argument. If you add non-nullable columns, make sure to provide a default value or rewrite functions to handle the missing values.
|
|
42
41
|
* :::
|
|
43
42
|
*
|
|
44
43
|
* ```ts title="auth.ts"
|
|
45
44
|
* import NextAuth from "next-auth"
|
|
46
45
|
* import Google from "next-auth/providers/google"
|
|
47
46
|
* import { DrizzleAdapter } from "@auth/drizzle-adapter"
|
|
48
|
-
* import {
|
|
47
|
+
* import { accounts, sessions, users, verificationTokens } from "./schema"
|
|
48
|
+
* import { db } from "./db.ts"
|
|
49
49
|
*
|
|
50
50
|
* export const { handlers, auth } = NextAuth({
|
|
51
51
|
* adapter: DrizzleAdapter(db, { usersTable: users, accountsTable: accounts, sessionsTable: sessions, verificationTokensTable: verificationTokens }),
|
|
@@ -80,7 +80,7 @@ export { mysqlUsersTable, mysqlAccountsTable, mysqlSessionsTable, mysqlVerificat
|
|
|
80
80
|
* export const users = pgTable("user", {
|
|
81
81
|
* id: text("id").primaryKey().$defaultFn(() => randomUUID()),
|
|
82
82
|
* name: text("name"),
|
|
83
|
-
* email: text("email").notNull()
|
|
83
|
+
* email: text("email").notNull(),
|
|
84
84
|
* emailVerified: timestamp("emailVerified", { mode: "date" }),
|
|
85
85
|
* image: text("image"),
|
|
86
86
|
* })
|
|
@@ -103,27 +103,23 @@ export { mysqlUsersTable, mysqlAccountsTable, mysqlSessionsTable, mysqlVerificat
|
|
|
103
103
|
* session_state: text("session_state"),
|
|
104
104
|
* },
|
|
105
105
|
* (account) => ({
|
|
106
|
-
* userIdIdx: index().on(account.userId),
|
|
107
106
|
* compoundKey: primaryKey({ columns: [account.provider, account.providerAccountId] }),
|
|
108
107
|
* })
|
|
109
108
|
* )
|
|
110
109
|
*
|
|
111
110
|
* export const sessions = pgTable("session", {
|
|
112
|
-
*
|
|
113
|
-
* sessionToken: text("sessionToken").notNull().unique(),
|
|
111
|
+
* sessionToken: text("sessionToken").primaryKey(),
|
|
114
112
|
* userId: text("userId")
|
|
115
113
|
* .notNull()
|
|
116
114
|
* .references(() => users.id, { onDelete: "cascade" }),
|
|
117
115
|
* expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
118
|
-
* }
|
|
119
|
-
* userIdIdx: index().on(session.userId)
|
|
120
|
-
* }))
|
|
116
|
+
* })
|
|
121
117
|
*
|
|
122
118
|
* export const verificationTokens = pgTable(
|
|
123
119
|
* "verificationToken",
|
|
124
120
|
* {
|
|
125
121
|
* identifier: text("identifier").notNull(),
|
|
126
|
-
* token: text("token").notNull()
|
|
122
|
+
* token: text("token").notNull(),
|
|
127
123
|
* expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
128
124
|
* },
|
|
129
125
|
* (vt) => ({
|
|
@@ -134,6 +130,8 @@ export { mysqlUsersTable, mysqlAccountsTable, mysqlSessionsTable, mysqlVerificat
|
|
|
134
130
|
*
|
|
135
131
|
* ### MySQL
|
|
136
132
|
*
|
|
133
|
+
* In MySQL, there's no `returning` clause, so in the `createUser` function, we first insert a new user and then search by `email` to get the user's data. To make the search faster, we suggest adding an index to the `email` column.
|
|
134
|
+
*
|
|
137
135
|
* ```ts title="schema.ts"
|
|
138
136
|
* import {
|
|
139
137
|
* int,
|
|
@@ -147,7 +145,7 @@ export { mysqlUsersTable, mysqlAccountsTable, mysqlSessionsTable, mysqlVerificat
|
|
|
147
145
|
* export const users = mysqlTable("user", {
|
|
148
146
|
* id: varchar("id", { length: 255 }).primaryKey().$defaultFn(() => randomUUID()),
|
|
149
147
|
* name: varchar("name", { length: 255 }),
|
|
150
|
-
* email: varchar("email", { length: 255 }).notNull()
|
|
148
|
+
* email: varchar("email", { length: 255 }).notNull(),
|
|
151
149
|
* emailVerified: timestamp("emailVerified", { mode: "date", fsp: 3 }),
|
|
152
150
|
* image: varchar("image", { length: 255 }),
|
|
153
151
|
* })
|
|
@@ -155,49 +153,45 @@ export { mysqlUsersTable, mysqlAccountsTable, mysqlSessionsTable, mysqlVerificat
|
|
|
155
153
|
* export const accounts = mysqlTable(
|
|
156
154
|
* "account",
|
|
157
155
|
* {
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
* })
|
|
156
|
+
* userId: varchar("userId", { length: 255 })
|
|
157
|
+
* .notNull()
|
|
158
|
+
* .references(() => users.id, { onDelete: "cascade" }),
|
|
159
|
+
* type: varchar("type", { length: 255 }).notNull(),
|
|
160
|
+
* provider: varchar("provider", { length: 255 }).notNull(),
|
|
161
|
+
* providerAccountId: varchar("providerAccountId", { length: 255 }).notNull(),
|
|
162
|
+
* refresh_token: varchar("refresh_token", { length: 255 }),
|
|
163
|
+
* access_token: varchar("access_token", { length: 255 }),
|
|
164
|
+
* expires_at: int("expires_at"),
|
|
165
|
+
* token_type: varchar("token_type", { length: 255 }),
|
|
166
|
+
* scope: varchar("scope", { length: 255 }),
|
|
167
|
+
* id_token: varchar("id_token", { length: 2048 }),
|
|
168
|
+
* session_state: varchar("session_state", { length: 255 }),
|
|
169
|
+
* },
|
|
170
|
+
* (account) => ({
|
|
171
|
+
* compoundKey: primaryKey({
|
|
172
|
+
columns: [account.provider, account.providerAccountId],
|
|
173
|
+
})
|
|
174
|
+
* })
|
|
178
175
|
* )
|
|
179
176
|
*
|
|
180
177
|
* export const sessions = mysqlTable("session", {
|
|
181
|
-
*
|
|
182
|
-
* sessionToken: varchar("sessionToken", { length: 255 }).notNull().unique(),
|
|
178
|
+
* sessionToken: varchar("sessionToken", { length: 255 }).primaryKey(),
|
|
183
179
|
* userId: varchar("userId", { length: 255 })
|
|
184
180
|
* .notNull()
|
|
185
181
|
* .references(() => users.id, { onDelete: "cascade" }),
|
|
186
182
|
* expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
187
|
-
* }
|
|
188
|
-
* userIdIdx: index('Session_userId_index').on(session.userId)
|
|
189
|
-
* }))
|
|
183
|
+
* })
|
|
190
184
|
*
|
|
191
185
|
* export const verificationTokens = mysqlTable(
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
186
|
+
* "verificationToken",
|
|
187
|
+
* {
|
|
188
|
+
* identifier: varchar("identifier", { length: 255 }).notNull(),
|
|
189
|
+
* token: varchar("token", { length: 255 }).notNull(),
|
|
190
|
+
* expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
191
|
+
* },
|
|
192
|
+
* (vt) => ({
|
|
193
|
+
* compoundKey: primaryKey({ columns: [vt.identifier, vt.token] }),
|
|
194
|
+
* })
|
|
201
195
|
* )
|
|
202
196
|
* ```
|
|
203
197
|
*
|
|
@@ -210,7 +204,7 @@ export { mysqlUsersTable, mysqlAccountsTable, mysqlSessionsTable, mysqlVerificat
|
|
|
210
204
|
* export const users = sqliteTable("user", {
|
|
211
205
|
* id: text("id").primaryKey().$defaultFn(() => randomUUID()),
|
|
212
206
|
* name: text("name"),
|
|
213
|
-
* email: text("email").notNull()
|
|
207
|
+
* email: text("email").notNull(),
|
|
214
208
|
* emailVerified: integer("emailVerified", { mode: "timestamp_ms" }),
|
|
215
209
|
* image: text("image"),
|
|
216
210
|
* })
|
|
@@ -235,39 +229,35 @@ export { mysqlUsersTable, mysqlAccountsTable, mysqlSessionsTable, mysqlVerificat
|
|
|
235
229
|
* (account) => ({
|
|
236
230
|
* compoundKey: primaryKey({
|
|
237
231
|
columns: [account.provider, account.providerAccountId],
|
|
238
|
-
})
|
|
239
|
-
userIdIdx: index('Account_userId_index').on(account.userId)
|
|
232
|
+
})
|
|
240
233
|
* })
|
|
241
234
|
* )
|
|
242
235
|
*
|
|
243
236
|
* export const sessions = sqliteTable("session", {
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
* }, (table) => ({
|
|
251
|
-
* userIdIdx: index('Session_userId_index').on(table.userId)
|
|
252
|
-
* }))
|
|
237
|
+
* sessionToken: text("sessionToken").primaryKey(),
|
|
238
|
+
* userId: text("userId")
|
|
239
|
+
* .notNull()
|
|
240
|
+
* .references(() => users.id, { onDelete: "cascade" }),
|
|
241
|
+
* expires: integer("expires", { mode: "timestamp_ms" }).notNull(),
|
|
242
|
+
* })
|
|
253
243
|
*
|
|
254
244
|
* export const verificationTokens = sqliteTable(
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
245
|
+
* "verificationToken",
|
|
246
|
+
* {
|
|
247
|
+
* identifier: text("identifier").notNull(),
|
|
248
|
+
* token: text("token").notNull(),
|
|
249
|
+
* expires: integer("expires", { mode: "timestamp_ms" }).notNull(),
|
|
250
|
+
* },
|
|
251
|
+
* (vt) => ({
|
|
252
|
+
* compoundKey: primaryKey({ columns: [vt.identifier, vt.token] }),
|
|
253
|
+
* })
|
|
264
254
|
* )
|
|
265
255
|
* ```
|
|
266
256
|
*
|
|
267
257
|
* ## Migrating your database
|
|
268
258
|
* With your schema now described in your code, you'll need to migrate your database to your schema.
|
|
269
259
|
*
|
|
270
|
-
* For full documentation on how to run migrations with Drizzle, [visit the Drizzle documentation](https://orm.drizzle.team/kit-docs/overview#running-migrations).
|
|
260
|
+
* For full documentation on how to run migrations with Drizzle, [visit the Drizzle documentation](https://orm.drizzle.team/kit-docs/overview#running-migrations) or check how to apply changes directly to the database with [push command](https://orm.drizzle.team/kit-docs/overview#prototyping-with-db-push).
|
|
271
261
|
*
|
|
272
262
|
* ---
|
|
273
263
|
*
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AASH,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAEhE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AASH,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAEhE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAoPI;AACJ,wBAAgB,cAAc,CAAC,SAAS,SAAS,gBAAgB,EAC/D,EAAE,EAAE,SAAS,EACb,MAAM,CAAC,EAAE,aAAa,CAAC,SAAS,CAAC,GAChC,OAAO,CAYT"}
|
package/index.js
CHANGED
|
@@ -22,17 +22,14 @@ import { BaseSQLiteDatabase } from "drizzle-orm/sqlite-core";
|
|
|
22
22
|
import { MySqlDrizzleAdapter } from "./lib/mysql.js";
|
|
23
23
|
import { PostgresDrizzleAdapter } from "./lib/pg.js";
|
|
24
24
|
import { SQLiteDrizzleAdapter } from "./lib/sqlite.js";
|
|
25
|
-
export { postgresUsersTable, postgresAccountsTable, postgresSessionsTable, postgresVerificationTokensTable, } from "./lib/pg.js";
|
|
26
|
-
export { sqliteUsersTable, sqliteAccountsTable, sqliteSessionsTable, sqliteVerificationTokensTable, } from "./lib/sqlite.js";
|
|
27
|
-
export { mysqlUsersTable, mysqlAccountsTable, mysqlSessionsTable, mysqlVerificationTokensTable, } from "./lib/mysql.js";
|
|
28
25
|
/**
|
|
29
|
-
* Add this adapter to your `auth.ts` Auth.js configuration object:
|
|
26
|
+
* Create db instance and pass it to adapter. Add this adapter to your `auth.ts` Auth.js configuration object:
|
|
30
27
|
*
|
|
31
28
|
* ```ts title="auth.ts"
|
|
32
29
|
* import NextAuth from "next-auth"
|
|
33
30
|
* import Google from "next-auth/providers/google"
|
|
34
31
|
* import { DrizzleAdapter } from "@auth/drizzle-adapter"
|
|
35
|
-
* import { db } from "./
|
|
32
|
+
* import { db } from "./db.ts"
|
|
36
33
|
*
|
|
37
34
|
* export const { handlers, auth } = NextAuth({
|
|
38
35
|
* adapter: DrizzleAdapter(db),
|
|
@@ -42,15 +39,18 @@ export { mysqlUsersTable, mysqlAccountsTable, mysqlSessionsTable, mysqlVerificat
|
|
|
42
39
|
* })
|
|
43
40
|
* ```
|
|
44
41
|
*
|
|
42
|
+
* Follow the Drizzle documentation for [PostgreSQL setup](https://orm.drizzle.team/docs/get-started-postgresql), [MySQL setup](https://orm.drizzle.team/docs/get-started-mysql) and [SQLite setup](https://orm.drizzle.team/docs/get-started-sqlite).
|
|
43
|
+
*
|
|
45
44
|
* :::info
|
|
46
|
-
* If you want to use your own tables, you can pass them as a second argument
|
|
45
|
+
* If you want to use your own tables, you can pass them as a second argument. If you add non-nullable columns, make sure to provide a default value or rewrite functions to handle the missing values.
|
|
47
46
|
* :::
|
|
48
47
|
*
|
|
49
48
|
* ```ts title="auth.ts"
|
|
50
49
|
* import NextAuth from "next-auth"
|
|
51
50
|
* import Google from "next-auth/providers/google"
|
|
52
51
|
* import { DrizzleAdapter } from "@auth/drizzle-adapter"
|
|
53
|
-
* import {
|
|
52
|
+
* import { accounts, sessions, users, verificationTokens } from "./schema"
|
|
53
|
+
* import { db } from "./db.ts"
|
|
54
54
|
*
|
|
55
55
|
* export const { handlers, auth } = NextAuth({
|
|
56
56
|
* adapter: DrizzleAdapter(db, { usersTable: users, accountsTable: accounts, sessionsTable: sessions, verificationTokensTable: verificationTokens }),
|
|
@@ -85,7 +85,7 @@ export { mysqlUsersTable, mysqlAccountsTable, mysqlSessionsTable, mysqlVerificat
|
|
|
85
85
|
* export const users = pgTable("user", {
|
|
86
86
|
* id: text("id").primaryKey().$defaultFn(() => randomUUID()),
|
|
87
87
|
* name: text("name"),
|
|
88
|
-
* email: text("email").notNull()
|
|
88
|
+
* email: text("email").notNull(),
|
|
89
89
|
* emailVerified: timestamp("emailVerified", { mode: "date" }),
|
|
90
90
|
* image: text("image"),
|
|
91
91
|
* })
|
|
@@ -108,27 +108,23 @@ export { mysqlUsersTable, mysqlAccountsTable, mysqlSessionsTable, mysqlVerificat
|
|
|
108
108
|
* session_state: text("session_state"),
|
|
109
109
|
* },
|
|
110
110
|
* (account) => ({
|
|
111
|
-
* userIdIdx: index().on(account.userId),
|
|
112
111
|
* compoundKey: primaryKey({ columns: [account.provider, account.providerAccountId] }),
|
|
113
112
|
* })
|
|
114
113
|
* )
|
|
115
114
|
*
|
|
116
115
|
* export const sessions = pgTable("session", {
|
|
117
|
-
*
|
|
118
|
-
* sessionToken: text("sessionToken").notNull().unique(),
|
|
116
|
+
* sessionToken: text("sessionToken").primaryKey(),
|
|
119
117
|
* userId: text("userId")
|
|
120
118
|
* .notNull()
|
|
121
119
|
* .references(() => users.id, { onDelete: "cascade" }),
|
|
122
120
|
* expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
123
|
-
* }
|
|
124
|
-
* userIdIdx: index().on(session.userId)
|
|
125
|
-
* }))
|
|
121
|
+
* })
|
|
126
122
|
*
|
|
127
123
|
* export const verificationTokens = pgTable(
|
|
128
124
|
* "verificationToken",
|
|
129
125
|
* {
|
|
130
126
|
* identifier: text("identifier").notNull(),
|
|
131
|
-
* token: text("token").notNull()
|
|
127
|
+
* token: text("token").notNull(),
|
|
132
128
|
* expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
133
129
|
* },
|
|
134
130
|
* (vt) => ({
|
|
@@ -139,6 +135,8 @@ export { mysqlUsersTable, mysqlAccountsTable, mysqlSessionsTable, mysqlVerificat
|
|
|
139
135
|
*
|
|
140
136
|
* ### MySQL
|
|
141
137
|
*
|
|
138
|
+
* In MySQL, there's no `returning` clause, so in the `createUser` function, we first insert a new user and then search by `email` to get the user's data. To make the search faster, we suggest adding an index to the `email` column.
|
|
139
|
+
*
|
|
142
140
|
* ```ts title="schema.ts"
|
|
143
141
|
* import {
|
|
144
142
|
* int,
|
|
@@ -152,7 +150,7 @@ export { mysqlUsersTable, mysqlAccountsTable, mysqlSessionsTable, mysqlVerificat
|
|
|
152
150
|
* export const users = mysqlTable("user", {
|
|
153
151
|
* id: varchar("id", { length: 255 }).primaryKey().$defaultFn(() => randomUUID()),
|
|
154
152
|
* name: varchar("name", { length: 255 }),
|
|
155
|
-
* email: varchar("email", { length: 255 }).notNull()
|
|
153
|
+
* email: varchar("email", { length: 255 }).notNull(),
|
|
156
154
|
* emailVerified: timestamp("emailVerified", { mode: "date", fsp: 3 }),
|
|
157
155
|
* image: varchar("image", { length: 255 }),
|
|
158
156
|
* })
|
|
@@ -160,49 +158,45 @@ export { mysqlUsersTable, mysqlAccountsTable, mysqlSessionsTable, mysqlVerificat
|
|
|
160
158
|
* export const accounts = mysqlTable(
|
|
161
159
|
* "account",
|
|
162
160
|
* {
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
* })
|
|
161
|
+
* userId: varchar("userId", { length: 255 })
|
|
162
|
+
* .notNull()
|
|
163
|
+
* .references(() => users.id, { onDelete: "cascade" }),
|
|
164
|
+
* type: varchar("type", { length: 255 }).notNull(),
|
|
165
|
+
* provider: varchar("provider", { length: 255 }).notNull(),
|
|
166
|
+
* providerAccountId: varchar("providerAccountId", { length: 255 }).notNull(),
|
|
167
|
+
* refresh_token: varchar("refresh_token", { length: 255 }),
|
|
168
|
+
* access_token: varchar("access_token", { length: 255 }),
|
|
169
|
+
* expires_at: int("expires_at"),
|
|
170
|
+
* token_type: varchar("token_type", { length: 255 }),
|
|
171
|
+
* scope: varchar("scope", { length: 255 }),
|
|
172
|
+
* id_token: varchar("id_token", { length: 2048 }),
|
|
173
|
+
* session_state: varchar("session_state", { length: 255 }),
|
|
174
|
+
* },
|
|
175
|
+
* (account) => ({
|
|
176
|
+
* compoundKey: primaryKey({
|
|
177
|
+
columns: [account.provider, account.providerAccountId],
|
|
178
|
+
})
|
|
179
|
+
* })
|
|
183
180
|
* )
|
|
184
181
|
*
|
|
185
182
|
* export const sessions = mysqlTable("session", {
|
|
186
|
-
*
|
|
187
|
-
* sessionToken: varchar("sessionToken", { length: 255 }).notNull().unique(),
|
|
183
|
+
* sessionToken: varchar("sessionToken", { length: 255 }).primaryKey(),
|
|
188
184
|
* userId: varchar("userId", { length: 255 })
|
|
189
185
|
* .notNull()
|
|
190
186
|
* .references(() => users.id, { onDelete: "cascade" }),
|
|
191
187
|
* expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
192
|
-
* }
|
|
193
|
-
* userIdIdx: index('Session_userId_index').on(session.userId)
|
|
194
|
-
* }))
|
|
188
|
+
* })
|
|
195
189
|
*
|
|
196
190
|
* export const verificationTokens = mysqlTable(
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
191
|
+
* "verificationToken",
|
|
192
|
+
* {
|
|
193
|
+
* identifier: varchar("identifier", { length: 255 }).notNull(),
|
|
194
|
+
* token: varchar("token", { length: 255 }).notNull(),
|
|
195
|
+
* expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
196
|
+
* },
|
|
197
|
+
* (vt) => ({
|
|
198
|
+
* compoundKey: primaryKey({ columns: [vt.identifier, vt.token] }),
|
|
199
|
+
* })
|
|
206
200
|
* )
|
|
207
201
|
* ```
|
|
208
202
|
*
|
|
@@ -215,7 +209,7 @@ export { mysqlUsersTable, mysqlAccountsTable, mysqlSessionsTable, mysqlVerificat
|
|
|
215
209
|
* export const users = sqliteTable("user", {
|
|
216
210
|
* id: text("id").primaryKey().$defaultFn(() => randomUUID()),
|
|
217
211
|
* name: text("name"),
|
|
218
|
-
* email: text("email").notNull()
|
|
212
|
+
* email: text("email").notNull(),
|
|
219
213
|
* emailVerified: integer("emailVerified", { mode: "timestamp_ms" }),
|
|
220
214
|
* image: text("image"),
|
|
221
215
|
* })
|
|
@@ -240,39 +234,35 @@ export { mysqlUsersTable, mysqlAccountsTable, mysqlSessionsTable, mysqlVerificat
|
|
|
240
234
|
* (account) => ({
|
|
241
235
|
* compoundKey: primaryKey({
|
|
242
236
|
columns: [account.provider, account.providerAccountId],
|
|
243
|
-
})
|
|
244
|
-
userIdIdx: index('Account_userId_index').on(account.userId)
|
|
237
|
+
})
|
|
245
238
|
* })
|
|
246
239
|
* )
|
|
247
240
|
*
|
|
248
241
|
* export const sessions = sqliteTable("session", {
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
* }, (table) => ({
|
|
256
|
-
* userIdIdx: index('Session_userId_index').on(table.userId)
|
|
257
|
-
* }))
|
|
242
|
+
* sessionToken: text("sessionToken").primaryKey(),
|
|
243
|
+
* userId: text("userId")
|
|
244
|
+
* .notNull()
|
|
245
|
+
* .references(() => users.id, { onDelete: "cascade" }),
|
|
246
|
+
* expires: integer("expires", { mode: "timestamp_ms" }).notNull(),
|
|
247
|
+
* })
|
|
258
248
|
*
|
|
259
249
|
* export const verificationTokens = sqliteTable(
|
|
260
|
-
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
250
|
+
* "verificationToken",
|
|
251
|
+
* {
|
|
252
|
+
* identifier: text("identifier").notNull(),
|
|
253
|
+
* token: text("token").notNull(),
|
|
254
|
+
* expires: integer("expires", { mode: "timestamp_ms" }).notNull(),
|
|
255
|
+
* },
|
|
256
|
+
* (vt) => ({
|
|
257
|
+
* compoundKey: primaryKey({ columns: [vt.identifier, vt.token] }),
|
|
258
|
+
* })
|
|
269
259
|
* )
|
|
270
260
|
* ```
|
|
271
261
|
*
|
|
272
262
|
* ## Migrating your database
|
|
273
263
|
* With your schema now described in your code, you'll need to migrate your database to your schema.
|
|
274
264
|
*
|
|
275
|
-
* For full documentation on how to run migrations with Drizzle, [visit the Drizzle documentation](https://orm.drizzle.team/kit-docs/overview#running-migrations).
|
|
265
|
+
* For full documentation on how to run migrations with Drizzle, [visit the Drizzle documentation](https://orm.drizzle.team/kit-docs/overview#running-migrations) or check how to apply changes directly to the database with [push command](https://orm.drizzle.team/kit-docs/overview#prototyping-with-db-push).
|
|
276
266
|
*
|
|
277
267
|
* ---
|
|
278
268
|
*
|