From 46524e4298e3536a534c90173043290cad213993 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Fri, 26 Mar 2021 19:02:32 -0400 Subject: [PATCH] Fix indexes --- databases/_private_indexes.sql | 2 +- databases/_sponsorTimes_indexes.sql | 8 ++++---- src/databases/Postgres.ts | 7 ++++++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/databases/_private_indexes.sql b/databases/_private_indexes.sql index 2b4781e..2b70fa7 100644 --- a/databases/_private_indexes.sql +++ b/databases/_private_indexes.sql @@ -5,7 +5,7 @@ CREATE INDEX IF NOT EXISTS "sponsorTimes_hashedIP" ("hashedIP" COLLATE pg_catalog."default" ASC NULLS LAST) TABLESPACE pg_default; -CREATE INDEX "privateDB_sponsorTimes_videoID" +CREATE INDEX IF NOT EXISTS "privateDB_sponsorTimes_videoID" ON public."sponsorTimes" USING btree ("videoID" ASC NULLS LAST) ; diff --git a/databases/_sponsorTimes_indexes.sql b/databases/_sponsorTimes_indexes.sql index 6d4d91d..c90ef51 100644 --- a/databases/_sponsorTimes_indexes.sql +++ b/databases/_sponsorTimes_indexes.sql @@ -1,6 +1,6 @@ -- sponsorTimes -CREATE INDEX IF NOT EXISTS "sponsorTiems_timeSubmitted" +CREATE INDEX IF NOT EXISTS "sponsorTime_timeSubmitted" ON public."sponsorTimes" USING btree ("timeSubmitted" ASC NULLS LAST) TABLESPACE pg_default; @@ -14,8 +14,8 @@ CREATE INDEX IF NOT EXISTS "sponsorTimes_UUID" ON public."sponsorTimes" USING btree ("UUID" COLLATE pg_catalog."default" ASC NULLS LAST) TABLESPACE pg_default; - -CREATE INDEX "sponsorTimes_hashedVideoID_gin" + +CREATE INDEX IF NOT EXISTS "sponsorTimes_hashedVideoID_gin" ON public."sponsorTimes" USING gin ("hashedVideoID" COLLATE pg_catalog."default" gin_trgm_ops, category COLLATE pg_catalog."default" gin_trgm_ops) TABLESPACE pg_default; @@ -41,7 +41,7 @@ CREATE INDEX IF NOT EXISTS "vipUsers_index" -- warnings -CREATE INDEX IF NOT EXISTS warnings_index +CREATE INDEX IF NOT EXISTS "warnings_index" ON public.warnings USING btree ("userID" COLLATE pg_catalog."default" ASC NULLS LAST, "issueTime" DESC NULLS LAST, enabled DESC NULLS LAST) TABLESPACE pg_default; diff --git a/src/databases/Postgres.ts b/src/databases/Postgres.ts index 1f87e8f..e7e16f4 100644 --- a/src/databases/Postgres.ts +++ b/src/databases/Postgres.ts @@ -24,7 +24,12 @@ 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); + try { + await this.applyIndexes(this.config.fileNamePrefix, this.config.dbSchemaFolder); + } catch (e) { + Logger.warn("Applying indexes failed. See https://github.com/ajayyy/SponsorBlockServer/wiki/Postgres-Extensions for more information."); + Logger.warn(e); + } } }