[node] improved sql migrations code
This commit is contained in:
parent
427cc77fa3
commit
1f6daef018
2 changed files with 6 additions and 10 deletions
|
@ -32,11 +32,11 @@ async function runOne(contract: Contract, ship: Ship): Promise<void> {
|
||||||
await libContracts.accept(contract);
|
await libContracts.accept(contract);
|
||||||
switch(contract.type) {
|
switch(contract.type) {
|
||||||
case 'PROCUREMENT':
|
case 'PROCUREMENT':
|
||||||
if (contract.terms.deliver[0].tradeSymbol.match(/_ORE$/)) {
|
//if (contract.terms.deliver[0].tradeSymbol.match(/_ORE$/)) {
|
||||||
await runOreProcurement(contract, ship);
|
// await runOreProcurement(contract, ship);
|
||||||
} else {
|
//} else {
|
||||||
await runTradeProcurement(contract, ship);
|
await runTradeProcurement(contract, ship);
|
||||||
}
|
//}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw `Handling of contract type ${contract.type} is not implemented yet`;
|
throw `Handling of contract type ${contract.type} is not implemented yet`;
|
||||||
|
|
|
@ -2,12 +2,6 @@ import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import Database from 'better-sqlite3';
|
import Database from 'better-sqlite3';
|
||||||
|
|
||||||
let allMigrations: Array<string> = [];
|
|
||||||
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 type DbData = {data: string};
|
||||||
|
|
||||||
export const db = new Database(
|
export const db = new Database(
|
||||||
|
@ -18,6 +12,8 @@ db.pragma('foreign_keys = ON');
|
||||||
db.pragma('journal_mode = WAL');
|
db.pragma('journal_mode = WAL');
|
||||||
|
|
||||||
function init(): void {
|
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() {
|
db.transaction(function migrate() {
|
||||||
let version;
|
let version;
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Add table
Reference in a new issue