Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/database/migration/mysql/14.0.x/1635599216113-renameAlertsToMedia.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
src/database/migration/postgres/14.0.x/1635599216113-renameAlertsToMedia.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/database/migration/sqlite/14.0.x/1635599216113-renameAlertsToMedia.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |