From 0750e13d3f8ab561adfa7b6c4a5323cd678668ca Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 6 Jan 2024 16:18:42 -0600 Subject: [PATCH] chore(server): set onboarding for existing instances (#6229) * chore(server): set onboarding for existing instances * down --- ...DefaultOnboardingForExistingInstallations.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 server/src/infra/migrations/1704571051932-DefaultOnboardingForExistingInstallations.ts 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'`); + } +}