mirror of
https://github.com/docmost/docmost.git
synced 2025-11-14 03:31:11 +10:00
* Replace tsvector generated column with triggers.
* reason: due to typeorm generated column metadata bug
This commit is contained in:
@ -0,0 +1,13 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddTsvectorColumn1706450034470 implements MigrationInterface {
|
||||
name = 'AddTsvectorColumn1706450034470';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "pages" ADD "tsv" tsvector`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "pages" DROP COLUMN "tsv"`);
|
||||
}
|
||||
}
|
||||
@ -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`);
|
||||
}
|
||||
}
|
||||
@ -4,10 +4,11 @@ export class AddIndexTSVColumn1706453158729 implements MigrationInterface {
|
||||
name = 'AddIndexTSVColumn1706453158729'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`CREATE INDEX pages_tsv_index ON pages USING GIN ("tsv");`);
|
||||
await queryRunner.query(`DROP INDEX IF EXISTS pages_tsv_idx;`);
|
||||
await queryRunner.query(`CREATE INDEX pages_tsv_idx ON pages USING GIN ("tsv");`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DROP INDEX IF EXISTS pages_tsv_index;`);
|
||||
await queryRunner.query(`DROP INDEX IF EXISTS pages_tsv_idx;`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user