Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/gamification/entities/challenge.entity.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Entity, PrimaryGeneratedColumn, Column, VersionColumn } from 'typeorm';
import { Entity, PrimaryGeneratedColumn, Column, VersionColumn, Index } from 'typeorm';

/**
* Represents the challenge entity.
*/
@Entity('challenges')
@Index(['type'])
export class Challenge {
@PrimaryGeneratedColumn('uuid')
id: string;
Expand Down
3 changes: 3 additions & 0 deletions src/gamification/entities/point-transaction.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import {
ManyToOne,
CreateDateColumn,
VersionColumn,
Index,
} from 'typeorm';
import { User } from '../../users/entities/user.entity';

/**
* Represents the point Transaction entity.
*/
@Entity('point_transactions')
@Index(['user', 'createdAt'])
@Index(['activityType'])
export class PointTransaction {
@PrimaryGeneratedColumn('uuid')
id: string;
Expand Down
3 changes: 2 additions & 1 deletion src/gamification/entities/tier-reward.entity.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Entity, PrimaryGeneratedColumn, Column, VersionColumn } from 'typeorm';
import { Entity, PrimaryGeneratedColumn, Column, VersionColumn, Index } from 'typeorm';
import { Tier } from '../enums/tier.enum';

/**
* Defines the reward granted when a user reaches a specific tier.
*/
@Entity('tier_rewards')
@Index(['tier'])
export class TierReward {
@PrimaryGeneratedColumn('uuid')
id: string;
Expand Down
3 changes: 2 additions & 1 deletion src/gamification/entities/user-challenge.entity.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Entity, PrimaryGeneratedColumn, ManyToOne, Column, VersionColumn } from 'typeorm';
import { Entity, PrimaryGeneratedColumn, ManyToOne, Column, VersionColumn, Index } from 'typeorm';
import { User } from '../../users/entities/user.entity';
import { Challenge } from './challenge.entity';

/**
* Represents the user Challenge entity.
*/
@Entity('user_challenges')
@Index(['userId', 'challengeId'])
export class UserChallenge {
@PrimaryGeneratedColumn('uuid')
id: string;
Expand Down
19 changes: 19 additions & 0 deletions src/migrations/1750000000000-add-gamification-indexes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddGamificationIndexes1750000000000 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_point_transactions_user_createdAt" ON "point_transactions" ("userId", "createdAt")`);

Check failure on line 5 in src/migrations/1750000000000-add-gamification-indexes.ts

View workflow job for this annotation

GitHub Actions / validate

Strings must use singlequote

Check failure on line 5 in src/migrations/1750000000000-add-gamification-indexes.ts

View workflow job for this annotation

GitHub Actions / validate

Replace ``CREATE·INDEX·IF·NOT·EXISTS·"IDX_point_transactions_user_createdAt"·ON·"point_transactions"·("userId",·"createdAt")`` with `⏎······`CREATE·INDEX·IF·NOT·EXISTS·"IDX_point_transactions_user_createdAt"·ON·"point_transactions"·("userId",·"createdAt")`,⏎····`
await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_point_transactions_activityType" ON "point_transactions" ("activityType")`);

Check failure on line 6 in src/migrations/1750000000000-add-gamification-indexes.ts

View workflow job for this annotation

GitHub Actions / validate

Strings must use singlequote

Check failure on line 6 in src/migrations/1750000000000-add-gamification-indexes.ts

View workflow job for this annotation

GitHub Actions / validate

Replace ``CREATE·INDEX·IF·NOT·EXISTS·"IDX_point_transactions_activityType"·ON·"point_transactions"·("activityType")`` with `⏎······`CREATE·INDEX·IF·NOT·EXISTS·"IDX_point_transactions_activityType"·ON·"point_transactions"·("activityType")`,⏎····`
await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_user_challenges_user_challenge" ON "user_challenges" ("userId", "challengeId")`);

Check failure on line 7 in src/migrations/1750000000000-add-gamification-indexes.ts

View workflow job for this annotation

GitHub Actions / validate

Strings must use singlequote

Check failure on line 7 in src/migrations/1750000000000-add-gamification-indexes.ts

View workflow job for this annotation

GitHub Actions / validate

Replace ``CREATE·INDEX·IF·NOT·EXISTS·"IDX_user_challenges_user_challenge"·ON·"user_challenges"·("userId",·"challengeId")`` with `⏎······`CREATE·INDEX·IF·NOT·EXISTS·"IDX_user_challenges_user_challenge"·ON·"user_challenges"·("userId",·"challengeId")`,⏎····`
await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_challenges_type" ON "challenges" ("type")`);

Check failure on line 8 in src/migrations/1750000000000-add-gamification-indexes.ts

View workflow job for this annotation

GitHub Actions / validate

Strings must use singlequote

Check failure on line 8 in src/migrations/1750000000000-add-gamification-indexes.ts

View workflow job for this annotation

GitHub Actions / validate

Replace ``CREATE·INDEX·IF·NOT·EXISTS·"IDX_challenges_type"·ON·"challenges"·("type")`` with `⏎······`CREATE·INDEX·IF·NOT·EXISTS·"IDX_challenges_type"·ON·"challenges"·("type")`,⏎····`
await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_tier_rewards_tier" ON "tier_rewards" ("tier")`);

Check failure on line 9 in src/migrations/1750000000000-add-gamification-indexes.ts

View workflow job for this annotation

GitHub Actions / validate

Strings must use singlequote

Check failure on line 9 in src/migrations/1750000000000-add-gamification-indexes.ts

View workflow job for this annotation

GitHub Actions / validate

Replace ``CREATE·INDEX·IF·NOT·EXISTS·"IDX_tier_rewards_tier"·ON·"tier_rewards"·("tier")`` with `⏎······`CREATE·INDEX·IF·NOT·EXISTS·"IDX_tier_rewards_tier"·ON·"tier_rewards"·("tier")`,⏎····`
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP INDEX IF EXISTS "IDX_tier_rewards_tier"`);
await queryRunner.query(`DROP INDEX IF EXISTS "IDX_challenges_type"`);
await queryRunner.query(`DROP INDEX IF EXISTS "IDX_user_challenges_user_challenge"`);
await queryRunner.query(`DROP INDEX IF EXISTS "IDX_point_transactions_activityType"`);
await queryRunner.query(`DROP INDEX IF EXISTS "IDX_point_transactions_user_createdAt"`);
}
}
Loading