fix pages tsv column index

This commit is contained in:
Philipinho
2024-03-23 00:12:01 +00:00
parent f1d7ffb9dd
commit 7d56920ad5
4 changed files with 11 additions and 2 deletions

View File

@ -0,0 +1,28 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddTsvectorTrigger1711152548283 implements MigrationInterface {
name = 'AddTsvectorTrigger1711152548283';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE FUNCTION pages_tsvector_trigger() RETURNS trigger AS $$
begin
new.tsv :=
setweight(to_tsvector('english', coalesce(new.title, '')), 'A') ||
setweight(to_tsvector('english', coalesce(new.\"textContent\", '')), 'B');
return new;
end;
$$ LANGUAGE plpgsql;
`);
await queryRunner.query(`
CREATE TRIGGER pages_tsvector_update BEFORE INSERT OR UPDATE
ON pages FOR EACH ROW EXECUTE FUNCTION pages_tsvector_trigger();
`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TRIGGER pages_tsvector_update ON Pages`);
await queryRunner.query(`DROP FUNCTION pages_tsvector_trigger`);
}
}