From 936a46b4edd1f62916c2b65592a2bae1410e4215 Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Thu, 16 May 2024 17:24:54 -0400 Subject: [PATCH] fix(server): use jasonnnnnnnnnb (#9539) --- server/src/entities/system-metadata.entity.ts | 2 +- .../src/migrations/1715890481637-FixJsonB.ts | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 server/src/migrations/1715890481637-FixJsonB.ts diff --git a/server/src/entities/system-metadata.entity.ts b/server/src/entities/system-metadata.entity.ts index b702d2606d..fcbc66edae 100644 --- a/server/src/entities/system-metadata.entity.ts +++ b/server/src/entities/system-metadata.entity.ts @@ -6,7 +6,7 @@ export class SystemMetadataEntity { + await queryRunner.query(`ALTER TABLE "system_metadata" ALTER COLUMN "value" DROP DEFAULT`); + const records = await queryRunner.query('SELECT "key", "value" FROM "system_metadata"'); + for (const { key, value } of records) { + await queryRunner.query(`UPDATE "system_metadata" SET "value" = $1 WHERE "key" = $2`, [value, key]); + } + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "system_metadata" ALTER COLUMN "value" SET DEFAULT '{}'`); + const records = await queryRunner.query('SELECT "key", "value" FROM "system_metadata"'); + for (const { key, value } of records) { + await queryRunner.query(`UPDATE "system_metadata" SET "value" = $1 WHERE "key" = $2`, [ + JSON.stringify(JSON.stringify(value)), + key, + ]); + } + } +}