Add index migration

This commit is contained in:
Zoe Roux 2025-01-24 19:19:05 +01:00
parent ce81caaf14
commit 1e2fd919ff
4 changed files with 27 additions and 31 deletions

View File

@ -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");

View File

@ -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");

View File

@ -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": {}
}
},

View File

@ -40,8 +40,8 @@
{
"idx": 5,
"version": "7",
"when": 1737301476949,
"tag": "0005_search",
"when": 1737742695309,
"tag": "0005_trigram",
"breakpoints": true
}
]