Skip to content
This repository has been archived by the owner on Jul 17, 2022. It is now read-only.

Commit

Permalink
feat(prisma): use new Adapter interface (#72)
Browse files Browse the repository at this point in the history
* feat(prisma): use new Adapter interface

* fix(prisma): fix TS errors

* fix(prisma): make all ids string

* docs(prisma): update README to reflect new schema

* fix(core): update next-auth types

* chore(prisma): remove comment

* chore(prisma): remove unused dependencies

* test(prisma): fix tests

* fix(prisma): add new db migration

* test(prisma): fix tests
  • Loading branch information
balazsorban44 authored Apr 29, 2021
1 parent edff780 commit e7a7690
Show file tree
Hide file tree
Showing 10 changed files with 1,817 additions and 6,206 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"lerna": "^3.22.1",
"lint-staged": ">=10",
"next-auth": "latest",
"prettier": "^2.2.1"
"prettier": "^2.2.1",
"typescript": "^4.2.4"
},
"prettier": {
"semi": false
Expand Down
24 changes: 12 additions & 12 deletions packages/prisma/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

```prisma filename="schema.prisma"
model Account {
id Int @id @default(autoincrement())
userId Int
id String @id @default(cuid())
userId String
providerType String
providerId String
providerAccountId String
Expand All @@ -18,8 +18,8 @@ model Account {
}
model Session {
id Int @id @default(autoincrement())
userId Int
id String @id @default(cuid())
userId String
expires DateTime
sessionToken String @unique
accessToken String @unique
Expand All @@ -29,7 +29,7 @@ model Session {
}
model User {
id Int @id @default(autoincrement())
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
Expand All @@ -41,7 +41,7 @@ model User {
}
model VerificationRequest {
id Int @id @default(autoincrement())
id String @id @default(cuid())
identifier String
token String @unique
expires DateTime
Expand All @@ -58,10 +58,10 @@ Changes from the original Prisma Adapter
```diff
model Account {
- id Int @default(autoincrement()) @id
+ id Int @id @default(autoincrement())
+ id String @id @default(cuid())
- compoundId String @unique @map(name: "compound_id")
- userId Int @map(name: "user_id")
+ userId Int
+ userId String
+ user User @relation(fields: [userId], references: [id])
- providerType String @map(name: "provider_type")
+ providerType String
Expand Down Expand Up @@ -89,9 +89,9 @@ Changes from the original Prisma Adapter

model Session {
- id Int @default(autoincrement()) @id
+ id Int @id @default(autoincrement())
+ id String @id @default(cuid())
- userId Int @map(name: "user_id")
+ userId Int
+ userId String
+ user User @relation(fields: [userId], references: [id])
expires DateTime
- sessionToken String @unique @map(name: "session_token")
Expand All @@ -108,7 +108,7 @@ Changes from the original Prisma Adapter

model User {
- id Int @default(autoincrement()) @id
+ id Int @id @default(autoincrement())
+ id String @id @default(cuid())
name String?
email String? @unique
- emailVerified DateTime? @map(name: "email_verified")
Expand All @@ -126,7 +126,7 @@ Changes from the original Prisma Adapter

model VerificationRequest {
- id Int @default(autoincrement()) @id
+ id Int @id @default(autoincrement())
+ id String @id @default(cuid())
identifier String
token String @unique
expires DateTime
Expand Down
12 changes: 3 additions & 9 deletions packages/prisma/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,15 @@
],
"peerDependencies": {
"@prisma/client": ">=2.16.0",
"next-auth": ">=3.15.13"
},
"dependencies": {
"crypto": "^1.0.1",
"lru-cache": "^6.0.0"
"next-auth": ">=3.19.2"
},
"dependencies": {},
"devDependencies": {
"@prisma/client": "^2.16.0",
"@types/jest": "^26.0.20",
"@types/lru-cache": "^5.1.0",
"jest": "^26.6.3",
"next-auth": "^3.1.0",
"prettier": "^2.2.1",
"prisma": "^2.16.0",
"ts-jest": "^26.4.4",
"typescript": "^4.1.3"
"ts-jest": "^26.4.4"
}
}
71 changes: 71 additions & 0 deletions packages/prisma/prisma/migrations/20210428211515_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
Warnings:
- The primary key for the `Account` table will be changed. If it partially fails, the table could be left without primary key constraint.
- The primary key for the `Session` table will be changed. If it partially fails, the table could be left without primary key constraint.
- The primary key for the `User` table will be changed. If it partially fails, the table could be left without primary key constraint.
- The primary key for the `VerificationRequest` table will be changed. If it partially fails, the table could be left without primary key constraint.
*/
-- RedefineTables
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_Account" (
"id" TEXT NOT NULL PRIMARY KEY,
"userId" TEXT NOT NULL,
"providerType" TEXT NOT NULL,
"providerId" TEXT NOT NULL,
"providerAccountId" TEXT NOT NULL,
"refreshToken" TEXT,
"accessToken" TEXT,
"accessTokenExpires" DATETIME,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL,
FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_Account" ("id", "userId", "providerType", "providerId", "providerAccountId", "refreshToken", "accessToken", "accessTokenExpires", "createdAt", "updatedAt") SELECT "id", "userId", "providerType", "providerId", "providerAccountId", "refreshToken", "accessToken", "accessTokenExpires", "createdAt", "updatedAt" FROM "Account";
DROP TABLE "Account";
ALTER TABLE "new_Account" RENAME TO "Account";
CREATE UNIQUE INDEX "Account.providerId_providerAccountId_unique" ON "Account"("providerId", "providerAccountId");
CREATE TABLE "new_Session" (
"id" TEXT NOT NULL PRIMARY KEY,
"userId" TEXT NOT NULL,
"expires" DATETIME NOT NULL,
"sessionToken" TEXT NOT NULL,
"accessToken" TEXT NOT NULL,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL,
FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_Session" ("id", "userId", "expires", "sessionToken", "accessToken", "createdAt", "updatedAt") SELECT "id", "userId", "expires", "sessionToken", "accessToken", "createdAt", "updatedAt" FROM "Session";
DROP TABLE "Session";
ALTER TABLE "new_Session" RENAME TO "Session";
CREATE UNIQUE INDEX "Session.sessionToken_unique" ON "Session"("sessionToken");
CREATE UNIQUE INDEX "Session.accessToken_unique" ON "Session"("accessToken");
CREATE TABLE "new_User" (
"id" TEXT NOT NULL PRIMARY KEY,
"name" TEXT,
"email" TEXT,
"emailVerified" DATETIME,
"image" TEXT,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL
);
INSERT INTO "new_User" ("id", "name", "email", "emailVerified", "image", "createdAt", "updatedAt") SELECT "id", "name", "email", "emailVerified", "image", "createdAt", "updatedAt" FROM "User";
DROP TABLE "User";
ALTER TABLE "new_User" RENAME TO "User";
CREATE UNIQUE INDEX "User.email_unique" ON "User"("email");
CREATE TABLE "new_VerificationRequest" (
"id" TEXT NOT NULL PRIMARY KEY,
"identifier" TEXT NOT NULL,
"token" TEXT NOT NULL,
"expires" DATETIME NOT NULL,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL
);
INSERT INTO "new_VerificationRequest" ("id", "identifier", "token", "expires", "createdAt", "updatedAt") SELECT "id", "identifier", "token", "expires", "createdAt", "updatedAt" FROM "VerificationRequest";
DROP TABLE "VerificationRequest";
ALTER TABLE "new_VerificationRequest" RENAME TO "VerificationRequest";
CREATE UNIQUE INDEX "VerificationRequest.token_unique" ON "VerificationRequest"("token");
CREATE UNIQUE INDEX "VerificationRequest.identifier_token_unique" ON "VerificationRequest"("identifier", "token");
PRAGMA foreign_key_check;
PRAGMA foreign_keys=ON;
1 change: 1 addition & 0 deletions packages/prisma/prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "sqlite"
12 changes: 6 additions & 6 deletions packages/prisma/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ generator client {
provider = "prisma-client-js"
}
model Account {
id Int @id @default(autoincrement())
userId Int
id String @id @default(cuid())
userId String
providerType String
providerId String
providerAccountId String
Expand All @@ -21,8 +21,8 @@ model Account {
}

model Session {
id Int @id @default(autoincrement())
userId Int
id String @id @default(cuid())
userId String
expires DateTime
sessionToken String @unique
accessToken String @unique
Expand All @@ -32,7 +32,7 @@ model Session {
}

model User {
id Int @id @default(autoincrement())
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
Expand All @@ -44,7 +44,7 @@ model User {
}

model VerificationRequest {
id Int @id @default(autoincrement())
id String @id @default(cuid())
identifier String
token String @unique
expires DateTime
Expand Down
Loading

0 comments on commit e7a7690

Please sign in to comment.