fix semver error
This commit is contained in:
+8
-4
@@ -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.`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user