From 4d09cafd4639b2b95c272c4ffe6f9143ebbdf61c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20=C3=96hlerking?= Date: Thu, 25 Jul 2024 16:58:33 +0200 Subject: [PATCH 1/2] fix oauth feature for all schools --- .../mikro-orm/Migration20240725143018.ts | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 apps/server/src/migrations/mikro-orm/Migration20240725143018.ts diff --git a/apps/server/src/migrations/mikro-orm/Migration20240725143018.ts b/apps/server/src/migrations/mikro-orm/Migration20240725143018.ts new file mode 100644 index 00000000000..40cd27b32c6 --- /dev/null +++ b/apps/server/src/migrations/mikro-orm/Migration20240725143018.ts @@ -0,0 +1,39 @@ +import { Migration } from '@mikro-orm/migrations-mongodb'; + +export class Migration20240725143018 extends Migration { + async up(): Promise { + // eslint-disable-next-line no-process-env + if (process.env.SC_THEME !== 'n21') { + return; + } + + console.info(`Adding 'oauthProvisioningEnabled' school feature to schools with moin.schule system`); + + const moinSchuleSystem = await this.getCollection('systems').findOne({ alias: 'SANIS' }); + + if (!moinSchuleSystem) { + console.error('moin.schule system not found'); + return; + } + console.info(`moin.schule system ${moinSchuleSystem._id.toHexString()} found`); + + const addOauthFeatureToSchools = await this.driver.nativeUpdate( + 'schools', + { systems: moinSchuleSystem._id }, + { + $addToSet: { + features: { + $each: ['oauthProvisioningEnabled'], + }, + }, + } + ); + + console.info(`Added 'oauthProvisioningEnabled' school feature to ${addOauthFeatureToSchools.affectedRows} schools`); + } + + // eslint-disable-next-line @typescript-eslint/require-await + async down(): Promise { + console.error(`Migration down not implemented. You might need to restore database from backup!`); + } +} From 060f919e4997ec39eb2d197aee3f05abcb11c3be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20=C3=96hlerking?= Date: Fri, 26 Jul 2024 10:38:33 +0200 Subject: [PATCH 2/2] update migrations.json --- backup/setup/migrations.json | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/backup/setup/migrations.json b/backup/setup/migrations.json index 7a6b74f4f1b..574b93a2949 100644 --- a/backup/setup/migrations.json +++ b/backup/setup/migrations.json @@ -187,5 +187,14 @@ "created_at": { "$date": "2024-07-24T09:11:11.359Z" } + }, + { + "_id": { + "$oid": "66a267da6d71e4510a572d08" + }, + "name": "Migration20240725143018", + "created_at": { + "$date": "2024-07-25T14:57:30.752Z" + } } ]