1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-29 11:24:37 +02:00

fix(server): use jasonnnnnnnnnb (#9539)

This commit is contained in:
Jason Rasmussen 2024-05-16 17:24:54 -04:00 committed by GitHub
parent d8eca168ca
commit 936a46b4ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 1 deletions

View File

@ -6,7 +6,7 @@ export class SystemMetadataEntity<T extends keyof SystemMetadata = SystemMetadat
@PrimaryColumn({ type: 'varchar' })
key!: T;
@Column({ type: 'jsonb', default: '{}', transformer: { to: JSON.stringify, from: JSON.parse } })
@Column({ type: 'jsonb' })
value!: SystemMetadata[T];
}

View File

@ -0,0 +1,24 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class FixJsonB1715890481637 implements MigrationInterface {
name = 'FixJsonB1715890481637';
public async up(queryRunner: QueryRunner): Promise<void> {
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<void> {
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,
]);
}
}
}