diff --git a/apps/server/src/migrations/mikro-orm/Migration20241112163538.ts b/apps/server/src/migrations/mikro-orm/Migration20241112163538.ts deleted file mode 100644 index 26e50089fd..0000000000 --- a/apps/server/src/migrations/mikro-orm/Migration20241112163538.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { Migration } from '@mikro-orm/migrations-mongodb'; - -export class Migration20241112163538 extends Migration { - async up(): Promise { - const collection = this.getCollection('room-members'); - - await collection.updateMany({ roomId: { $type: 'string' } }, [ - { - $set: { - roomId: { - $convert: { - input: '$roomId', - to: 'objectId', - onError: '$roomId', // Keep the original value if conversion fails - onNull: '$roomId', // Keep the original value if the input is null - }, - }, - }, - }, - ]); - console.info('Converted roomId from string to ObjectId'); - - await collection.updateMany({}, { $rename: { roomId: 'room' } }); - console.info('Renamed roomId to room'); - } - - async down(): Promise { - await Promise.resolve(); - console.error(`Migration down not implemented. You might need to restore database from backup!`); - } -} diff --git a/apps/server/src/migrations/mikro-orm/Migration20241113152001.ts b/apps/server/src/migrations/mikro-orm/Migration20241113152001.ts deleted file mode 100644 index 9914935c0a..0000000000 --- a/apps/server/src/migrations/mikro-orm/Migration20241113152001.ts +++ /dev/null @@ -1,102 +0,0 @@ -import { Migration } from '@mikro-orm/migrations-mongodb'; - -export class Migration20241113152001 extends Migration { - async up(): Promise { - const roomsToSchoolView = [ - { - $lookup: { - from: 'rooms', - localField: 'room', - foreignField: '_id', - as: 'roomDetails', - }, - }, - { - $unwind: '$roomDetails', - }, - { - $match: { - 'roomDetails.school': { $exists: false, $eq: null }, - }, - }, - { - $lookup: { - from: 'groups', - localField: 'userGroup', - foreignField: '_id', - as: 'groupDetails', - }, - }, - { - $unwind: '$groupDetails', - }, - { - $unwind: '$groupDetails.users', - }, - { - $lookup: { - from: 'roles', - localField: 'groupDetails.users.role', - foreignField: '_id', - as: 'roleDetails', - }, - }, - { - $unwind: '$roleDetails', - }, - { - $match: { - 'roleDetails.name': 'roomeditor', - }, - }, - { - $lookup: { - from: 'users', - localField: 'groupDetails.users.user', - foreignField: '_id', - as: 'userDetails', - }, - }, - { - $unwind: '$userDetails', - }, - { - $group: { - _id: '$userDetails.schoolId', - rooms: { $push: '$roomDetails._id' }, - }, - }, - { - $project: { - _id: 0, - school: '$_id', - rooms: 1, - }, - }, - ]; - - const mappings = await this.driver.aggregate('room-members', roomsToSchoolView); - - for await (const mapping of mappings) { - const schoolUpdate = await this.driver.nativeUpdate( - 'rooms', - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access - { _id: { $in: mapping.rooms } }, - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access - { $set: { school: mapping.school } } - ); - - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access, @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-unsafe-call - console.info(`Updated ${schoolUpdate.affectedRows} rooms with school ${mapping.school.toHexString()}`); - } - - if (mappings.length === 0) { - console.info(`No rooms without school to update`); - } - } - - async down(): Promise { - await Promise.resolve(); - console.error(`Migration down not implemented. You might need to restore database from backup!`); - } -} diff --git a/apps/server/src/migrations/mikro-orm/Migration20241127195120.ts b/apps/server/src/migrations/mikro-orm/Migration20241127195120.ts deleted file mode 100644 index 0b74ac61e6..0000000000 --- a/apps/server/src/migrations/mikro-orm/Migration20241127195120.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Migration } from '@mikro-orm/migrations-mongodb'; - -export class Migration20241127195120 extends Migration { - async up(): Promise { - const db = this.driver.getConnection().getDb(); - await db.renameCollection('room-members', 'room-memberships'); - console.info('Collection renamed from room-members to room-memberships'); - } - - async down(): Promise { - const db = this.driver.getConnection().getDb(); - await db.renameCollection('room-memberships', 'room-members'); - console.info('Collection renamed from room-memberships to room-members'); - } -} diff --git a/apps/server/src/migrations/mikro-orm/Migration20241128155801.ts b/apps/server/src/migrations/mikro-orm/Migration20241128155801.ts deleted file mode 100644 index 725ef54ecd..0000000000 --- a/apps/server/src/migrations/mikro-orm/Migration20241128155801.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { Migration } from '@mikro-orm/migrations-mongodb'; - -export class Migration20241128155801 extends Migration { - async up(): Promise { - const roomMembershipToSchoolView = [ - { - $match: { - school: { $exists: false, $eq: null }, - }, - }, - { - $lookup: { - from: 'rooms', - localField: 'room', - foreignField: '_id', - as: 'roomDetails', - }, - }, - { - $unwind: '$roomDetails', - }, - { - $group: { - _id: '$roomDetails.school', - roomMemberships: { $push: '$_id' }, - }, - }, - { - $project: { - _id: 0, - school: '$_id', - roomMemberships: 1, - }, - }, - ]; - - const mappings = await this.driver.aggregate('room-memberships', roomMembershipToSchoolView); - - for await (const mapping of mappings) { - const schoolUpdate = await this.driver.nativeUpdate( - 'room-memberships', - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access - { _id: { $in: mapping.roomMemberships } }, - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access - { $set: { school: mapping.school } } - ); - - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access, @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-unsafe-call - console.info(`Updated ${schoolUpdate.affectedRows} rooms with school ${mapping.school.toHexString()}`); - } - - if (mappings.length === 0) { - console.info(`No roomMemberships without school to update`); - } - } - - async down(): Promise { - await Promise.resolve(); - console.error(`Migration down not implemented. You might need to restore database from backup!`); - } -}