mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-08 20:47:02 +03:00
Apply indexes after upgrades
This commit is contained in:
@@ -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')");
|
||||
|
||||
Reference in New Issue
Block a user