migrations

This commit is contained in:
Philipinho
2024-01-30 00:22:29 +01:00
parent 9444281c0e
commit e03b1f9f25
21 changed files with 363 additions and 2 deletions
@@ -0,0 +1,16 @@
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 GENERATED ALWAYS AS (setweight(to_tsvector('english', coalesce(pages.title, '')), 'A') || setweight(to_tsvector('english', coalesce(pages."textContent", '')), 'B')) STORED`);
await queryRunner.query(`INSERT INTO "typeorm_metadata"("database", "schema", "table", "type", "name", "value") VALUES ($1, $2, $3, $4, $5, $6)`, ["","public","pages","GENERATED_COLUMN","tsv","setweight(to_tsvector('english', coalesce(pages.title, '')), 'A') || setweight(to_tsvector('english', coalesce(pages.\"textContent\", '')), 'B')"]);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DELETE FROM "typeorm_metadata" WHERE "type" = $1 AND "name" = $2 AND "database" = $3 AND "schema" = $4 AND "table" = $5`, ["GENERATED_COLUMN","tsv","","public","pages"]);
await queryRunner.query(`ALTER TABLE "pages" DROP COLUMN "tsv"`);
}
}