|
|
@ -79,6 +79,15 @@ export class QueryHelper {
|
|
|
|
this.pool = pgPool;
|
|
|
|
this.pool = pgPool;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Async init function
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public async init() {
|
|
|
|
|
|
|
|
await this.pool.connect();
|
|
|
|
|
|
|
|
await this.createTables();
|
|
|
|
|
|
|
|
await this.updateTableDefinitions();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* creates all tables needed if a filepath was given with the constructor
|
|
|
|
* creates all tables needed if a filepath was given with the constructor
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -86,7 +95,18 @@ export class QueryHelper {
|
|
|
|
if (this.tableCreationFile) {
|
|
|
|
if (this.tableCreationFile) {
|
|
|
|
logger.info("Creating nonexistent tables...");
|
|
|
|
logger.info("Creating nonexistent tables...");
|
|
|
|
const tableSql = await fsx.readFile(this.tableCreationFile, "utf-8");
|
|
|
|
const tableSql = await fsx.readFile(this.tableCreationFile, "utf-8");
|
|
|
|
await this.query({text: tableSql});
|
|
|
|
const trans = await this.createTransaction();
|
|
|
|
|
|
|
|
await trans.begin();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
await trans.query({text: tableSql});
|
|
|
|
|
|
|
|
await trans.commit();
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
globals.logger.error(`Error on table creation ${err.message}`);
|
|
|
|
|
|
|
|
globals.logger.debug(err.stack);
|
|
|
|
|
|
|
|
await trans.rollback();
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
trans.release();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -97,7 +117,18 @@ export class QueryHelper {
|
|
|
|
if (this.tableUpdateFile) {
|
|
|
|
if (this.tableUpdateFile) {
|
|
|
|
logger.info("Updating table definitions...");
|
|
|
|
logger.info("Updating table definitions...");
|
|
|
|
const tableSql = await fsx.readFile(this.tableUpdateFile, "utf-8");
|
|
|
|
const tableSql = await fsx.readFile(this.tableUpdateFile, "utf-8");
|
|
|
|
await this.query({text: tableSql});
|
|
|
|
const trans = await this.createTransaction();
|
|
|
|
|
|
|
|
await trans.begin();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
await trans.query({text: tableSql});
|
|
|
|
|
|
|
|
await trans.commit();
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
globals.logger.error(`Error on table update ${err.message}`);
|
|
|
|
|
|
|
|
globals.logger.debug(err.stack);
|
|
|
|
|
|
|
|
await trans.rollback();
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
trans.release();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|