mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Fix for schema selection in pg adapter.
Some checks are pending
Node.js CI / build (postgresql, 18.18) (push) Waiting to run
Some checks are pending
Node.js CI / build (postgresql, 18.18) (push) Waiting to run
This commit is contained in:
parent
366c52d703
commit
e610de383a
6 changed files with 22 additions and 11 deletions
|
|
@ -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",
|
||||
|
|
|
|||
10
pnpm-lock.yaml
generated
10
pnpm-lock.yaml
generated
|
|
@ -247,8 +247,8 @@ importers:
|
|||
specifier: ^8.41.0
|
||||
version: 8.41.0(eslint@8.57.1)(typescript@5.9.2)
|
||||
'@umami/prisma-client':
|
||||
specifier: ^0.19.0
|
||||
version: 0.19.0(@prisma/adapter-pg@6.16.0)(@prisma/client@6.16.0(prisma@6.16.0(typescript@5.9.2))(typescript@5.9.2))(@prisma/extension-read-replicas@0.4.1(@prisma/client@6.16.0(prisma@6.16.0(typescript@5.9.2))(typescript@5.9.2)))
|
||||
specifier: ^0.20.0
|
||||
version: 0.20.0(@prisma/adapter-pg@6.16.0)(@prisma/client@6.16.0(prisma@6.16.0(typescript@5.9.2))(typescript@5.9.2))(@prisma/extension-read-replicas@0.4.1(@prisma/client@6.16.0(prisma@6.16.0(typescript@5.9.2))(typescript@5.9.2)))
|
||||
babel-plugin-react-compiler:
|
||||
specifier: 19.1.0-rc.2
|
||||
version: 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/prisma-client@0.19.0':
|
||||
resolution: {integrity: sha512-Vnys7MMAPexxmxrC+0q68B/iYmM1LFaP9RjKjffHbLfgZJ3moklJ2ea91cr8+m0CA3+3mqN38WEJI/o/ohOxYQ==}
|
||||
'@umami/prisma-client@0.20.0':
|
||||
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.0
|
||||
eslint-visitor-keys: 4.2.1
|
||||
|
||||
'@umami/prisma-client@0.19.0(@prisma/adapter-pg@6.16.0)(@prisma/client@6.16.0(prisma@6.16.0(typescript@5.9.2))(typescript@5.9.2))(@prisma/extension-read-replicas@0.4.1(@prisma/client@6.16.0(prisma@6.16.0(typescript@5.9.2))(typescript@5.9.2)))':
|
||||
'@umami/prisma-client@0.20.0(@prisma/adapter-pg@6.16.0)(@prisma/client@6.16.0(prisma@6.16.0(typescript@5.9.2))(typescript@5.9.2))(@prisma/extension-read-replicas@0.4.1(@prisma/client@6.16.0(prisma@6.16.0(typescript@5.9.2))(typescript@5.9.2)))':
|
||||
dependencies:
|
||||
'@prisma/adapter-pg': 6.16.0
|
||||
'@prisma/client': 6.16.0(prisma@6.16.0(typescript@5.9.2))(typescript@5.9.2)
|
||||
|
|
|
|||
|
|
@ -40,5 +40,5 @@ export async function GET(
|
|||
endDate,
|
||||
});
|
||||
|
||||
return json({ ...data, comparison });
|
||||
return json({ ...data[0], comparison });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 }));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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 }> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue