From 1f6daef0180bc737a2883203f6d513e5b81712ed Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Tue, 7 May 2024 00:34:26 +0200 Subject: [node] improved sql migrations code --- nodejs/automation/contracting.ts | 8 ++++---- nodejs/database/db.ts | 8 ++------ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/nodejs/automation/contracting.ts b/nodejs/automation/contracting.ts index 93c2f8e..9ac5d2f 100644 --- a/nodejs/automation/contracting.ts +++ b/nodejs/automation/contracting.ts @@ -32,11 +32,11 @@ async function runOne(contract: Contract, ship: Ship): Promise { await libContracts.accept(contract); switch(contract.type) { case 'PROCUREMENT': - if (contract.terms.deliver[0].tradeSymbol.match(/_ORE$/)) { - await runOreProcurement(contract, ship); - } else { + //if (contract.terms.deliver[0].tradeSymbol.match(/_ORE$/)) { + // await runOreProcurement(contract, ship); + //} else { await runTradeProcurement(contract, ship); - } + //} break; default: throw `Handling of contract type ${contract.type} is not implemented yet`; diff --git a/nodejs/database/db.ts b/nodejs/database/db.ts index 115d6a3..2fba09b 100644 --- a/nodejs/database/db.ts +++ b/nodejs/database/db.ts @@ -2,12 +2,6 @@ import fs from 'fs'; import path from 'path'; import Database from 'better-sqlite3'; -let allMigrations: Array = []; -fs.readdir('./database/', function(err, files) { - if (err) throw err; - allMigrations = files.filter(e => e.match(/\.sql$/)).map(e => path.join('./database', e)); -}); - export type DbData = {data: string}; export const db = new Database( @@ -18,6 +12,8 @@ db.pragma('foreign_keys = ON'); db.pragma('journal_mode = WAL'); function init(): void { + const filenames = fs.readdirSync('./database/'); + const allMigrations = filenames.filter(e => e.match(/\.sql$/)).map(e => path.join('./database', e)); db.transaction(function migrate() { let version; try { -- cgit v1.2.3