first commit
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user