Adds full text indexes, and advanced search capabilities to the StyleAI chat bot.
This commit is contained in:
parent
a8c7729558
commit
910d1b3d21
11 changed files with 252 additions and 36 deletions
|
@ -0,0 +1,44 @@
|
|||
-- Add tsvector column to MantisIssue for title and description
|
||||
ALTER TABLE "MantisIssue" ADD COLUMN "fts" tsvector;
|
||||
|
||||
-- Create function to update MantisIssue fts column
|
||||
CREATE OR REPLACE FUNCTION update_mantisissue_fts() RETURNS trigger AS $$
|
||||
BEGIN
|
||||
NEW.fts := to_tsvector('english', coalesce(NEW.title, '') || ' ' || coalesce(NEW.description, ''));
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
-- Create trigger to update MantisIssue fts column on insert or update
|
||||
CREATE TRIGGER mantisissue_fts_update
|
||||
BEFORE INSERT OR UPDATE ON "MantisIssue"
|
||||
FOR EACH ROW EXECUTE FUNCTION update_mantisissue_fts();
|
||||
|
||||
-- Update existing rows in MantisIssue
|
||||
UPDATE "MantisIssue" SET fts = to_tsvector('english', coalesce(title, '') || ' ' || coalesce(description, ''));
|
||||
|
||||
-- Create index on MantisIssue fts column
|
||||
CREATE INDEX mantisissue_fts_idx ON "MantisIssue" USING gin(fts);
|
||||
|
||||
|
||||
-- Add tsvector column to MantisComment for comment text
|
||||
ALTER TABLE "MantisComment" ADD COLUMN "fts" tsvector;
|
||||
|
||||
-- Create function to update MantisComment fts column
|
||||
CREATE OR REPLACE FUNCTION update_mantiscomment_fts() RETURNS trigger AS $$
|
||||
BEGIN
|
||||
NEW.fts := to_tsvector('english', coalesce(NEW.comment, ''));
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
-- Create trigger to update MantisComment fts column on insert or update
|
||||
CREATE TRIGGER mantiscomment_fts_update
|
||||
BEFORE INSERT OR UPDATE ON "MantisComment"
|
||||
FOR EACH ROW EXECUTE FUNCTION update_mantiscomment_fts();
|
||||
|
||||
-- Update existing rows in MantisComment
|
||||
UPDATE "MantisComment" SET fts = to_tsvector('english', coalesce(comment, ''));
|
||||
|
||||
-- Create index on MantisComment fts column
|
||||
CREATE INDEX mantiscomment_fts_idx ON "MantisComment" USING gin(fts);
|
5
prisma/migrations/20250426123027_fts_fix/migration.sql
Normal file
5
prisma/migrations/20250426123027_fts_fix/migration.sql
Normal file
|
@ -0,0 +1,5 @@
|
|||
-- DropIndex
|
||||
DROP INDEX "mantiscomment_fts_idx";
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX "mantisissue_fts_idx";
|
|
@ -0,0 +1,5 @@
|
|||
-- CreateIndex
|
||||
CREATE INDEX "mantiscomment_fts_idx" ON "MantisComment" USING GIN ("fts");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "mantisissue_fts_idx" ON "MantisIssue" USING GIN ("fts");
|
|
@ -1,5 +1,6 @@
|
|||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
provider = "prisma-client-js"
|
||||
previewFeatures = ["fullTextSearchPostgres"]
|
||||
}
|
||||
|
||||
datasource db {
|
||||
|
@ -135,51 +136,57 @@ model Log {
|
|||
timestamp DateTime @default(now())
|
||||
level String
|
||||
message String
|
||||
meta Json? // Optional field for additional structured data
|
||||
meta Json? // Optional field for additional structured data
|
||||
}
|
||||
|
||||
// --- Mantis Models Start ---
|
||||
|
||||
model MantisIssue {
|
||||
id Int @id @default(autoincrement())
|
||||
title String
|
||||
description String?
|
||||
reporterUsername String? @map("reporter_username")
|
||||
status String
|
||||
priority String
|
||||
severity String
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
id Int @id @default(autoincrement())
|
||||
title String
|
||||
description String?
|
||||
reporterUsername String? @map("reporter_username")
|
||||
status String
|
||||
priority String
|
||||
severity String
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
comments MantisComment[]
|
||||
comments MantisComment[]
|
||||
|
||||
fts Unsupported("tsvector")?
|
||||
|
||||
@@index([reporterUsername])
|
||||
@@index([status])
|
||||
@@index([priority])
|
||||
@@index([severity])
|
||||
@@index([fts], map: "mantisissue_fts_idx", type: Gin) // Add this line
|
||||
}
|
||||
|
||||
model MantisComment {
|
||||
id Int @id @default(autoincrement())
|
||||
mantisIssueId Int @map("mantis_issue_id")
|
||||
senderUsername String? @map("sender_username")
|
||||
comment String
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
id Int @id @default(autoincrement())
|
||||
mantisIssueId Int @map("mantis_issue_id")
|
||||
senderUsername String? @map("sender_username")
|
||||
comment String
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
|
||||
mantisIssue MantisIssue @relation(fields: [mantisIssueId], references: [id], onDelete: Cascade)
|
||||
attachments MantisAttachment[]
|
||||
mantisIssue MantisIssue @relation(fields: [mantisIssueId], references: [id], onDelete: Cascade)
|
||||
attachments MantisAttachment[]
|
||||
fts Unsupported("tsvector")?
|
||||
|
||||
@@index([fts], map: "mantiscomment_fts_idx", type: Gin) // Add this line
|
||||
}
|
||||
|
||||
model MantisAttachment {
|
||||
id Int @id @default(autoincrement())
|
||||
commentId Int @map("comment_id")
|
||||
id Int @id @default(autoincrement())
|
||||
commentId Int @map("comment_id")
|
||||
filename String
|
||||
url String // Store path or URL to the file
|
||||
mimeType String? @map("mime_type")
|
||||
mimeType String? @map("mime_type")
|
||||
size Int?
|
||||
uploadedAt DateTime @default(now()) @map("uploaded_at")
|
||||
uploadedAt DateTime @default(now()) @map("uploaded_at")
|
||||
|
||||
comment MantisComment @relation(fields: [commentId], references: [id], onDelete: Cascade)
|
||||
comment MantisComment @relation(fields: [commentId], references: [id], onDelete: Cascade)
|
||||
}
|
||||
|
||||
// --- Mantis Models End ---
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue