-
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: health indicator for Prisma ORM (#2250) * chore: drop support for Node v12 BREAKING CHANGE: drop support for Node v12 * chore: fix prisma sample * chore: add prisma client as optional peer dependency * refactor(prisma): rename PrismaORM to PrismaHealthIndicator * chore(): release v10.0.0-beta.0 * chore: fix format * chore: add node v18 and v20 * chore: drop support for node v14 BREAKING CHANGE: drop support for node v14 * feat: upgrade to nest v10 * feat(deps): upgrade TypeScript to v5 * chore: update dependencies * feat(disk): prettify type information * chore(): release v10.0.0-beta.1 * Revert "feat(disk): prettify type information" This reverts commit e0b13aa. * chore: use --legacy-peer-deps in ci Revert once mikro-orm/nestjs#122 is resolved * chore: remove prisma timeout * chore: add debian openssl for prisma --------- Co-authored-by: Thalles Passos <[email protected]>
- Loading branch information
1 parent
6ecdc1f
commit 291bbed
Showing
42 changed files
with
11,520 additions
and
7,253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
tests/** | ||
lib/**/*.spec.ts | ||
lib/**/*.spec.ts | ||
e2e/prisma/generated/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ npm-debug.log | |
/test | ||
/coverage | ||
/.nyc_output | ||
e2e/prisma/generated | ||
|
||
# dist | ||
dist | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
e2e/prisma/generated/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import { INestApplication } from '@nestjs/common'; | ||
import { PrismaClient as MongoPrismaClient } from '../prisma/generated/mongodb'; | ||
import { PrismaClient as MySQLPrismaClient } from '../prisma/generated/mysql'; | ||
import { bootstrapTestingModule, DynamicHealthEndpointFn } from '../helper'; | ||
import * as request from 'supertest'; | ||
|
||
jest.setTimeout(300_000); | ||
|
||
describe('PrismaHealthIndicator', () => { | ||
let app: INestApplication; | ||
let setHealthEndpoint: DynamicHealthEndpointFn; | ||
|
||
describe('mongodb', () => { | ||
beforeEach( | ||
() => | ||
(setHealthEndpoint = bootstrapTestingModule() | ||
.withPrisma() | ||
.andMongo().setHealthEndpoint), | ||
); | ||
|
||
describe('#pingCheck', () => { | ||
it('should check if the prisma is available', async () => { | ||
app = await setHealthEndpoint(({ healthCheck, prisma }) => | ||
healthCheck.check([ | ||
async () => | ||
prisma.pingCheck('prismamongo', new MongoPrismaClient()), | ||
]), | ||
).start(); | ||
|
||
return request(app.getHttpServer()) | ||
.get('/health') | ||
.expect(200) | ||
.expect({ | ||
status: 'ok', | ||
info: { prismamongo: { status: 'up' } }, | ||
error: {}, | ||
details: { prismamongo: { status: 'up' } }, | ||
}); | ||
}); | ||
|
||
it('should throw an error if runs into timeout error', async () => { | ||
app = await setHealthEndpoint(({ healthCheck, prisma }) => | ||
healthCheck.check([ | ||
async () => | ||
prisma.pingCheck('prismamongo', new MongoPrismaClient(), { | ||
timeout: 1, | ||
}), | ||
]), | ||
).start(); | ||
|
||
return request(app.getHttpServer()) | ||
.get('/health') | ||
.expect(503) | ||
.expect({ | ||
status: 'error', | ||
info: {}, | ||
error: { | ||
prismamongo: { | ||
status: 'down', | ||
message: 'timeout of 1ms exceeded', | ||
}, | ||
}, | ||
details: { | ||
prismamongo: { | ||
status: 'down', | ||
message: 'timeout of 1ms exceeded', | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('mysql', () => { | ||
beforeEach( | ||
() => | ||
(setHealthEndpoint = bootstrapTestingModule() | ||
.withPrisma() | ||
.andMySql().setHealthEndpoint), | ||
); | ||
|
||
describe('#pingCheck', () => { | ||
it('should check if the prisma is available', async () => { | ||
app = await setHealthEndpoint(({ healthCheck, prisma }) => | ||
healthCheck.check([ | ||
async () => prisma.pingCheck('prisma', new MySQLPrismaClient()), | ||
]), | ||
).start(); | ||
|
||
return request(app.getHttpServer()) | ||
.get('/health') | ||
.expect({ | ||
status: 'ok', | ||
info: { prisma: { status: 'up' } }, | ||
error: {}, | ||
details: { prisma: { status: 'up' } }, | ||
}); | ||
}); | ||
|
||
it('should throw an error if runs into timeout error', async () => { | ||
app = await setHealthEndpoint(({ healthCheck, prisma }) => | ||
healthCheck.check([ | ||
async () => | ||
prisma.pingCheck('prisma', new MySQLPrismaClient(), { | ||
timeout: 1, | ||
}), | ||
]), | ||
).start(); | ||
|
||
return request(app.getHttpServer()) | ||
.get('/health') | ||
.expect(503) | ||
.expect({ | ||
status: 'error', | ||
error: { | ||
prisma: { status: 'down', message: 'timeout of 1ms exceeded' }, | ||
}, | ||
info: {}, | ||
details: { | ||
prisma: { status: 'down', message: 'timeout of 1ms exceeded' }, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
afterEach(async () => await app.close()); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
declare module '*prisma/generated/mongodb' { | ||
class PrismaClient { | ||
$runCommandRaw(command: unknown): any; | ||
} | ||
} | ||
|
||
declare module '*prisma/generated/mysql' { | ||
class PrismaClient { | ||
$queryRawUnsafe(query: string): any; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { execSync } from 'child_process'; | ||
|
||
execSync(`npx [email protected] generate --schema e2e/prisma/schema-mysql.prisma`); | ||
execSync(`npx [email protected] generate --schema e2e/prisma/schema-mongodb.prisma`); |
Oops, something went wrong.