mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-25 11:27:31 -07:00
[backend] Add postgres FTS migration
This commit is contained in:
parent
b2f6808bef
commit
361176448e
2 changed files with 20 additions and 0 deletions
|
@ -0,0 +1,19 @@
|
||||||
|
import { MigrationInterface, QueryRunner } from "typeorm"
|
||||||
|
|
||||||
|
export class NoteTextFtsIdx1700331070890 implements MigrationInterface {
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`CREATE EXTENSION IF NOT EXISTS pg_trgm`);
|
||||||
|
const total = await queryRunner.query(`SELECT COUNT(*) FROM "note"`);
|
||||||
|
if (total && total.length > 0) {
|
||||||
|
const count = BigInt(total[0].count);
|
||||||
|
console.log(`Indexing the "note" table for full text search, please hang tight!`);
|
||||||
|
console.log(`You have ${count} notes in your database. This process will take an estimated ${count / 1000000n * 45n} seconds, though the exact duration depends on your hardware configuration.`);
|
||||||
|
}
|
||||||
|
await queryRunner.query(`CREATE INDEX IF NOT EXISTS "note_text_fts_idx" ON "note" USING gin ("text" gin_trgm_ops)`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`DROP INDEX IF EXISTS "note_text_fts_idx"`);
|
||||||
|
await queryRunner.query(`DROP EXTENSION IF EXISTS pg_trgm`);
|
||||||
|
}
|
||||||
|
}
|
|
@ -62,6 +62,7 @@ export class Note {
|
||||||
})
|
})
|
||||||
public threadId: string | null;
|
public threadId: string | null;
|
||||||
|
|
||||||
|
@Index('note_text_fts_idx', { synchronize: false })
|
||||||
@Column("text", {
|
@Column("text", {
|
||||||
nullable: true,
|
nullable: true,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue