Skip to content

Commit 062acab

Browse files
fix(transactional-adapter-prisma): updates Prisma peer dependency to v7 (#431)
* build(deps-peer): updates Prisma peer dependency to v7 Extends the supported versions of Prisma in peer dependencies to include versions greater than 4 and less than 8. This allows users to upgrade to newer Prisma versions while maintaining compatibility with the transactional adapter. * build(deps-dev): upgrade Prisma to v7 in tests
1 parent beeeb45 commit 062acab

File tree

11 files changed

+574
-78
lines changed

11 files changed

+574
-78
lines changed

packages/transactional-adapters/transactional-adapter-prisma/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,21 @@
4747
},
4848
"peerDependencies": {
4949
"@nestjs-cls/transactional": "workspace:^3.1.1",
50-
"@prisma/client": "> 4 < 7",
50+
"@prisma/client": "> 4 < 8",
5151
"nestjs-cls": "workspace:^6.1.0",
52-
"prisma": "> 4 < 7"
52+
"prisma": "> 4 < 8"
5353
},
5454
"devDependencies": {
5555
"@nestjs/cli": "^11.0.10",
5656
"@nestjs/common": "^11.1.6",
5757
"@nestjs/core": "^11.1.6",
5858
"@nestjs/testing": "^11.1.6",
59-
"@prisma/client": "^6.19.0",
59+
"@prisma/adapter-pg": "^7.1.0",
60+
"@prisma/client": "^7.1.0",
6061
"@types/jest": "^29.5.14",
6162
"@types/node": "^22.15.24",
6263
"jest": "^29.7.0",
63-
"prisma": "^6.19.0",
64+
"prisma": "^7.1.0",
6465
"reflect-metadata": "^0.2.2",
6566
"rimraf": "^6.0.1",
6667
"rxjs": "^7.8.2",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineConfig } from 'prisma/config';
2+
3+
export default defineConfig({
4+
datasource: {
5+
url: process.env.DATA_SOURCE_URL ?? '',
6+
},
7+
});

packages/transactional-adapters/transactional-adapter-prisma/prisma/migrations/20240119144105_init/migration.sql

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- CreateTable
2+
CREATE TABLE "User" (
3+
"id" SERIAL NOT NULL,
4+
"email" TEXT NOT NULL,
5+
"name" TEXT,
6+
7+
CONSTRAINT "User_pkey" PRIMARY KEY ("id")
8+
);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Please do not edit this file manually
2-
# It should be added in your version-control system (i.e. Git)
3-
provider = "sqlite"
2+
# It should be added in your version-control system (e.g., Git)
3+
provider = "postgresql"

packages/transactional-adapters/transactional-adapter-prisma/prisma/schema.prisma

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ generator client {
66
}
77

88
datasource db {
9-
provider = "sqlite"
10-
url = env("DATA_SOURCE_URL")
9+
provider = "postgres"
1110
}
1211

