mirror of
https://github.com/kremalicious/umami.git
synced 2024-06-30 05:31:50 +02:00
Merge pull request #2003 from Maxime-J/cleanup-check-db
Cleanup check-db
This commit is contained in:
commit
3f90c34f94
|
@ -11,7 +11,7 @@ if (process.env.SKIP_DB_CHECK) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDatabaseType(url = process.env.DATABASE_URL) {
|
function getDatabaseType(url = process.env.DATABASE_URL) {
|
||||||
const type = process.env.DATABASE_TYPE || (url && url.split(':')[0]);
|
const type = url && url.split(':')[0];
|
||||||
|
|
||||||
if (type === 'postgres') {
|
if (type === 'postgres') {
|
||||||
return 'postgresql';
|
return 'postgresql';
|
||||||
|
@ -20,7 +20,6 @@ function getDatabaseType(url = process.env.DATABASE_URL) {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
const databaseType = getDatabaseType();
|
|
||||||
const prisma = new PrismaClient();
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
function success(msg) {
|
function success(msg) {
|
||||||
|
@ -49,10 +48,11 @@ async function checkConnection() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkDatabaseVersion(databaseType) {
|
async function checkDatabaseVersion() {
|
||||||
const query = await prisma.$queryRaw`select version() as version`;
|
const query = await prisma.$queryRaw`select version() as version`;
|
||||||
const version = semver.valid(semver.coerce(query[0].version));
|
const version = semver.valid(semver.coerce(query[0].version));
|
||||||
|
|
||||||
|
const databaseType = getDatabaseType();
|
||||||
const minVersion = databaseType === 'postgresql' ? '9.4.0' : '5.7.0';
|
const minVersion = databaseType === 'postgresql' ? '9.4.0' : '5.7.0';
|
||||||
|
|
||||||
if (semver.lt(version, minVersion)) {
|
if (semver.lt(version, minVersion)) {
|
||||||
|
@ -87,7 +87,7 @@ async function applyMigration() {
|
||||||
let err = false;
|
let err = false;
|
||||||
for (let fn of [checkEnv, checkConnection, checkDatabaseVersion, checkV1Tables, applyMigration]) {
|
for (let fn of [checkEnv, checkConnection, checkDatabaseVersion, checkV1Tables, applyMigration]) {
|
||||||
try {
|
try {
|
||||||
fn.name === 'checkDatabaseVersion' ? await fn(databaseType) : await fn();
|
await fn();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error(e.message);
|
error(e.message);
|
||||||
err = true;
|
err = true;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user