Apply indexes after upgrades

This commit is contained in:
Ajay Ramachandran
2021-03-21 19:16:56 -04:00
parent cbf043ac7e
commit 11b4f642a6
3 changed files with 109 additions and 0 deletions

View File

@@ -23,6 +23,8 @@ export class Postgres implements IDatabase {
// Upgrade database if required
await this.upgradeDB(this.config.fileNamePrefix, this.config.dbSchemaFolder);
await this.applyIndexes(this.config.fileNamePrefix, this.config.dbSchemaFolder);
}
}
@@ -118,6 +120,15 @@ export class Postgres implements IDatabase {
Logger.debug('db update: no file ' + path);
}
private async applyIndexes(fileNamePrefix: string, schemaFolder: string) {
const path = schemaFolder + "/_" + fileNamePrefix + "_indexes.sql";
if (fs.existsSync(path)) {
await this.pool.query(fs.readFileSync(path).toString());
} else {
Logger.debug('failed to apply indexes to ' + fileNamePrefix);
}
}
private processUpgradeQuery(query: string): string {
let result = query;
result = result.replace(/sha256\((.*?)\)/gm, "digest($1, 'sha256')");