From 660d56becf9b574c56c26de0b37d8e37c0ed541f Mon Sep 17 00:00:00 2001 From: Marigold Date: Tue, 24 Oct 2023 17:30:12 +0200 Subject: [PATCH] :sparkles: add indicator shortName to catalogPath in variables table --- ...8654-AddIndicatorShortNameToCatalogPath.ts | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 db/migration/1698087308654-AddIndicatorShortNameToCatalogPath.ts diff --git a/db/migration/1698087308654-AddIndicatorShortNameToCatalogPath.ts b/db/migration/1698087308654-AddIndicatorShortNameToCatalogPath.ts new file mode 100644 index 00000000000..38c29244436 --- /dev/null +++ b/db/migration/1698087308654-AddIndicatorShortNameToCatalogPath.ts @@ -0,0 +1,44 @@ +import { MigrationInterface, QueryRunner } from "typeorm" + +export class AddIndicatorShortNameToCatalogPath1698087308654 + implements MigrationInterface +{ + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `UPDATE variables + SET catalogPath = CONCAT(catalogPath, '#', shortName) + WHERE catalogPath not like '%#%'; + ` + ) + // change it from text to varchar for more efficient indexing, make it as long as possible + // to fit into index + await queryRunner.query( + `ALTER TABLE variables + MODIFY catalogPath VARCHAR(767) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_cs; + ` + ) + await queryRunner.query( + `ALTER TABLE variables + ADD UNIQUE INDEX idx_catalogPath (catalogPath); + ` + ) + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + ALTER TABLE variables + DROP INDEX idx_catalogPath + `) + await queryRunner.query( + `UPDATE variables + SET catalogPath = SUBSTRING_INDEX(catalogPath, '#', 1) + WHERE catalogPath LIKE '%#%'; + ` + ) + await queryRunner.query( + `ALTER TABLE variables + MODIFY catalogPath text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_cs; + ` + ) + } +}