From ccde93ae0e68dbde73d0059480810f6937209186 Mon Sep 17 00:00:00 2001 From: Chris Wilkinson Date: Mon, 11 Oct 2021 10:45:41 +0100 Subject: [PATCH] fix: add and remove missing database indexes The database migrations are out of sync with the codebase: 1. The code doesn't know about some of the indexes in the migrations. 2. The code has indexes that don't exist in the migrations. 3. The code has misconfigured indexes; the ORM cannot read them but doesn't error until it tries to apply the broken SQL. These problems caused a failure in CI as it now checks that no migrations are missing. This change removes the broken and unapplied changes and adds in code for the missing ones to allow CI to pass. I'm not sure if any of the valid but unapplied indexes would help with performance issues, but they can be revisited later. Refs #388, #395, #400, d4c18e4 --- src/backend/models/entities/Badge.ts | 2 -- src/backend/models/entities/Community.ts | 7 ------- src/backend/models/entities/FullReview.ts | 9 --------- src/backend/models/entities/Group.ts | 2 -- src/backend/models/entities/Persona.ts | 11 +---------- src/backend/models/entities/Preprint.ts | 9 ++++----- src/backend/models/entities/Tag.ts | 3 --- src/backend/models/entities/User.ts | 8 -------- 8 files changed, 5 insertions(+), 46 deletions(-) diff --git a/src/backend/models/entities/Badge.ts b/src/backend/models/entities/Badge.ts index ab4f73dc..abd70929 100644 --- a/src/backend/models/entities/Badge.ts +++ b/src/backend/models/entities/Badge.ts @@ -2,7 +2,6 @@ import { Collection, Entity, EntityRepositoryType, - Index, ManyToMany, Property, Unique, @@ -13,7 +12,6 @@ import { BaseEntity } from './BaseEntity'; import { Persona } from './Persona'; @Entity() -@Index({ properties: ['personas'] }) export class Badge extends BaseEntity { [EntityRepositoryType]?: BadgeModel; diff --git a/src/backend/models/entities/Community.ts b/src/backend/models/entities/Community.ts index 64d8c113..5ce3b3f8 100644 --- a/src/backend/models/entities/Community.ts +++ b/src/backend/models/entities/Community.ts @@ -2,7 +2,6 @@ import { Collection, Entity, EntityRepositoryType, - Index, ManyToMany, OneToMany, Property, @@ -19,12 +18,6 @@ import { Template } from './Template'; import { User } from './User'; @Entity() -@Index({ properties: ['members'] }) -@Index({ properties: ['owners'] }) -@Index({ properties: ['preprints'] }) -@Index({ properties: ['events'] }) -@Index({ properties: ['tags'] }) -@Index({ properties: ['templates'] }) export class Community extends BaseEntity { [EntityRepositoryType]?: CommunityModel; diff --git a/src/backend/models/entities/FullReview.ts b/src/backend/models/entities/FullReview.ts index a3f5f634..b0d5dd76 100644 --- a/src/backend/models/entities/FullReview.ts +++ b/src/backend/models/entities/FullReview.ts @@ -2,7 +2,6 @@ import { Collection, Entity, EntityRepositoryType, - Index, ManyToMany, ManyToOne, OneToMany, @@ -20,14 +19,6 @@ import { Statement } from './Statement'; import { createRandomDoi } from '../../utils/ids'; @Entity() -@Index({ properties: ['drafts'] }) -@Index({ properties: ['mentorInvites'] }) -@Index({ properties: ['mentors'] }) -@Index({ properties: ['authorInvites'] }) -@Index({ properties: ['authors'] }) -@Index({ properties: ['preprint'] }) -@Index({ properties: ['comments'] }) -@Index({ properties: ['statements'] }) export class FullReview extends BaseEntity { [EntityRepositoryType]?: FullReviewModel; diff --git a/src/backend/models/entities/Group.ts b/src/backend/models/entities/Group.ts index e33a7a78..d0540ef1 100644 --- a/src/backend/models/entities/Group.ts +++ b/src/backend/models/entities/Group.ts @@ -2,7 +2,6 @@ import { Collection, Entity, EntityRepositoryType, - Index, ManyToMany, Property, Unique, @@ -13,7 +12,6 @@ import { BaseEntity } from './BaseEntity'; import { User } from './User'; @Entity() -@Index({ properties: ['members'] }) export class Group extends BaseEntity { [EntityRepositoryType]?: GroupModel; diff --git a/src/backend/models/entities/Persona.ts b/src/backend/models/entities/Persona.ts index 5389450d..e82fcf41 100644 --- a/src/backend/models/entities/Persona.ts +++ b/src/backend/models/entities/Persona.ts @@ -20,16 +20,7 @@ import { Request } from './Request'; import { User } from './User'; @Entity() -@Index({ properties: ['identity'] }) -@Index({ properties: ['communities'] }) -@Index({ properties: ['rapidReviews'] }) -@Index({ properties: ['fullReviews'] }) -@Index({ properties: ['invitedToAuthor'] }) -@Index({ properties: ['mentoring'] }) -@Index({ properties: ['invitedToMentor'] }) -@Index({ properties: ['requests'] }) -@Index({ properties: ['badges'] }) -@Index({ properties: ['expertises'] }) +@Index({ name: 'persona_trgm', properties: ['name', 'bio'] }) export class Persona extends BaseEntity { [EntityRepositoryType]?: PersonaModel; diff --git a/src/backend/models/entities/Preprint.ts b/src/backend/models/entities/Preprint.ts index e4e6bd90..ee63da92 100644 --- a/src/backend/models/entities/Preprint.ts +++ b/src/backend/models/entities/Preprint.ts @@ -19,11 +19,10 @@ import { Tag } from './Tag'; import { createRandomDoi } from '../../utils/ids'; @Entity() -@Index({ properties: ['rapidReviews'] }) -@Index({ properties: ['fullReviews'] }) -@Index({ properties: ['requests'] }) -@Index({ properties: ['communities'] }) -@Index({ properties: ['tags'] }) +@Index({ + name: 'preprint_trgm', + properties: ['title', 'handle', 'abstractText', 'authors'], +}) export class Preprint extends BaseEntity { [EntityRepositoryType]?: PreprintModel; diff --git a/src/backend/models/entities/Tag.ts b/src/backend/models/entities/Tag.ts index cb995a94..2311529c 100644 --- a/src/backend/models/entities/Tag.ts +++ b/src/backend/models/entities/Tag.ts @@ -2,7 +2,6 @@ import { Collection, Entity, EntityRepositoryType, - Index, ManyToMany, Property, Unique, @@ -14,8 +13,6 @@ import { Community } from './Community'; import { Preprint } from './Preprint'; @Entity() -@Index({ properties: ['preprints'] }) -@Index({ properties: ['communities'] }) export class Tag extends BaseEntity { [EntityRepositoryType]?: TagModel; diff --git a/src/backend/models/entities/User.ts b/src/backend/models/entities/User.ts index 48a4c9f3..72f6b731 100644 --- a/src/backend/models/entities/User.ts +++ b/src/backend/models/entities/User.ts @@ -2,7 +2,6 @@ import { Collection, Entity, EntityRepositoryType, - Index, ManyToMany, OneToMany, OneToOne, @@ -21,13 +20,6 @@ import { Key } from './Key'; import { createRandomOrcid } from '../../utils/orcid'; @Entity() -@Index({ properties: ['defaultPersona'] }) -@Index({ properties: ['groups'] }) -@Index({ properties: ['owned'] }) -@Index({ properties: ['personas'] }) -@Index({ properties: ['contacts'] }) -@Index({ properties: ['works'] }) -@Index({ properties: ['keys'] }) export class User extends BaseEntity { [EntityRepositoryType]?: UserModel;