mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-14 21:10:34 +01:00
Updated migration process.
This commit is contained in:
parent
6b0401a040
commit
eda40d2336
@ -3,13 +3,9 @@ const { PrismaClient } = require('@prisma/client');
|
|||||||
const prisma = new PrismaClient();
|
const prisma = new PrismaClient();
|
||||||
const chalk = require('chalk');
|
const chalk = require('chalk');
|
||||||
const spawn = require('cross-spawn');
|
const spawn = require('cross-spawn');
|
||||||
|
const { execSync } = require('child_process');
|
||||||
|
|
||||||
let message = '';
|
let message = '';
|
||||||
const updateMessage = `To update your database, you need to run:\n${chalk.bold.yellow(
|
|
||||||
'yarn update-db',
|
|
||||||
)}`;
|
|
||||||
const baselineMessage = cmd =>
|
|
||||||
`You need to update your database by running:\n${chalk.bold.yellow(cmd)}`;
|
|
||||||
|
|
||||||
function success(msg) {
|
function success(msg) {
|
||||||
console.log(chalk.greenBright(`✓ ${msg}`));
|
console.log(chalk.greenBright(`✓ ${msg}`));
|
||||||
@ -39,9 +35,9 @@ async function checkTables() {
|
|||||||
|
|
||||||
success('Database tables found.');
|
success('Database tables found.');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
message = updateMessage;
|
console.log('Adding tables...');
|
||||||
|
|
||||||
throw new Error('Database tables not found.');
|
console.log(execSync('prisma migrate deploy').toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,16 +62,10 @@ async function checkMigrations() {
|
|||||||
const missingMigrations = output.includes('Following migration have not yet been applied');
|
const missingMigrations = output.includes('Following migration have not yet been applied');
|
||||||
const notManaged = output.includes('The current database is not managed');
|
const notManaged = output.includes('The current database is not managed');
|
||||||
|
|
||||||
if (notManaged) {
|
if (notManaged || missingMigrations) {
|
||||||
const cmd = output.match(/yarn prisma migrate resolve --applied ".*"/g);
|
console.log('Running update...');
|
||||||
|
|
||||||
message = baselineMessage(cmd[0]);
|
console.log(execSync('prisma migrate resolve --applied "01_init"').toString());
|
||||||
|
|
||||||
throw new Error('Database is out of date.');
|
|
||||||
} else if (missingMigrations) {
|
|
||||||
message = updateMessage;
|
|
||||||
|
|
||||||
throw new Error('Database is out of date.');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
success('Database is up to date.');
|
success('Database is up to date.');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user