Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

Updated migration process.

Mike Caoeda40d23367a
diff --git a/db/mysql/migrations/20220627184654_init/migration.sql b/db/mysql/migrations/01_init/migration.sql
similarity index 100%
rename from db/mysql/migrations/20220627184654_init/migration.sql
rename to db/mysql/migrations/01_init/migration.sql
diff --git a/db/postgresql/migrations/20210320112717_init/migration.sql b/db/postgresql/migrations/01_init/migration.sql
similarity index 100%
rename from db/postgresql/migrations/20210320112717_init/migration.sql
rename to db/postgresql/migrations/01_init/migration.sql
diff --git a/scripts/check-db.js b/scripts/check-db.js
index 702581980..85e92d7b1 100644
--- a/scripts/check-db.js
+++ b/scripts/check-db.js
@@ -3,13 +3,9 @@ const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
const chalk = require('chalk');
const spawn = require('cross-spawn');
+const { execSync } = require('child_process');
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) {
console.log(chalk.greenBright(`✓ ${msg}`));
@@ -39,9 +35,9 @@ async function checkTables() {
success('Database tables found.');
} 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 notManaged = output.includes('The current database is not managed');
- if (notManaged) {
- const cmd = output.match(/yarn prisma migrate resolve --applied ".*"/g);
+ if (notManaged || missingMigrations) {
+ console.log('Running update...');
- message = baselineMessage(cmd[0]);
-
- throw new Error('Database is out of date.');
- } else if (missingMigrations) {
- message = updateMessage;
-
- throw new Error('Database is out of date.');
+ console.log(execSync('prisma migrate resolve --applied "01_init"').toString());
}
success('Database is up to date.');