fix(infra): pass PostgreSQL config to Prisma adapter
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import { PrismaPg } from '@prisma/adapter-pg';
|
import { PrismaPg } from '@prisma/adapter-pg';
|
||||||
import { Pool } from 'pg';
|
|
||||||
|
|
||||||
export type PostgresLogLevel = 'query' | 'info' | 'warn' | 'error';
|
export type PostgresLogLevel = 'query' | 'info' | 'warn' | 'error';
|
||||||
|
|
||||||
@@ -89,11 +88,13 @@ export const createPostgresConnector = <TClient>(
|
|||||||
): PostgresConnector<TClient> => {
|
): PostgresConnector<TClient> => {
|
||||||
const schema =
|
const schema =
|
||||||
extractSchemaFromDatabaseUrl(config.url) ?? process.env.POSTGRES_SCHEMA ?? process.env.DATABASE_SCHEMA;
|
extractSchemaFromDatabaseUrl(config.url) ?? process.env.POSTGRES_SCHEMA ?? process.env.DATABASE_SCHEMA;
|
||||||
const pool = new Pool({
|
const adapter = new PrismaPg(
|
||||||
|
{
|
||||||
connectionString: config.url,
|
connectionString: config.url,
|
||||||
...(schema ? { options: `-c search_path=${schema}` } : {}),
|
...(schema ? { options: `-c search_path=${schema}` } : {}),
|
||||||
});
|
},
|
||||||
const adapter = new PrismaPg(pool, schema ? { schema } : undefined);
|
schema ? { schema } : undefined
|
||||||
|
);
|
||||||
const prisma = createClient({
|
const prisma = createClient({
|
||||||
adapter,
|
adapter,
|
||||||
log: config.log,
|
log: config.log,
|
||||||
@@ -102,9 +103,6 @@ export const createPostgresConnector = <TClient>(
|
|||||||
return {
|
return {
|
||||||
prisma,
|
prisma,
|
||||||
connect: () => (prisma as { $connect: () => Promise<void> }).$connect(),
|
connect: () => (prisma as { $connect: () => Promise<void> }).$connect(),
|
||||||
disconnect: async () => {
|
disconnect: () => (prisma as { $disconnect: () => Promise<void> }).$disconnect(),
|
||||||
await (prisma as { $disconnect: () => Promise<void> }).$disconnect();
|
|
||||||
await pool.end();
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user