28 lines
807 B
TypeScript
28 lines
807 B
TypeScript
import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
|
|
import { ConfigService } from '@nestjs/config';
|
|
import { PrismaClient } from '@prisma/client';
|
|
|
|
/**
|
|
* Conectada via `DATABASE_URL_MASTER` (role `app_master`, LOGIN + BYPASSRLS).
|
|
* Usada pelo painel master, que precisa enxergar dados de todos os tenants
|
|
* sem passar pelas policies de RLS.
|
|
*/
|
|
@Injectable()
|
|
export class PrismaMasterService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
|
|
constructor(configService: ConfigService) {
|
|
super({
|
|
datasourceUrl:
|
|
configService.get<string>('DATABASE_URL_MASTER') ??
|
|
configService.get<string>('DATABASE_URL'),
|
|
});
|
|
}
|
|
|
|
async onModuleInit() {
|
|
await this.$connect();
|
|
}
|
|
|
|
async onModuleDestroy() {
|
|
await this.$disconnect();
|
|
}
|
|
}
|