From 1e2fd919ffc86d9d2e2cc15a7e352070c0c8de23 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Fri, 24 Jan 2025 19:19:05 +0100 Subject: [PATCH] Add index migration --- api/drizzle/0005_search.sql | 14 ------------ api/drizzle/0005_trigram.sql | 5 +++++ api/drizzle/meta/0005_snapshot.json | 35 ++++++++++++++++------------- api/drizzle/meta/_journal.json | 4 ++-- 4 files changed, 27 insertions(+), 31 deletions(-) delete mode 100644 api/drizzle/0005_search.sql create mode 100644 api/drizzle/0005_trigram.sql diff --git a/api/drizzle/0005_search.sql b/api/drizzle/0005_search.sql deleted file mode 100644 index 9b66c9fe..00000000 --- a/api/drizzle/0005_search.sql +++ /dev/null @@ -1,14 +0,0 @@ -CREATE OR REPLACE FUNCTION array_to_string_im(text[], text) - RETURNS text LANGUAGE sql IMMUTABLE AS $$SELECT array_to_string($1, $2)$$; - -ALTER TABLE "kyoo"."show_translations" ADD COLUMN "search" "tsvector" GENERATED ALWAYS AS ( - setweight(to_tsvector('simple', "kyoo"."show_translations"."name"), 'A') || - setweight(to_tsvector('simple', array_to_string_im("kyoo"."show_translations"."aliases", ' ')), 'B') || - setweight(to_tsvector('simple', array_to_string_im("kyoo"."show_translations"."tags", ' ')), 'C') || - setweight(to_tsvector('simple', coalesce("kyoo"."show_translations"."tagline", '')), 'D') || - setweight(to_tsvector('simple', coalesce("kyoo"."show_translations"."description", '')), 'D') - ) STORED;--> statement-breakpoint -CREATE INDEX "search" ON "kyoo"."show_translations" USING gin ("search");--> statement-breakpoint -CREATE INDEX "kind" ON "kyoo"."shows" USING hash ("kind");--> statement-breakpoint -CREATE INDEX "rating" ON "kyoo"."shows" USING btree ("rating");--> statement-breakpoint -CREATE INDEX "startAir" ON "kyoo"."shows" USING btree ("start_air"); diff --git a/api/drizzle/0005_trigram.sql b/api/drizzle/0005_trigram.sql new file mode 100644 index 00000000..cb2aa11b --- /dev/null +++ b/api/drizzle/0005_trigram.sql @@ -0,0 +1,5 @@ +CREATE INDEX "name_trgm" ON "kyoo"."show_translations" USING gin ("name" gin_trgm_ops);--> statement-breakpoint +CREATE INDEX "tags" ON "kyoo"."show_translations" USING btree ("tags");--> statement-breakpoint +CREATE INDEX "kind" ON "kyoo"."shows" USING hash ("kind");--> statement-breakpoint +CREATE INDEX "rating" ON "kyoo"."shows" USING btree ("rating");--> statement-breakpoint +CREATE INDEX "startAir" ON "kyoo"."shows" USING btree ("start_air"); \ No newline at end of file diff --git a/api/drizzle/meta/0005_snapshot.json b/api/drizzle/meta/0005_snapshot.json index 721b0396..55a64e20 100644 --- a/api/drizzle/meta/0005_snapshot.json +++ b/api/drizzle/meta/0005_snapshot.json @@ -1,5 +1,5 @@ { - "id": "8e9e90b8-5dbf-4e36-9615-5683c1c1c3e5", + "id": "1d98727c-290d-4491-8bb8-74390da0c021", "prevId": "0d5d6d22-dc13-4f3d-9975-cb7b38f628d4", "version": "7", "dialect": "postgresql", @@ -473,24 +473,29 @@ "type": "text", "primaryKey": false, "notNull": false - }, - "search": { - "name": "search", - "type": "tsvector", - "primaryKey": false, - "notNull": false, - "generated": { - "as": "\n\t\t\tsetweight(to_tsvector('simple', \"kyoo\".\"show_translations\".\"name\"), 'A') ||\n\t\t\tsetweight(to_tsvector('simple', array_to_string(\"kyoo\".\"show_translations\".\"aliases\", ' ')), 'B') ||\n\t\t\tsetweight(to_tsvector('simple', array_to_string(\"kyoo\".\"show_translations\".\"tags\", ' ')), 'C') ||\n\t\t\tsetweight(to_tsvector('simple', coalesce(\"kyoo\".\"show_translations\".\"tagline\", '')), 'D') ||\n\t\t\tsetweight(to_tsvector('simple', coalesce(\"kyoo\".\"show_translations\".\"description\", '')), 'D')\n\t\t", - "type": "stored" - } } }, "indexes": { - "search": { - "name": "search", + "name_trgm": { + "name": "name_trgm", "columns": [ { - "expression": "search", + "expression": "\"name\" gin_trgm_ops", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "gin", + "with": {} + }, + "tags": { + "name": "tags", + "columns": [ + { + "expression": "tags", "isExpression": false, "asc": true, "nulls": "last" @@ -498,7 +503,7 @@ ], "isUnique": false, "concurrently": false, - "method": "gin", + "method": "btree", "with": {} } }, diff --git a/api/drizzle/meta/_journal.json b/api/drizzle/meta/_journal.json index 8f5e4851..f1e402ae 100644 --- a/api/drizzle/meta/_journal.json +++ b/api/drizzle/meta/_journal.json @@ -40,8 +40,8 @@ { "idx": 5, "version": "7", - "when": 1737301476949, - "tag": "0005_search", + "when": 1737742695309, + "tag": "0005_trigram", "breakpoints": true } ]