mirror of
https://github.com/documenso/documenso.git
synced 2026-07-25 01:15:49 +10:00
feat: support optional read replicas (#2540)
This commit is contained in:
@@ -2,6 +2,7 @@ import { expect, test } from '@playwright/test';
|
||||
import { WebhookCallStatus, WebhookTriggerEvents } from '@prisma/client';
|
||||
|
||||
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
||||
import { alphaid } from '@documenso/lib/universal/id';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
import { seedBlankDocument } from '@documenso/prisma/seed/documents';
|
||||
import { seedUser } from '@documenso/prisma/seed/users';
|
||||
@@ -279,8 +280,8 @@ test('[WEBHOOKS]: cannot see unrelated webhooks', async ({ page }) => {
|
||||
const user1Data = await seedUser();
|
||||
const user2Data = await seedUser();
|
||||
|
||||
const webhookUrl1 = `https://example.com/webhook-team1-${Date.now()}`;
|
||||
const webhookUrl2 = `https://example.com/webhook-team2-${Date.now()}`;
|
||||
const webhookUrl1 = `https://example.com/webhook-team1-${alphaid(12)}`;
|
||||
const webhookUrl2 = `https://example.com/webhook-team2-${alphaid(12)}`;
|
||||
|
||||
// Create webhooks for both teams with DOCUMENT_CREATED event
|
||||
const webhook1 = await seedWebhook({
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/// <reference types="@documenso/prisma/types/types.d.ts" />
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { readReplicas } from '@prisma/extension-read-replicas';
|
||||
import { Kysely, PostgresAdapter, PostgresIntrospector, PostgresQueryCompiler } from 'kysely';
|
||||
import kyselyExtension from 'prisma-extension-kysely';
|
||||
|
||||
@@ -7,7 +8,7 @@ import type { DB } from './generated/types';
|
||||
import { getDatabaseUrl } from './helper';
|
||||
import { remember } from './utils/remember';
|
||||
|
||||
export const prisma = remember(
|
||||
const prisma = remember(
|
||||
'prisma',
|
||||
() =>
|
||||
new PrismaClient({
|
||||
@@ -65,4 +66,25 @@ export const prismaWithLogging = remember('prismaWithLogging', () => {
|
||||
return client;
|
||||
});
|
||||
|
||||
export const prismaWithReplicas = remember('prismaWithReplicas', () => {
|
||||
if (!process.env.NEXT_PRIVATE_DATABASE_REPLICA_URLS) {
|
||||
return prisma;
|
||||
}
|
||||
|
||||
const replicaUrls = process.env.NEXT_PRIVATE_DATABASE_REPLICA_URLS.split(',').map((url) =>
|
||||
url.trim(),
|
||||
);
|
||||
|
||||
// !: Nasty hack, means we can't do any fancy $primary/$replica queries
|
||||
// !: but it is acceptable since not all setups will have replicas anyway.
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
return prisma.$extends(
|
||||
readReplicas({
|
||||
url: replicaUrls,
|
||||
}),
|
||||
) as unknown as typeof prisma;
|
||||
});
|
||||
|
||||
export { prismaWithReplicas as prisma };
|
||||
|
||||
export { sql } from 'kysely';
|
||||
|
||||
Reference in New Issue
Block a user