* Replace tsvector generated column with triggers.

* reason: due to typeorm generated column metadata bug
This commit is contained in:
Philipinho
2024-02-26 13:57:28 +00:00
parent 4008e15c04
commit 1d620eba49
4 changed files with 46 additions and 5 deletions
@@ -0,0 +1,28 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddTsvectorTrigger1706450034471 implements MigrationInterface {
name = 'AddTsvectorTrigger1706450034471';
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`);
}
}