Compare commits

..

No commits in common. "d0e3507cc022a354fbdd9b1cdc30aacd908796b7" and "47e036cde6acf564fd900a403f5b99a5557de2fa" have entirely different histories.

2 changed files with 11 additions and 12 deletions

View File

@ -9,8 +9,11 @@ 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.');
@ -31,19 +34,16 @@ async function init() {
}
async function bringUpToDate(): Promise<void>{
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){
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){
console.log('No migration needed.');
} else {
console.log('Versions differ, migrating now.');
var diff: string[] = scripts.filter(n => {
//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<diff.length;i++){
console.log('Running migration '+diff[i]);
await require('./db/'+diff[i]).run();
for(let i=0;i<diff;i++){
console.log('Migration to version '+Math.floor(scripts.length-(diff-i)));
await require('./db/'+scripts[Math.floor(scripts.length-(diff-i))]).run();
}
console.log('Done migrating database.');
}

View File

@ -3,7 +3,6 @@ import {init as clean} from "./cleanup";
import { config } from "./config";
async function run() {
process.argv = process.argv.concat(['--skip-compile']);
await initDB();
await clean();
}