You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* You need to use at least Prisma 2.26.0. Create a schema file in `prisma/schema.prisma` similar to this one:
51
-
*
52
-
* > This schema is adapted for use in Prisma and based upon our main [schema](https://authjs.dev/reference/core/adapters#models)
53
-
*
54
-
* ```json title="schema.prisma"
55
-
* datasource db {
56
-
* provider = "postgresql"
57
-
* url = env("DATABASE_URL")
58
-
* shadowDatabaseUrl = env("SHADOW_DATABASE_URL") // Only needed when using a cloud provider that doesn't support the creation of new databases, like Heroku. Learn more: https://pris.ly/d/migrate-shadow
59
-
* }
60
-
*
61
-
* generator client {
62
-
* provider = "prisma-client-js"
63
-
* previewFeatures = ["referentialActions"] // You won't need this in Prisma 3.X or higher.
64
-
* }
65
-
*
66
-
* model Account {
67
-
* id String @id@default(cuid())
68
-
* userId String
69
-
* type String
70
-
* provider String
71
-
* providerAccountId String
72
-
* refresh_token String? @db.Text
73
-
* access_token String? @db.Text
74
-
* expires_at Int?
75
-
* token_type String?
76
-
* scope String?
77
-
* id_token String? @db.Text
78
-
* session_state String?
79
-
*
80
-
* user User @relation(fields: [userId], references: [id], onDelete: Cascade)
81
-
*
82
-
* @@unique([provider, providerAccountId])
83
-
* }
84
-
*
85
-
* model Session {
86
-
* id String @id@default(cuid())
87
-
* sessionToken String @unique
88
-
* userId String
89
-
* expires DateTime
90
-
* user User @relation(fields: [userId], references: [id], onDelete: Cascade)
91
-
* }
92
-
*
93
-
* model User {
94
-
* id String @id@default(cuid())
95
-
* name String?
96
-
* email String? @unique
97
-
* emailVerified DateTime?
98
-
* image String?
99
-
* accounts Account[]
100
-
* sessions Session[]
101
-
* }
102
-
*
103
-
* model VerificationToken {
104
-
* identifier String
105
-
* token String @unique
106
-
* expires DateTime
107
-
*
108
-
* @@unique([identifier, token])
109
-
* }
110
-
* ```
111
-
*
112
-
* :::note
113
-
* When using the MySQL connector for Prisma, the [Prisma `String` type](https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#string) gets mapped to `varchar(191)` which may not be long enough to store fields such as `id_token` in the `Account` model. This can be avoided by explicitly using the `Text` type with `@db.Text`.
114
-
* :::
115
-
*
116
-
*
117
-
* ### Create the Prisma schema with `prisma migrate`
118
-
*
119
-
* This will create an SQL migration file and execute it:
120
-
*
121
-
* ```
122
-
* npx prisma migrate dev
123
-
* ```
124
-
*
125
-
* Note that you will need to specify your database connection string in the environment variable `DATABASE_URL`. You can do this by setting it in a `.env` file at the root of your project.
126
-
*
127
-
* To learn more about [Prisma Migrate](https://www.prisma.io/migrate), check out the [Migrate docs](https://www.prisma.io/docs/concepts/components/prisma-migrate).
128
-
*
129
-
* ### Generating the Prisma Client
130
-
*
131
-
* Once you have saved your schema, use the Prisma CLI to generate the Prisma Client:
132
-
*
133
-
* ```
134
-
* npx prisma generate
135
-
* ```
136
-
*
137
-
* To configure your database to use the new schema (i.e. create tables and columns) use the `prisma migrate` command:
138
-
*
139
-
* ```
140
-
* npx prisma migrate dev
141
-
* ```
142
-
*
143
-
* ### MongoDB support
144
-
*
145
-
* Prisma supports MongoDB, and so does Auth.js. Following the instructions of the [Prisma documentation](https://www.prisma.io/docs/concepts/database-connectors/mongodb) on the MongoDB connector, things you have to change are:
146
-
*
147
-
* 1. Make sure that the id fields are mapped correctly
148
-
*
149
-
* ```prisma
150
-
* id String @id @default(auto()) @map("_id") @db.ObjectId
151
-
* ```
152
-
*
153
-
* 2. The Native database type attribute to `@db.String` from `@db.Text` and userId to `@db.ObjectId`.
154
-
*
155
-
* ```prisma
156
-
* user_id String @db.ObjectId
157
-
* refresh_token String? @db.String
158
-
* access_token String? @db.String
159
-
* id_token String? @db.String
160
-
* ```
161
-
*
162
-
* Everything else should be the same.
163
-
*
164
-
* ### Naming Conventions
165
-
*
166
-
* If mixed snake_case and camelCase column names is an issue for you and/or your underlying database system, we recommend using Prisma's `@map()`([see the documentation here](https://www.prisma.io/docs/concepts/components/prisma-schema/names-in-underlying-database)) feature to change the field names. This won't affect Auth.js, but will allow you to customize the column names to whichever naming convention you wish.
167
-
*
168
-
* For example, moving to `snake_case` and plural table names.
0 commit comments