mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
New schema for pixels and links.
This commit is contained in:
parent
c60e8b3d23
commit
88639dfe83
67 changed files with 993 additions and 208 deletions
|
|
@ -7,21 +7,13 @@ import semver from 'semver';
|
|||
import { PrismaClient } from '@prisma/client';
|
||||
import { PrismaPg } from '@prisma/adapter-pg';
|
||||
|
||||
const MIN_VERSION = '9.4.0';
|
||||
|
||||
if (process.env.SKIP_DB_CHECK) {
|
||||
console.log('Skipping database check.');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
function getDatabaseType(url = process.env.DATABASE_URL) {
|
||||
const type = url && url.split(':')[0];
|
||||
|
||||
if (type === 'postgres') {
|
||||
return 'postgresql';
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
const url = new URL(process.env.DATABASE_URL);
|
||||
|
||||
const adapter = new PrismaPg(
|
||||
|
|
@ -61,35 +53,15 @@ async function checkDatabaseVersion() {
|
|||
const query = await prisma.$queryRaw`select version() as version`;
|
||||
const version = semver.valid(semver.coerce(query[0].version));
|
||||
|
||||
const databaseType = getDatabaseType();
|
||||
const minVersion = databaseType === 'postgresql' ? '9.4.0' : '5.7.0';
|
||||
|
||||
if (semver.lt(version, minVersion)) {
|
||||
if (semver.lt(version, MIN_VERSION)) {
|
||||
throw new Error(
|
||||
`Database version is not compatible. Please upgrade ${databaseType} version to ${minVersion} or greater`,
|
||||
`Database version is not compatible. Please upgrade to ${MIN_VERSION} or greater.`,
|
||||
);
|
||||
}
|
||||
|
||||
success('Database version check successful.');
|
||||
}
|
||||
|
||||
async function checkV1Tables() {
|
||||
try {
|
||||
// check for v1 migrations before v2 release date
|
||||
const record =
|
||||
await prisma.$queryRaw`select * from _prisma_migrations where started_at < '2023-04-17'`;
|
||||
|
||||
if (record.length > 0) {
|
||||
error(
|
||||
'Umami v1 tables detected. For how to upgrade from v1 to v2 go to https://umami.is/docs/migrate-v1-v2.',
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
} catch {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
async function applyMigration() {
|
||||
if (!process.env.SKIP_DB_MIGRATION) {
|
||||
console.log(execSync('prisma migrate deploy').toString());
|
||||
|
|
@ -100,13 +72,7 @@ async function applyMigration() {
|
|||
|
||||
(async () => {
|
||||
let err = false;
|
||||
for (const fn of [
|
||||
checkEnv,
|
||||
checkConnection,
|
||||
checkDatabaseVersion,
|
||||
checkV1Tables,
|
||||
applyMigration,
|
||||
]) {
|
||||
for (const fn of [checkEnv, checkConnection, checkDatabaseVersion, applyMigration]) {
|
||||
try {
|
||||
await fn();
|
||||
} catch (e) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue