fix semver error

This commit is contained in:
Francis Cao
2026-06-23 11:50:19 -07:00
parent 9defe7e3e0
commit 3b792720af
+8 -4
View File
@@ -3,10 +3,10 @@ import 'dotenv/config';
import { execSync } from 'node:child_process';
import { PrismaPg } from '@prisma/adapter-pg';
import chalk from 'chalk';
import semver from 'semver';
import { PrismaClient } from '../generated/prisma/client.js';
const MIN_VERSION = '9.4.0';
const MIN_VERSION_NUM = 90400;
if (process.env.SKIP_DB_CHECK) {
console.log('Skipping database check.');
@@ -53,10 +53,14 @@ async function checkConnection() {
}
async function checkDatabaseVersion() {
const query = await prisma.$queryRaw`select version() as version`;
const version = semver.valid(semver.coerce(query[0].version));
const query = await prisma.$queryRaw`select current_setting('server_version_num') as version_num`;
const version = Number(query[0]?.version_num);
if (semver.lt(version, MIN_VERSION)) {
if (!Number.isFinite(version)) {
throw new Error('Unable to determine database version.');
}
if (version < MIN_VERSION_NUM) {
throw new Error(
`Database version is not compatible. Please upgrade to ${MIN_VERSION} or greater.`,
);