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

@ -8,6 +8,7 @@ import {
JoinColumn, JoinColumn,
OneToMany, OneToMany,
DeleteDateColumn, DeleteDateColumn,
Index,
} from 'typeorm'; } from 'typeorm';
import { User } from '../../user/entities/user.entity'; import { User } from '../../user/entities/user.entity';
import { Workspace } from '../../workspace/entities/workspace.entity'; import { Workspace } from '../../workspace/entities/workspace.entity';
@ -16,6 +17,7 @@ import { PageHistory } from './page-history.entity';
import { Space } from '../../space/entities/space.entity'; import { Space } from '../../space/entities/space.entity';
@Entity('pages') @Entity('pages')
@Index(['tsv'])
export class Page { export class Page {
@PrimaryGeneratedColumn('uuid') @PrimaryGeneratedColumn('uuid')
id: string; id: string;

View File

@ -25,6 +25,7 @@ export class Init1711150216801 implements MigrationInterface {
await queryRunner.query( await queryRunner.query(
`CREATE TABLE "pages" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "title" character varying(500), "icon" character varying, "content" jsonb, "html" text, "textContent" text, "tsv" tsvector, "ydoc" bytea, "slug" character varying, "coverPhoto" character varying, "editor" character varying(255), "shareId" character varying(255), "parentPageId" uuid, "creatorId" uuid NOT NULL, "lastUpdatedById" uuid, "deletedById" uuid, "spaceId" uuid NOT NULL, "workspaceId" uuid NOT NULL, "isLocked" boolean NOT NULL DEFAULT false, "status" character varying(255), "publishedAt" date, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "deletedAt" TIMESTAMP, CONSTRAINT "PK_pages" PRIMARY KEY ("id"))`, `CREATE TABLE "pages" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "title" character varying(500), "icon" character varying, "content" jsonb, "html" text, "textContent" text, "tsv" tsvector, "ydoc" bytea, "slug" character varying, "coverPhoto" character varying, "editor" character varying(255), "shareId" character varying(255), "parentPageId" uuid, "creatorId" uuid NOT NULL, "lastUpdatedById" uuid, "deletedById" uuid, "spaceId" uuid NOT NULL, "workspaceId" uuid NOT NULL, "isLocked" boolean NOT NULL DEFAULT false, "status" character varying(255), "publishedAt" date, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "deletedAt" TIMESTAMP, CONSTRAINT "PK_pages" PRIMARY KEY ("id"))`,
); );
await queryRunner.query(`CREATE INDEX "IDX_pages_tsv" ON "pages" ("id") `);
await queryRunner.query( await queryRunner.query(
`CREATE TABLE "users" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "name" character varying(255), "email" character varying(255) NOT NULL, "emailVerifiedAt" TIMESTAMP, "password" character varying NOT NULL, "avatarUrl" character varying, "role" character varying(100), "workspaceId" uuid, "locale" character varying(100), "timezone" character varying(300), "settings" jsonb, "lastLoginAt" TIMESTAMP, "lastLoginIp" character varying(100), "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "UQ_users_email_workspaceId" UNIQUE ("email", "workspaceId"), CONSTRAINT "PK_users" PRIMARY KEY ("id"))`, `CREATE TABLE "users" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "name" character varying(255), "email" character varying(255) NOT NULL, "emailVerifiedAt" TIMESTAMP, "password" character varying NOT NULL, "avatarUrl" character varying, "role" character varying(100), "workspaceId" uuid, "locale" character varying(100), "timezone" character varying(300), "settings" jsonb, "lastLoginAt" TIMESTAMP, "lastLoginIp" character varying(100), "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "UQ_users_email_workspaceId" UNIQUE ("email", "workspaceId"), CONSTRAINT "PK_users" PRIMARY KEY ("id"))`,
); );
@ -259,6 +260,7 @@ export class Init1711150216801 implements MigrationInterface {
await queryRunner.query(`DROP TABLE "workspaces"`); await queryRunner.query(`DROP TABLE "workspaces"`);
await queryRunner.query(`DROP TABLE "users"`); await queryRunner.query(`DROP TABLE "users"`);
await queryRunner.query(`DROP TABLE "pages"`); await queryRunner.query(`DROP TABLE "pages"`);
await queryRunner.query(`DROP INDEX IF EXISTS "public"."IDX_pages_id"`);
await queryRunner.query(`DROP TABLE "page_history"`); await queryRunner.query(`DROP TABLE "page_history"`);
await queryRunner.query(`DROP TABLE "spaces"`); await queryRunner.query(`DROP TABLE "spaces"`);
await queryRunner.query(`DROP TABLE "space_members"`); await queryRunner.query(`DROP TABLE "space_members"`);

View File

@ -4,6 +4,11 @@ export class AddTSVColumnIndex1711150345785 implements MigrationInterface {
name = 'AddTSVColumnIndex1711150345785'; name = 'AddTSVColumnIndex1711150345785';
public async up(queryRunner: QueryRunner): Promise<void> { public async up(queryRunner: QueryRunner): Promise<void> {
// TypeORM entity does not support custom index type
// if we don't set the index on the entity,
// TypeORM will always generate the index here in new migrations
// dropping previous index to recreate using GIN
await queryRunner.query(`DROP INDEX IF EXISTS "IDX_pages_tsv";`);
await queryRunner.query( await queryRunner.query(
`CREATE INDEX "IDX_pages_tsv" ON pages USING GIN ("tsv");`, `CREATE INDEX "IDX_pages_tsv" ON pages USING GIN ("tsv");`,
); );

View File

@ -1,7 +1,7 @@
import { MigrationInterface, QueryRunner } from 'typeorm'; import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddTsvectorTrigger1711150304333 implements MigrationInterface { export class AddTsvectorTrigger1711152548283 implements MigrationInterface {
name = 'AddTsvectorTrigger1711150304333'; name = 'AddTsvectorTrigger1711152548283';
public async up(queryRunner: QueryRunner): Promise<void> { public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(` await queryRunner.query(`