diff --git a/server/src/infra/migrations/1704571051932-DefaultOnboardingForExistingInstallations.ts b/server/src/infra/migrations/1704571051932-DefaultOnboardingForExistingInstallations.ts new file mode 100644 index 0000000000..cba248b5f7 --- /dev/null +++ b/server/src/infra/migrations/1704571051932-DefaultOnboardingForExistingInstallations.ts @@ -0,0 +1,17 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class DefaultOnboardingForExistingInstallations1704571051932 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + const adminCount = await queryRunner.query(`SELECT COUNT(*) FROM users WHERE "isAdmin" = true`); + if (adminCount[0].count > 0) { + await queryRunner.query(`INSERT INTO system_metadata (key, value) VALUES ($1, $2)`, [ + 'admin-onboarding', + '"{\\"isOnboarded\\":true}"', + ]); + } + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DELETE FROM system_metadata WHERE key = 'admin-onboarding'`); + } +}