Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions scripts/check-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ if (process.env.SKIP_DB_CHECK) {

const url = new URL(process.env.DATABASE_URL);

const existingOptions = url.searchParams.get('options') || '';
if (!existingOptions.includes('timezone')) {
url.searchParams.set(
'options',
existingOptions ? `${existingOptions} -c timezone=UTC` : '-c timezone=UTC',
);
}

const adapter = new PrismaPg(
{ connectionString: url.toString() },
{ schema: url.searchParams.get('schema') },
Expand Down
10 changes: 9 additions & 1 deletion scripts/seed/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,15 @@ function createPrismaClient(): PrismaClient {
);
}

const adapter = new PrismaPg({ connectionString: url }, { schema });
const existingOptions = connectionUrl.searchParams.get('options') || '';
if (!existingOptions.includes('timezone')) {
connectionUrl.searchParams.set(
'options',
existingOptions ? `${existingOptions} -c timezone=UTC` : '-c timezone=UTC',
);
}

const adapter = new PrismaPg({ connectionString: connectionUrl.toString() }, { schema });

return new PrismaClient({
adapter,
Expand Down
29 changes: 27 additions & 2 deletions src/lib/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,21 @@ function getClient() {

const schema = getSchema();

const baseAdapter = new PrismaPg({ connectionString: url }, { schema });
// Ensure consistent UTC session timezone so that TIMESTAMPTZ values
// written by @prisma/adapter-pg are not mis-interpreted by PostgreSQL.
// The adapter's formatDateTime omits the timezone offset, causing
// PostgreSQL to assume the session timezone (default: server timezone).
// See https://github.com/umami-software/umami/issues/4285
const connectionUrl = new URL(url);
const existingOptions = connectionUrl.searchParams.get('options') || '';
if (!existingOptions.includes('timezone')) {
connectionUrl.searchParams.set(
'options',
existingOptions ? `${existingOptions} -c timezone=UTC` : '-c timezone=UTC',
);
}

const baseAdapter = new PrismaPg({ connectionString: connectionUrl.toString() }, { schema });
Comment thread
sudoeren marked this conversation as resolved.
Outdated

const baseClient = new PrismaClient({
adapter: baseAdapter,
Expand All @@ -569,7 +583,18 @@ function getClient() {
return baseClient;
}

const replicaAdapter = new PrismaPg({ connectionString: replicaUrl }, { schema });
const replicaConnectionUrl = new URL(replicaUrl);
const replicaExistingOptions = replicaConnectionUrl.searchParams.get('options') || '';
if (!replicaExistingOptions.includes('timezone')) {
replicaConnectionUrl.searchParams.set(
'options',
replicaExistingOptions
? `${replicaExistingOptions} -c timezone=UTC`
: '-c timezone=UTC',
);
}

const replicaAdapter = new PrismaPg({ connectionString: replicaConnectionUrl.toString() }, { schema });

const replicaClient = new PrismaClient({
adapter: replicaAdapter,
Expand Down