Skip to content

Commit

Permalink
fix: add and remove missing database indexes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
thewilkybarkid committed Oct 11, 2021
1 parent d4c18e4 commit ccde93a
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 46 deletions.
2 changes: 0 additions & 2 deletions src/backend/models/entities/Badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
Collection,
Entity,
EntityRepositoryType,
Index,
ManyToMany,
Property,
Unique,
Expand All @@ -13,7 +12,6 @@ import { BaseEntity } from './BaseEntity';
import { Persona } from './Persona';

@Entity()
@Index({ properties: ['personas'] })
export class Badge extends BaseEntity {
[EntityRepositoryType]?: BadgeModel;

Expand Down
7 changes: 0 additions & 7 deletions src/backend/models/entities/Community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
Collection,
Entity,
EntityRepositoryType,
Index,
ManyToMany,
OneToMany,
Property,
Expand All @@ -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;

Expand Down
9 changes: 0 additions & 9 deletions src/backend/models/entities/FullReview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
Collection,
Entity,
EntityRepositoryType,
Index,
ManyToMany,
ManyToOne,
OneToMany,
Expand All @@ -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;

Expand Down
2 changes: 0 additions & 2 deletions src/backend/models/entities/Group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
Collection,
Entity,
EntityRepositoryType,
Index,
ManyToMany,
Property,
Unique,
Expand All @@ -13,7 +12,6 @@ import { BaseEntity } from './BaseEntity';
import { User } from './User';

@Entity()
@Index({ properties: ['members'] })
export class Group extends BaseEntity {
[EntityRepositoryType]?: GroupModel;

Expand Down
11 changes: 1 addition & 10 deletions src/backend/models/entities/Persona.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
9 changes: 4 additions & 5 deletions src/backend/models/entities/Preprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 0 additions & 3 deletions src/backend/models/entities/Tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
Collection,
Entity,
EntityRepositoryType,
Index,
ManyToMany,
Property,
Unique,
Expand All @@ -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;

Expand Down
8 changes: 0 additions & 8 deletions src/backend/models/entities/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
Collection,
Entity,
EntityRepositoryType,
Index,
ManyToMany,
OneToMany,
OneToOne,
Expand All @@ -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;

Expand Down

0 comments on commit ccde93a

Please sign in to comment.