Skip to content

Commit

Permalink
fix: add migration alerts to media
Browse files Browse the repository at this point in the history
  • Loading branch information
sogehige committed Nov 9, 2021
1 parent 36f0814 commit 909d3a4
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
@@ -0,0 +1,35 @@
import { defaultsDeep } from 'lodash';
import { MigrationInterface, QueryRunner } from 'typeorm';

export class renameAlertsToMedia1635599216113 implements MigrationInterface {
name = 'renameAlertsToMedia1635599216111';

public async up(queryRunner: QueryRunner): Promise<void> {
const items = await queryRunner.query('SELECT * FROM overlay_mapper', undefined);
for (const item of items) {
let opts: Record<string, any> = {};
if (item.opts) {
opts = JSON.parse(item.opts);
}
if(['alerts'].includes(item.value)) {
opts = defaultsDeep(opts ?? {}, {
galleryCache: false,
galleryCacheLimitInMb: 50,
});
item.value = 'media';
}
const keys = Object.keys(item);
item.opts = JSON.stringify(opts);
await queryRunner.query('DELETE FROM `overlay_mapper` WHERE `id`=?', [item.id]);
await queryRunner.query(
`INSERT INTO \`overlay_mapper\`(${keys.map(o => `\`${o}\``).join(', ')}) values (${keys.map(o => `?`).join(', ')})`,
[keys.map(key => item[key])],
);
}
}

public async down(queryRunner: QueryRunner): Promise<void> {
return;
}

}
@@ -0,0 +1,32 @@
import { defaultsDeep } from 'lodash';
import { MigrationInterface, QueryRunner } from 'typeorm';

export class renameAlertsToMedia1635599216113 implements MigrationInterface {
name = 'renameAlertsToMedia1635599216111';

public async up(queryRunner: QueryRunner): Promise<void> {
const items = await queryRunner.query('SELECT * FROM overlay_mapper', undefined);
for (const item of items) {
let opts: Record<string, any> = {};
if (item.opts) {
opts = JSON.parse(item.opts);
}
if(['alerts'].includes(item.value)) {
opts = defaultsDeep(opts ?? {}, {
galleryCache: false,
galleryCacheLimitInMb: 50,
});
item.value = 'media';
}
const keys = Object.keys(item);
item.opts = JSON.stringify(opts);
await queryRunner.query('DELETE FROM "overlay_mapper" WHERE "id"=\'' + item.id + '\'');
await queryRunner.query(`INSERT INTO "overlay_mapper"(${keys.map(o => `${o}`).join(', ')}) values (${keys.map(o => `'${item[o]}'`).join(', ')})`);
}
}

public async down(queryRunner: QueryRunner): Promise<void> {
return;
}

}
@@ -0,0 +1,35 @@
import { defaultsDeep } from 'lodash';
import { MigrationInterface, QueryRunner } from 'typeorm';

export class renameAlertsToMedia1635599216113 implements MigrationInterface {
name = 'renameAlertsToMedia1635599216111';

public async up(queryRunner: QueryRunner): Promise<void> {
const items = await queryRunner.query('SELECT * FROM overlay_mapper', undefined);
for (const item of items) {
let opts: Record<string, any> = {};
if (item.opts) {
opts = JSON.parse(item.opts);
}
if(['alerts'].includes(item.value)) {
opts = defaultsDeep(opts ?? {}, {
galleryCache: false,
galleryCacheLimitInMb: 50,
});
item.value = 'media';
}
const keys = Object.keys(item);
item.opts = JSON.stringify(opts);
await queryRunner.query('DELETE FROM "overlay_mapper" WHERE "id"=?', [item.id]);
await queryRunner.query(
`INSERT INTO "overlay_mapper"(${keys.map(o => `"${o}"`).join(', ')}) values (${keys.map(o => `?`).join(', ')})`,
[keys.map(key => item[key])],
);
}
}

public async down(queryRunner: QueryRunner): Promise<void> {
return;
}

}

0 comments on commit 909d3a4

Please sign in to comment.