Skip to content

Commit

Permalink
Fix linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
CeEv committed Jan 15, 2025
1 parent e96edca commit d708c6b
Show file tree
Hide file tree
Showing 37 changed files with 98 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { Migration } from '@mikro-orm/migrations-mongodb';
* cleanup old migration records from db
*/
export class Migration20240108111130 extends Migration {
async up(): Promise<void> {
public async up(): Promise<void> {
const { deletedCount } = await this.getCollection('migrations').deleteMany({}, { session: this.ctx });
console.log(`removed ${deletedCount} records`);
}

// eslint-disable-next-line @typescript-eslint/require-await
async down(): Promise<void> {
// eslint-disable-next-line @typescript-eslint/require-await, require-await
public async down(): Promise<void> {
// do nothing
console.error(`Migration down not implemented. You might need to restore database from backup!`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Migration } from '@mikro-orm/migrations-mongodb';

// remove-undefined-parameters-from-external-tool
export class Migration20240115103302 extends Migration {
async up(): Promise<void> {
public async up(): Promise<void> {
const contextExternalToolResponse = await this.driver.nativeUpdate(
'context-external-tools',
{ $or: [{ 'parameters.value': undefined }, { 'parameters.value': '' }] },
Expand All @@ -22,8 +22,8 @@ export class Migration20240115103302 extends Migration {
console.info(`Removed ${schoolExternalToolResponse.affectedRows} parameter(s) in school-external-tools`);
}

// eslint-disable-next-line @typescript-eslint/require-await
async down() {
// eslint-disable-next-line @typescript-eslint/require-await, require-await
public async down(): Promise<void> {
console.error('This migration cannot be undone');
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Migration } from '@mikro-orm/migrations-mongodb';

export class Migration20240221131029 extends Migration {
async up(): Promise<void> {
public async up(): Promise<void> {
const contextExternalToolResponse = await this.driver.nativeUpdate(
'external-tools',
{ config_type: 'lti11' },
Expand All @@ -11,8 +11,8 @@ export class Migration20240221131029 extends Migration {
console.info(`Removed ${contextExternalToolResponse.affectedRows} resource_link_id(s) in context-external-tools`);
}

// eslint-disable-next-line @typescript-eslint/require-await
async down(): Promise<void> {
// eslint-disable-next-line @typescript-eslint/require-await, require-await
public async down(): Promise<void> {
// do nothing
console.error(`Migration down not implemented. You might need to restore database from backup!`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { Migration } from '@mikro-orm/migrations-mongodb';

export class Migration20240304123509 extends Migration {
async up(): Promise<void> {
public async up(): Promise<void> {
const columBoardResponse = await this.driver.nativeUpdate(
'boardnodes',
{ type: 'column-board' },
Expand Down Expand Up @@ -54,7 +54,7 @@ export class Migration20240304123509 extends Migration {
// console.info(`Collection colum-board-target was NOT removed`);
}

async down(): Promise<void> {
public async down(): Promise<void> {
const columBoardResponse = await this.driver.nativeUpdate(
'boardnodes',
{ type: 'column-board' },
Expand Down
22 changes: 15 additions & 7 deletions apps/server/src/migrations/mikro-orm/Migration20240315140224.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { Migration } from '@mikro-orm/migrations-mongodb';
import { RoleName } from '@shared/domain/interface';
import { FileRecordParentType } from '@src/modules/files-storage/interface';

enum FileRecordParentType {
'Submission' = 'submissions',
'Grading' = 'gradings',
}

export enum RoleName {
TEACHER = 'teacher',
}

export class Migration20240315140224 extends Migration {
async up(): Promise<void> {
public async up(): Promise<void> {
console.log('Start updating parentType of fileRecords if creator is teacher.');

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const teacherRole = (await this.driver.findOne('roles', { name: RoleName.TEACHER })) as any;
const teachers = await this.driver.aggregate('users', [
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
{ $match: { roles: teacherRole._id } },
{ $project: { _id: 1 } },
]);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return
const teacherIds = teachers.map((teacher: any) => teacher._id);

console.log(`Found ${teacherIds.length} teachers.`);
Expand All @@ -24,6 +31,7 @@ export class Migration20240315140224 extends Migration {
{ $match: { studentId: { $in: teacherIds } } },
{ $project: { _id: 1 } },
]);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return
const submissionsByTeachersIds = submissionsByTeachers.map((submission: any) => submission._id);

console.log(
Expand All @@ -43,7 +51,7 @@ export class Migration20240315140224 extends Migration {
console.log(`Updated ${result.affectedRows} filerecords.`);
}

async down(): Promise<void> {
public async down(): Promise<void> {
console.log('Resetting parentType "gradings" of fileRecords to "submissions".');

const result = await this.driver.nativeUpdate(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Migration } from '@mikro-orm/migrations-mongodb';

export class Migration20240320122229 extends Migration {
async up(): Promise<void> {
public async up(): Promise<void> {
const columBoardResponse = await this.driver.nativeUpdate(
'boardnodes',
{ $and: [{ type: 'column-board' }, { title: '' }] },
Expand All @@ -10,8 +10,8 @@ export class Migration20240320122229 extends Migration {
console.info(`Updated ${columBoardResponse.affectedRows} records in boardnodes`);
}

// eslint-disable-next-line @typescript-eslint/require-await
async down(): Promise<void> {
// eslint-disable-next-line @typescript-eslint/require-await, require-await
public async down(): Promise<void> {
console.error(`boardnodes cannot be rolled-back. It must be restored from backup!`);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Migration } from '@mikro-orm/migrations-mongodb';

export class Migration20240326072506 extends Migration {
async up(): Promise<void> {
public async up(): Promise<void> {
const adminRoleUpdate = await this.getCollection('roles').updateOne(
{ name: 'administrator' },
{
Expand Down Expand Up @@ -48,7 +48,7 @@ export class Migration20240326072506 extends Migration {
}
}

async down(): Promise<void> {
public async down(): Promise<void> {
const adminRoleUpdate = await this.getCollection('roles').updateOne(
{ name: 'administrator' },
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Migration } from '@mikro-orm/migrations-mongodb';
import { BoardLayout } from '@modules/board';
import { BoardNodeType } from '@modules/board/domain';
import { BoardLayout, BoardNodeType } from '@modules/board';

export class Migration20240415124640 extends Migration {
async up(): Promise<void> {
public async up(): Promise<void> {
const columBoardResponse = await this.driver.nativeUpdate<{ type: BoardNodeType; layout: BoardLayout }>(
'boardnodes',
{ $and: [{ type: 'column-board' }, { layout: { $exists: false } }] },
Expand All @@ -12,8 +11,8 @@ export class Migration20240415124640 extends Migration {
console.info(`Updated ${columBoardResponse.affectedRows} records in boardnodes`);
}

// eslint-disable-next-line @typescript-eslint/require-await
async down(): Promise<void> {
// eslint-disable-next-line @typescript-eslint/require-await, require-await
public async down(): Promise<void> {
console.error(`boardnodes cannot be rolled-back. It must be restored from backup!`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Migration } from '@mikro-orm/migrations-mongodb';

// add migration wizard permissions to admin role
export class Migration20240416104203 extends Migration {
async up(): Promise<void> {
public async up(): Promise<void> {
// eslint-disable-next-line no-process-env
if (process.env.SC_THEME !== 'thr') {
const adminRoleUpdate = await this.driver.nativeUpdate(
Expand All @@ -25,7 +25,7 @@ export class Migration20240416104203 extends Migration {
}
}

async down(): Promise<void> {
public async down(): Promise<void> {
// eslint-disable-next-line no-process-env
if (process.env.SC_THEME !== 'thr') {
const adminRoleUpdate = await this.driver.nativeUpdate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Migration } from '@mikro-orm/migrations-mongodb';
import { LtiMessageType, ToolConfigType } from '@modules/tool/common/enum';

export class Migration20240419075957 extends Migration {
async up(): Promise<void> {
public async up(): Promise<void> {
const result = await this.driver.nativeUpdate(
'external-tools',
{
Expand All @@ -15,8 +15,8 @@ export class Migration20240419075957 extends Migration {
console.info(`Changed ${result.affectedRows} lti_message_type(s) to basic-lti-launch-request in external-tools`);
}

// eslint-disable-next-line @typescript-eslint/require-await
async down(): Promise<void> {
// eslint-disable-next-line @typescript-eslint/require-await, require-await
public async down(): Promise<void> {
console.error(`Migration down not implemented. You might need to restore database from backup!`);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Migration } from '@mikro-orm/migrations-mongodb';

export class Migration20240430140106 extends Migration {
async up(): Promise<void> {
public async up(): Promise<void> {
const superheroRoleUpdate = await this.driver.nativeUpdate(
'roles',
{ name: 'superhero' },
Expand All @@ -19,7 +19,7 @@ export class Migration20240430140106 extends Migration {
}
}

async down(): Promise<void> {
public async down(): Promise<void> {
const superheroRoleUpdate = await this.driver.nativeUpdate(
'roles',
{ name: 'superhero' },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Migration } from '@mikro-orm/migrations-mongodb';
import { MediaBoardColors, BoardLayout } from '@modules/board/domain';
import { MediaBoardColors, BoardLayout } from '@modules/board';

export class Migration20240517135008 extends Migration {
async up(): Promise<void> {
public async up(): Promise<void> {
const mediaBoards = await this.driver.nativeUpdate(
'boardnodes',
{ type: 'media-board' },
Expand Down Expand Up @@ -30,7 +30,7 @@ export class Migration20240517135008 extends Migration {
}
}

async down(): Promise<void> {
public async down(): Promise<void> {
const mediaBoards = await this.driver.nativeUpdate(
'boardnodes',
{ type: 'media-board' },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Migration } from '@mikro-orm/migrations-mongodb';

export class Migration20240528140356 extends Migration {
async up(): Promise<void> {
public async up(): Promise<void> {
const mediaBoards = await this.driver.nativeUpdate(
'boardnodes',
{ type: 'media-board' },
Expand All @@ -15,7 +15,7 @@ export class Migration20240528140356 extends Migration {
}
}

async down(): Promise<void> {
public async down(): Promise<void> {
const mediaBoards = await this.driver.nativeUpdate(
'boardnodes',
{ type: 'media-board' },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Migration } from '@mikro-orm/migrations-mongodb';

export class Migration20240529091306 extends Migration {
async up(): Promise<void> {
public async up(): Promise<void> {
const systemOptions = await this.driver.nativeUpdate(
'school-system-options',
{},
Expand All @@ -13,7 +13,7 @@ export class Migration20240529091306 extends Migration {
);
}

async down(): Promise<void> {
public async down(): Promise<void> {
const systemOptions = await this.driver.nativeUpdate(
'school-system-options',
{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Migration } from '@mikro-orm/migrations-mongodb';
import * as process from 'node:process';

export class Migration20240604131554 extends Migration {
async up(): Promise<void> {
public async up(): Promise<void> {
// eslint-disable-next-line no-process-env
if (process.env.SC_THEME === 'n21') {
await this.driver.nativeInsert('instances', {
Expand Down Expand Up @@ -36,7 +36,7 @@ export class Migration20240604131554 extends Migration {
}
}

async down(): Promise<void> {
public async down(): Promise<void> {
await this.getCollection('instances').drop();

console.info('Collection "instances" was dropped');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Migration } from '@mikro-orm/migrations-mongodb';

export class Migration20240605065231 extends Migration {
async up(): Promise<void> {
public async up(): Promise<void> {
const filerecords = await this.driver.nativeUpdate(
'filerecords',
{},
Expand All @@ -11,7 +11,7 @@ export class Migration20240605065231 extends Migration {
console.info(`${filerecords.affectedRows} Filerecords were migrated to "storageLocationId" and "storageLocation"`);
}

async down(): Promise<void> {
public async down(): Promise<void> {
const filerecords = await this.driver.nativeUpdate(
'filerecords',
{},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Migration } from '@mikro-orm/migrations-mongodb';

export class Migration20240606142059 extends Migration {
async up(): Promise<void> {
public async up(): Promise<void> {
const superheroRole = await this.driver.nativeUpdate(
'roles',
{ name: 'superhero' },
Expand All @@ -19,7 +19,7 @@ export class Migration20240606142059 extends Migration {
}
}

async down(): Promise<void> {
public async down(): Promise<void> {
const superheroRole = await this.driver.nativeUpdate(
'roles',
{ name: 'superhero' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type MediaSourceEntityProps = {
};

export class Migration20240611081033 extends Migration {
async up(): Promise<void> {
public async up(): Promise<void> {
const uniqueSourceIds: unknown[] = await this.getCollection('user-licenses').distinct('mediaSourceId');

const validSourceIds: string[] = uniqueSourceIds.filter(
Expand Down Expand Up @@ -63,7 +63,7 @@ export class Migration20240611081033 extends Migration {
console.info(`mediaSourceId was renamed to mediaSource in ${userLicensesNameChange.affectedRows} user licenses`);
}

async down(): Promise<void> {
public async down(): Promise<void> {
await this.driver.aggregate('user-licenses', [
{ $match: { mediaSource: { $ne: null } } },
{ $lookup: { from: 'media-sources', localField: 'mediaSource', foreignField: '_id', as: 'mediaSourceId' } }, // Joins media-sources as array in mediaSourceId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Migration } from '@mikro-orm/migrations-mongodb';

export class Migration20240612122202 extends Migration {
async up(): Promise<void> {
public async up(): Promise<void> {
const filerecords = await this.driver.nativeUpdate('filerecords', {}, { $rename: { school: 'storageLocationId' } });

console.info(`${filerecords.affectedRows} Filerecords were migrated to "storageLocationId"`);
}

async down(): Promise<void> {
public async down(): Promise<void> {
const filerecords = await this.driver.nativeUpdate('filerecords', {}, { $rename: { storageLocationId: 'school' } });

console.info(`${filerecords.affectedRows} Filerecords were rolled back to use "schoolId"`);
Expand Down
Loading

0 comments on commit d708c6b

Please sign in to comment.