Skip to content

Commit

Permalink
ensuring config is loaded on delete
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmerz committed Feb 11, 2025
1 parent 3bee435 commit 8a3b659
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ class Model extends EventEmitter {
super();
// we batch INSERTS/UPDATES because cloud manged data is SLOWWWWW to connect
this.BATCH_SIZE = 100;
this.configLoaded = false;
this.setMaxListeners(10000);
}

async loadConfig() {
if( this.configLoaded ) return;

let configTableExists = await this.tableExists(config.TABLES.TABLE_CONFIG);
if( configTableExists ) {
let tables = await pg.query(`SELECT * FROM ${config.TABLES.PK}`);
Expand All @@ -42,6 +45,7 @@ class Model extends EventEmitter {
}

await this.loadUids();
this.configLoaded = true;
}

async tableExists(table) {
Expand Down Expand Up @@ -453,6 +457,8 @@ class Model extends EventEmitter {
* @return {Promise}
*/
async delete(sourceName) {
await this.loadConfig();

let s = await source.getSource(sourceName);
if( s === null ) throw new Error('Unknown source: '+sourceName);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ucd-lib/pgdm",
"version": "1.1.0",
"version": "1.1.1",
"description": "PostgreSQL Data Management Library",
"main": "index.js",
"bin": {
Expand Down

0 comments on commit 8a3b659

Please sign in to comment.