forked from mtusi2026/mtusi2026lab4
feat(storage): add RustFS attachments and presigned uploads
Add two API replicas, safe object reconciliation, upload validation, regression tests and documented load experiments.
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
import { PrismaService } from './prisma.service';
|
||||
|
||||
@Global()
|
||||
@Module({ providers: [PrismaService], exports: [PrismaService] })
|
||||
export class PrismaModule {}
|
||||
@@ -0,0 +1,42 @@
|
||||
import 'dotenv/config';
|
||||
import {
|
||||
Injectable,
|
||||
type OnModuleDestroy,
|
||||
type OnModuleInit,
|
||||
} from '@nestjs/common';
|
||||
import { PrismaPg } from '@prisma/adapter-pg';
|
||||
import { PrismaClient } from '../generated/prisma/client';
|
||||
|
||||
@Injectable()
|
||||
export class PrismaService
|
||||
extends PrismaClient
|
||||
implements OnModuleInit, OnModuleDestroy
|
||||
{
|
||||
constructor() {
|
||||
const connectionString = process.env.DATABASE_URL;
|
||||
if (!connectionString) throw new Error('DATABASE_URL is required');
|
||||
const poolMax = Number(process.env.DB_POOL_MAX ?? 15);
|
||||
if (!Number.isSafeInteger(poolMax) || poolMax < 1) {
|
||||
throw new Error('DB_POOL_MAX must be a positive integer');
|
||||
}
|
||||
super({
|
||||
adapter: new PrismaPg({
|
||||
connectionString,
|
||||
max: poolMax,
|
||||
connectionTimeoutMillis: 5000,
|
||||
query_timeout: 5000,
|
||||
idleTimeoutMillis: 30000,
|
||||
options: '-c statement_timeout=5000',
|
||||
}),
|
||||
transactionOptions: { maxWait: 5000, timeout: 10000 },
|
||||
});
|
||||
}
|
||||
|
||||
async onModuleInit(): Promise<void> {
|
||||
await this.$connect();
|
||||
}
|
||||
|
||||
async onModuleDestroy(): Promise<void> {
|
||||
await this.$disconnect();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user