From 33accfb8b7e0c6b21668ea8174f0a1b72aa9e4af Mon Sep 17 00:00:00 2001 From: knotteye Date: Fri, 30 Oct 2020 07:20:23 -0500 Subject: [PATCH] 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