From 3e073e7f66c39910d3a9336087876603852082e5 Mon Sep 17 00:00:00 2001 From: knotteye Date: Fri, 30 Oct 2020 06:25:47 -0500 Subject: [PATCH 1/2] Skip compiling templates when running migrations alone --- src/migrate.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/migrate.ts b/src/migrate.ts index 0e3cf14..450296d 100644 --- a/src/migrate.ts +++ b/src/migrate.ts @@ -3,6 +3,7 @@ import {init as clean} from "./cleanup"; import { config } from "./config"; async function run() { + process.argv = process.argv.concat(['--skip-compile']); await initDB(); await clean(); } -- 2.42.2 From 33accfb8b7e0c6b21668ea8174f0a1b72aa9e4af Mon Sep 17 00:00:00 2001 From: knotteye Date: Fri, 30 Oct 2020 07:20:23 -0500 Subject: [PATCH 2/2] Select scripts to run based on comparing version strings and script names. This means scripts need to insert a version value the same as their name to db_meta. This is nothing new, it just works better now. --- src/cleanup.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/cleanup.ts b/src/cleanup.ts index 4a3fd58..17e134e 100644 --- a/src/cleanup.ts +++ b/src/cleanup.ts @@ -9,11 +9,8 @@ async function init() { if(tmp.length === 0){ console.log('No database version info, running initial migration.'); await require('./db/0').run(); - await bringUpToDate(); - } - else { - await bringUpToDate(); } + await bringUpToDate(); } else { console.log('Skipping database version check.'); @@ -34,16 +31,19 @@ async function init() { } async function bringUpToDate(): Promise{ - var versions: Object[] = await db.query('select * from db_meta'); - var scripts: Buffer[] | string[] = readdirSync('./src/db/', {withFileTypes: false}); - var diff: number = scripts.length - versions.length - if(diff === 0){ + var versions: Object[] = JSON.parse(JSON.stringify(await db.query('select * from db_meta'))); //ugh, don't ask + var scripts: any[] = readdirSync('./src/db/', {withFileTypes: false}); + if(scripts.length - versions.length === 0){ console.log('No migration needed.'); } else { console.log('Versions differ, migrating now.'); - for(let i=0;i { + //we have to use versions.some because {version: 0} === {version: 0} returns false lmao + return !versions.some(o => o['version']+''=== n.substring(0, n.length - 3)) + }); + for(let i=0;i