Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
Fix for schema selection in pg adapter.
Mike Caoe610de383aac
diff --git a/package.json b/package.jsonindex 9112b3348..f4ccbc640 100644--- a/package.json+++ b/package.json@@ -151,7 +151,7 @@"@types/react-window": "^1.8.8","@typescript-eslint/eslint-plugin": "^8.41.0","@typescript-eslint/parser": "^8.41.0",- "@umami/prisma-client": "^0.19.0",+ "@umami/prisma-client": "^0.20.0","babel-plugin-react-compiler": "19.1.0-rc.2","cross-env": "^10.0.0","cypress": "^13.6.6",diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex f5176e1ca..865d02cf1 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -247,8 +247,8 @@ importers:specifier: ^8.41.0version: 8.41.0([email protected])([email protected])'@umami/prisma-client':- specifier: ^0.19.0- version: 0.19.0(@prisma/[email protected])(@prisma/[email protected]([email protected]([email protected]))([email protected]))(@prisma/[email protected](@prisma/[email protected]([email protected]([email protected]))([email protected])))+ specifier: ^0.20.0+ version: 0.20.0(@prisma/[email protected])(@prisma/[email protected]([email protected]([email protected]))([email protected]))(@prisma/[email protected](@prisma/[email protected]([email protected]([email protected]))([email protected])))babel-plugin-react-compiler:specifier: 19.1.0-rc.2version: 19.1.0-rc.2@@ -2728,8 +2728,8 @@ packages:resolution: {integrity: sha512-+GeGMebMCy0elMNg67LRNoVnUFPIm37iu5CmHESVx56/9Jsfdpsvbv605DQ81Pi/x11IdKUsS5nzgTYbCQU9fg==}engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}- '@umami/[email protected]':- resolution: {integrity: sha512-Vnys7MMAPexxmxrC+0q68B/iYmM1LFaP9RjKjffHbLfgZJ3moklJ2ea91cr8+m0CA3+3mqN38WEJI/o/ohOxYQ==}+ '@umami/[email protected]':+ resolution: {integrity: sha512-zcLzdSq+NJa/s4xZkzktreuuxmbAET7GAizO0LU+AVg3k9k4stEulvWUfBg48fC/iBRjz0AfOnHsuXDIHKN5Xw==}peerDependencies:'@prisma/adapter-pg': ^6.1.0'@prisma/client': ^6.1.0@@ -10313,7 +10313,7 @@ snapshots:'@typescript-eslint/types': 8.41.0eslint-visitor-keys: 4.2.1- '@umami/[email protected](@prisma/[email protected])(@prisma/[email protected]([email protected]([email protected]))([email protected]))(@prisma/[email protected](@prisma/[email protected]([email protected]([email protected]))([email protected])))':+ '@umami/[email protected](@prisma/[email protected])(@prisma/[email protected]([email protected]([email protected]))([email protected]))(@prisma/[email protected](@prisma/[email protected]([email protected]([email protected]))([email protected])))':dependencies:'@prisma/adapter-pg': 6.16.0diff --git a/src/app/api/websites/[websiteId]/stats/route.ts b/src/app/api/websites/[websiteId]/stats/route.tsindex f3b1a7081..7041f484c 100644--- a/src/app/api/websites/[websiteId]/stats/route.ts+++ b/src/app/api/websites/[websiteId]/stats/route.ts@@ -40,5 +40,5 @@ export async function GET(endDate,});- return json({ ...data, comparison });+ return json({ ...data[0], comparison });}diff --git a/src/lib/filters.ts b/src/lib/filters.tsindex 17b93ffcf..3da268d8a 100644--- a/src/lib/filters.ts+++ b/src/lib/filters.ts@@ -1,5 +1,5 @@export const percentFilter = (data: any[]) => {- if (!data) return [];+ if (!Array.isArray(data)) return [];const total = data.reduce((n, { y }) => n + y, 0);return data.map(({ x, y, ...props }) => ({ x, y, z: total ? (y / total) * 100 : 0, ...props }));};diff --git a/src/lib/prisma.ts b/src/lib/prisma.tsindex fdba769c9..3cf0bc0d1 100644--- a/src/lib/prisma.ts+++ b/src/lib/prisma.ts@@ -170,6 +170,11 @@ async function rawQuery(sql: string, data: object): Promise<any> {log('PARAMETERS:\n', data);}const params = [];+ const schema = getSchema();++ if (schema) {+ await client.$executeRawUnsafe(`SET search_path TO "${schema}";`);+ }const query = sql?.replaceAll(/\{\{\s*(\w+)(::\w+)?\s*}}/g, (...args) => {const [, name, type] = args;@@ -182,8 +187,8 @@ async function rawQuery(sql: string, data: object): Promise<any> {});return process.env.DATABASE_REPLICA_URL- ? client.$replica().$queryRawUnsafe(query, ...params)- : client.$queryRawUnsafe(query, ...params);+ ? await client.$replica().$queryRawUnsafe(query, ...params)+ : await client.$queryRawUnsafe(query, ...params);}async function pagedQuery<T>(model: string, criteria: T, filters?: QueryFilters) {@@ -265,6 +270,12 @@ function transaction(input: any, options?: any) {return client.$transaction(input, options);}+function getSchema() {+ const connectionUrl = new URL(process.env.DATABASE_URL);++ return connectionUrl.searchParams.get('schema');+}+function getClient() {const prisma = new UmamiPrismaClient({url: process.env.DATABASE_URL,diff --git a/src/queries/sql/getActiveVisitors.ts b/src/queries/sql/getActiveVisitors.tsindex 9dc52a50b..0077bc496 100644--- a/src/queries/sql/getActiveVisitors.ts+++ b/src/queries/sql/getActiveVisitors.ts@@ -24,7 +24,7 @@ async function relationalQuery(websiteId: string) {{ websiteId, startDate },);- return result[0] ?? null;+ return result?.[0] ?? null;}async function clickhouseQuery(websiteId: string): Promise<{ x: number }> {