1312
model User {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
services:
2+
postgresql-test-db-custom-client:
3+
image: postgres:15
4+
ports:
5+
- 5449:5432
6+
environment:
7+
POSTGRES_USER: postgres
8+
POSTGRES_PASSWORD: postgres
9+
POSTGRES_DB: postgres
10+
healthcheck:
11+
test: ['CMD-SHELL', 'pg_isready -U postgres']
12+
interval: 1s
13+
timeout: 1s
14+
retries: 5
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
services:
2+
postgresql-test-db:
3+
image: postgres:15
4+
ports:
5+
- 5448:5432
6+
environment:
7+
POSTGRES_USER: postgres
8+
POSTGRES_PASSWORD: postgres
9+
POSTGRES_DB: postgres
10+
healthcheck:
11+
test: ['CMD-SHELL', 'pg_isready -U postgres']
12+
interval: 1s
13+
timeout: 1s
14+
retries: 5

packages/transactional-adapters/transactional-adapter-prisma/test/transactional-adapter-prisma-custom-client.spec.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ import { PrismaClient } from '@prisma/client';
1010
import { execSync } from 'child_process';
1111
import { ClsModule } from 'nestjs-cls';
1212
import { TransactionalAdapterPrisma } from '../src';
13+
import { PrismaPg } from '@prisma/adapter-pg';
1314

14-
process.env.DATA_SOURCE_URL = 'file:../tmp/test-custom.db';
15+
process.env.DATA_SOURCE_URL =
16+
'postgres://postgres:postgres@localhost:5449/postgres';
1517

16-
const prisma = new PrismaClient();
18+
const prisma = new PrismaClient({
19+
adapter: new PrismaPg({
20+
connectionString: process.env.DATA_SOURCE_URL ?? '',
21+
}),
22+
});
1723
const customPrismaClient = prisma.$extends({
1824
model: {
1925
user: {
@@ -93,6 +99,14 @@ describe('Transactional', () => {
9399
let txHost: TransactionHost<TransactionalAdapterPrisma<CustomPrismaClient>>;
94100

95101
beforeAll(async () => {
102+
execSync(
103+
'docker compose -f test/docker-compose-custom-client.yml up -d --quiet-pull --wait',
104+
{
105+
stdio: 'inherit',
106+
cwd: process.cwd(),
107+
},
108+
);
109+
96110
execSync('yarn prisma migrate reset --force', { env: process.env });
97111
});
98112

packages/transactional-adapters/transactional-adapter-prisma/test/transactional-adapter-prisma.spec.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ import {
99
import { Injectable, Module } from '@nestjs/common';
1010
import { Test, TestingModule } from '@nestjs/testing';
1111
import { Prisma, PrismaClient } from '@prisma/client';
12+
import { PrismaPg } from '@prisma/adapter-pg';
1213
import { execSync } from 'child_process';
1314
import { ClsModule } from 'nestjs-cls';
1415
import { TransactionalAdapterPrisma } from '../src';
1516

16-
process.env.DATA_SOURCE_URL = 'file:../tmp/test.db';
17+
process.env.DATA_SOURCE_URL =
18+
'postgres://postgres:postgres@localhost:5448/postgres';
1719

1820
@Injectable()
1921
class UserRepository {
@@ -109,7 +111,17 @@ class UserService {
109111
}
110112

111113
@Module({
112-
providers: [PrismaClient],
114+
providers: [
115+
{
116+
provide: PrismaClient,
117+
useFactory: () =>
118+
new PrismaClient({
119+
adapter: new PrismaPg({
120+
connectionString: process.env.DATA_SOURCE_URL ?? '',
121+
}),
122+
}),
123+
},
124+
],
113125
exports: [PrismaClient],
114126
})
115127
class PrismaModule {}
@@ -123,7 +135,7 @@ class PrismaModule {}
123135
imports: [PrismaModule],
124136
adapter: new TransactionalAdapterPrisma({
125137
prismaInjectionToken: PrismaClient,
126-
sqlFlavor: 'sqlite',
138+
sqlFlavor: 'postgresql',
127139
}),
128140
enableTransactionProxy: true,
129141
}),
@@ -140,6 +152,14 @@ describe('Transactional', () => {
140152
let prisma: PrismaClient;
141153

142154
beforeAll(async () => {
155+
execSync(
156+
'docker compose -f test/docker-compose.yml up -d --quiet-pull --wait',
157+
{
158+
stdio: 'inherit',
159+
cwd: process.cwd(),
160+
},
161+
);
162+
143163
execSync('yarn prisma migrate reset --force', { env: process.env });
144164
});
145165

@@ -186,6 +206,7 @@ describe('Transactional', () => {
186206
const users = await prisma.user.findMany();
187207
expect(users).toEqual(expect.arrayContaining([r1]));
188208
});
209+
189210
it('should run a transaction with the specified options with a function wrapper', async () => {
190211
const { r1, r2, r3 } =
191212
await callingService.transactionWithFunctionWrapper();

0 commit comments

Comments
 (0)