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!`); + } +} 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" + } } ]